Knowledge Base Actions

These docs are for version 1.x of Rasa Open Source.

User Guide

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

Knowledge base actions enable you to handle the following kind of conversations:

To handle challenges in conversational AI regarding user references, Rasa can be integrated with knowledge bases, employing custom actions that inherit from ActionQueryKnowledgeBase.

Create a Knowledge Base

The data for user requests should be stored in a knowledge base. Below is an example JSON structure containing data about restaurants and hotels:

{
    "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"
        }
    ],
    "hotel": [
        {
            "id": 0,
            "name": "Hilton",
            "price-range": "expensive",
            "breakfast-included": true,
            "city": "Berlin",
            "free-wifi": true,
            "star-rating": 5,
            "swimming-pool": true
        }
    ]
}

Query the Knowledge Base for Objects

In user requests, specifying object types is critical for the bot to provide relevant information. An example request could be:

Can you please name some restaurants?
This will allow the action to identify the entity and respond accordingly.

Define the NLU Data

You will need to introduce a new intent, query_knowledge_base, with various training examples:

## 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?  
... 

Create an Action to Query your Knowledge Base

To create your own knowledge base action, inherit ActionQueryKnowledgeBase and initialize it with the knowledge base. Example:

from rasa_sdk.knowledge_base.storage import InMemoryKnowledgeBase
from rasa_sdk.knowledge_base.actions import ActionQueryKnowledgeBase

class MyKnowledgeBaseAction(ActionQueryKnowledgeBase):
    def __init__(self):
        knowledge_base = InMemoryKnowledgeBase("data.json")
        super().__init__(knowledge_base)

You can customize how the bot interacts regarding object listings or attribute queries by overriding the utter_objects() and utter_attribute_value() methods respectively.

Additional References

For further understanding of creating and managing knowledge bases, refer to:

Examples