Knowledge Base Actions

Knowledge Base Actions

Warning

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

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. Once you want to start working with a large amount of data, you can switch to a custom knowledge base.

Create a Knowledge Base

To initialize an InMemoryKnowledgeBase, you need to provide the data in a json file. The following example contains data about restaurants and hotels. The json structure should contain a key for every object type, i.e. "restaurant" and "hotel". Every object type maps to a list of objects – here we have a list of 3 restaurants and a list of 3 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"
        },
        {
            "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

In this section:

Creating Your Own Knowledge Base Actions

ActionQueryKnowledgeBase should allow you to easily get started with integrating knowledge bases into your actions. However, the action can only handle two kind of user requests:

Customizing ActionQueryKnowledgeBase

You can overwrite the following two functions of ActionQueryKnowledgeBase if you’d like to customize what the bot says to the user:

Note

There is a tutorial on our blog about how to use knowledge bases in custom actions.