ActionQueryKnowledgeBase does not return anything

I am building a chatbot that deals with pokemon.

The Setup

I have a knowledge_base.json file that looks like this;

{"pokemon": [
  {"name": "bulbasaur", "id": 001, "pokedex": "Bulbasaur can be seen...."}, 
  {"name": "ivysaur", "id": 1, "pokedex": "There is a bud on this Pokemon's back ..."},
  ...
]}

And I would like to try the knowledge base feature. It seems like a great use-case. The only issue … the bot is just not responding anything when I use that action.

This is my action file.

import json
from pathlib import Path
from rasa_sdk.knowledge_base.storage import InMemoryKnowledgeBase
from rasa_sdk.knowledge_base.actions import ActionQueryKnowledgeBase

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

And here is part of my domain;

actions:
- utter_goodbye
- utter_greet
- utter_joke
- action_query_knowledge_base
entities:
- object_type
- attribute
slots:
  object_type:
    type: unfeaturized
  mention:
    type: unfeaturized
  attribute:
    type: unfeaturized
intents:
- greet
- joke
- goodbye
- retreive_pokedex
responses:
  utter_ask_rephrase:
  - text: "Sorry, I'm not sure I understand. Could you rephrase it?"
  - text: "Could you please rephrase your message? I didn't quite get that."
session_config:
  carry_over_slots_to_new_session: true
  session_expiration_time: 60

I also have a small bit of training data, again a relevant subset:

## intent:retreive_pokedex
- give me [info](attribute:pokedex) on [charmander](object_type:pokemon)
- [pokedex](attribute:pokedex) [bulbasaur](object_type:pokemon)
- give me [info](attribute) about [ivysaur](object_type:pokemon)

The Failure

I now run this in via rasa interactive. It first trains and then I can talk to it. Here’s a chat history.

Chat History

 #    Bot                                                                                                                                                      You        
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 1    action_listen                                                                                                                                                       
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 2                                                                                                                                                                     yo 
                                                                                                                                                       intent: greet 0.97 
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 3    utter_greet 1.00                                                                                                                                                    
      Hi! I am pokebot. I am a bot that will help you catch them all! Right now I am only talk a little bit about pokemon names.                                          
      utter_ask_features 1.00                                                                                                                                             
      My features are being built as we speak. Is there anything you'd like me to be able to do in the future?                                                            
      action_listen                                                                                                                                                       
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 4                                                                                                                                                                give me 
                                                                                                                                      [information](attribute:pokedex) on 
                                                                                                                                        [charmander](object_type:pokemon) 
                                                                                                                                            intent: retreive_pokedex 1.00 
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 5    slot{"attribute": "pokedex"}                                                                                                                                        
      slot{"object_type": "pokemon"}                                                                                                                                      
      action_listen 0.53                                                                                                                                                  
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 6                                                                                                                                     gimme [info](attribute:pokedex) on 
                                                                                                                                         [bulbasaur](object_type:pokemon) 
                                                                                                                                            intent: retreive_pokedex 0.98 
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 7    slot{"attribute": "pokedex"}                                                                                                                                        
      slot{"object_type": "pokemon"}                                                                                                                                      


Current slots: 
        attribute: pokedex, knowledge_base_last_object: None, knowledge_base_last_object_type: None, knowledge_base_listed_objects: None, mention: None, object_type: pokemon

------
? The bot wants to run 'action_listen', correct?  (Y/n)  

My issue is, how can I give the user the pokedex entry? It seems like all that’s happening here is that the knowledge base is filling in slots. Is this accurate?

See this part of the doc.

I think you need to change your NLU training dataset to something like this:

## intent:retreive_pokedex
- give me [info](attribute:pokedex) on [charmander](pokemon)
- [pokedex](pokedex) [bulbasaur](pokemon)
- give me [info](attribute:pokedex) about [ivysaur](pokemon)

The attribute key should be the same as in the knowledge base hence we are using synonyms. But since we need to get info about a particular object (say bulbasaur) which is of the object type pokemon, we need training data to recognize bulbasaur as a pokemon. Objects in knowledge base are represented by their name attribute by default. See get_representation_function_of_object() method from the doc.

You also need to add pokemon as entity and slot in the domain.

See this example for more details.

Hope that helps.