Knowledge Base Actions
These docs are for version 1.x of Rasa Open Source.
User Guide
- Installation
- Tutorial: Rasa Basics
- Tutorial: Building Assistants
- Command Line Interface
- Architecture
- Messaging and Voice Channels
- Evaluating Models
- Validate Data
- Running the Server
- Deploying your Rasa Assistant
- Cloud Storage
NLU
- About
- Using NLU Only
- Training Data Format
- Choosing a Pipeline
- Language Support
- Entity Extraction
- Components
Core
- About
- Stories
- Domains
- Responses
- Actions
- Policies
- Slots
- Forms
- Retrieval Actions
- Interactive Learning
- Fallback Actions
- Knowledge Base Actions
Knowledge Base Actions
This feature is experimental. We introduce experimental features to get feedback from our community, so we encourage you to try it out! However, the functionality might be changed or removed in the future. If you have feedback (positive or negative) please share it with us on the forum.
Using ActionQueryKnowledgeBase
Create a Knowledge Base
The data used to answer the user’s requests will be stored in a knowledge base. A knowledge base can be used to store complex data structures. We suggest you get started by using the InMemoryKnowledgeBase.
Example JSON structure
{
"restaurant": [
{
"id": 0,
"name": "Donath",
"cuisine": "Italian",
"outside-seating": true,
"price-range": "mid-range"
},
{
"id": 1,
"name": "Berlin Burrito Company",
"cuisine": "Mexican",
"outside-seating": false,
"price-range": "cheap"
},
{
"id": 2,
"name": "I due forni",
"cuisine": "Italian",
"outside-seating": true,
"price-range": "mid-range"
}
],
"hotel": [
{
"id": 0,
"name": "Hilton",
"price-range": "expensive",
"breakfast-included": true,
"city": "Berlin",
"free-wifi": true,
"star-rating": 5,
"swimming-pool": true
},
{
"id": 1,
"name": "Hilton",
"price-range": "expensive",
"breakfast-included": true,
"city": "Frankfurt am Main",
"free-wifi": true,
"star-rating": 4,
"swimming-pool": false
},
{
"id": 2,
"name": "B&B",
"price-range": "mid-range",
"breakfast-included": false,
"city": "Berlin",
"free-wifi": false,
"star-rating": 1,
"swimming-pool": false
}
]
}
Define the NLU Data
- We will introduce a new intent,
query_knowledge_base - We will annotate
mentionentities so the model detects indirect mentions of objects like “the first one” - We will use synonyms extensively
## intent:query_knowledge_base
- what [restaurants](object_type:restaurant) can you recommend?
- list some [restaurants](object_type:restaurant)
- can you name some [restaurants](object_type:restaurant) please?
- can you show me some [restaurant](object_type:restaurant) options
- list [German](cuisine) [restaurants](object_type:restaurant)
- do you have any [mexican](cuisine) [restaurants](object_type:restaurant)?
...
Create an Action to Query your Knowledge Base
To create your own knowledge base action, inherit ActionQueryKnowledgeBase and pass the knowledge base to its constructor.
class MyKnowledgeBaseAction(ActionQueryKnowledgeBase):
def __init__(self):
knowledge_base = InMemoryKnowledgeBase("data.json")
super().__init__(knowledge_base)
How It Works
ActionQueryKnowledgeBase looks at both the entities picked up in the request as well as the previously set slots to decide what to query for.
Query the Knowledge Base for Objects
In order to query the knowledge base for any kind of object, the user’s request must include the object type.
Query the Knowledge Base for an Attribute of an Object
If the user wants to obtain specific information about an object, the request should include both the object and attribute of interest.
Resolve Mentions
Users may refer to objects by their name or a previously listed object via a mention. The action is able to resolve these mentions to the actual object in the knowledge base.
Customization
You can overwrite functions of ActionQueryKnowledgeBase to customize what the bot says to the user:
utter_objects()utter_attribute_value()
See the example bot for an example implementation.