# Issue with saving conversation into mongodb

Hi,

I am trying to save the RASA conversations in mongodb. I have taken the restaurantbot example from rasa_core and trying to save the conversation. Followed the instructions as mentioned in the documentation for mongo tracker store.

1. In bot.py to include MongoTrackerStore and changed the agent to include this tracker_store.
2. In endpoints.yml added the following tracker store: tracker_store: store_type: mongod url: mongodb://localhost:27017 db: rasa

Observations: The new db(rasa) and collection (conversations) is getting created in mongodb. However the actual chat is not getting stored into the db. The collection is empty.

Please advice on what could be the issue. This is executed on a window machine.

Thank you.

I think the issue probably comes from the fact that you have a bot.py where you pass the tracker_store as MongoTrackerStore but do you provide the connection parameters there?

unless you are using the rasa run.py script, the endpoints won’t be passed to the agent or you have to pass the endpoints yourself.

It is either you pass the tracker store directly with all the params to the Agent class using python or via the run.py script and endpoints.yml

in your case, the endpoints.yml is creating the collection but the agent you instantiated is not connecting to the right mongodb

Hi Souvik,

This is the snapshot of the code in bot.py

def train_dialogue(domain_file=“restaurant_domain.yml”, model_path=“models/dialogue”, training_data_file=“data/babi_stories.md”): nlu_interpreter = RasaNLUInterpreter(’./models/nlu/default/current/’) action_endpoint = EndpointConfig(url=“http://localhost:5055/webhook”)

agent = Agent(domain_file,
policies=[MemoizationPolicy(max_history=3),
RestaurantPolicy()],
tracker_store=db,
interpreter=nlu_interpreter,
generator=None, action_endpoint=action_endpoint,
fingerprint=None)

agent.train(
training_data,batch_size=100, epochs=600,validation_split=0.2
)

agent.persist(model_path)
return agent

The command used to run rasa core:

python -m rasa_core.run --nlu models/nlu/default/current --core models/dialogue --endpoints endpoints.yml --debug

So as per this the endpoints are being passed to the agent.

Do you see any issue with this?

Thank you.

What does the log say? because if it can’t find the tracker store, you won’t have the states saved and the next prediction won’t be correct

Hi Souvik,

There are no errors in the logs.

Below are the logs:

Bot loaded. Type a message and press enter (use '/stop' to exit): hi 2018-11-23 12:29:37 DEBUG rasa_core.tracker_store - Creating a new tracker for id 'default'. 2018-11-23 12:29:37 WARNING py.warnings - C:\Program Files\Python36\lib\site-packages\sklearn\preprocessing\label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use array.size > 0 to check that an array is not empty. if diff:

2018-11-23 12:29:37 DEBUG rasa_core.processor - Received user message ‘hi’ with intent ‘{‘name’: ‘greet’, ‘confidence’: 0.9904502504823246}’ and entities ‘[]’ 2018-11-23 12:29:37 DEBUG rasa_core.processor - Logged UserUtterance - tracker now has 2 events 2018-11-23 12:29:37 DEBUG rasa_core.processor - Current slot values: cuisine: None info: None location: None matches: None people: None price: None 2018-11-23 12:29:37 DEBUG rasa_core.policies.memoization - Current tracker state [None, {}, {‘intent_greet’: 1.0, ‘prev_action_listen’: 1.0}] 2018-11-23 12:29:37 DEBUG rasa_core.policies.memoization - There is a memorised next action ‘10’ 2018-11-23 12:29:37 DEBUG rasa_core.policies.ensemble - Predicted next action using policy_0_MemoizationPolicy 2018-11-23 12:29:37 DEBUG rasa_core.processor - Predicted next action ‘utter_ask_howcanhelp’ with prob 1.00. 2018-11-23 12:29:37 DEBUG rasa_core.processor - Action ‘utter_ask_howcanhelp’ ended with events ‘[]’ 2018-11-23 12:29:37 DEBUG rasa_core.processorhow can I help you? - Bot utterance ‘BotUttered(text: how can I help you?, data: { “elements”: null, “buttons”: null, “attachment”: null })’

2018-11-23 12:29:37 DEBUG rasa_core.policies.memoization - Current tracker state [{}, {‘intent_greet’: 1.0, ‘prev_action_listen’: 1.0}, {‘intent_greet’: 1.0, ‘prev_utter_ask_howcanhelp’: 1.0}] 2018-11-23 12:29:37 DEBUG rasa_core.policies.memoization - There is a memorised next action ‘0’ 2018-11-23 12:29:37 DEBUG rasa_core.policies.ensemble - Predicted next action using policy_0_MemoizationPolicy 2018-11-23 12:29:37 DEBUG rasa_core.processor - Predicted next action ‘action_listen’ with prob 1.00. 2018-11-23 12:29:37 DEBUG rasa_core.processor - Action ‘action_listen’ ended with events ‘[]’ 127.0.0.1 - - [2018-11-23 12:29:37] “POST /webhooks/rest/webhook?stream=true&token= HTTP/1.1” 200 187 0.288016 i want to search for a restaurant 2018-11-23 12:30:22 DEBUG rasa_core.tracker_store - Recreating tracker for id ‘default’ 2018-11-23 12:30:22 WARNING py.warnings - C:\Program Files\Python36\lib\site-packages\sklearn\preprocessing\label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use array.size > 0 to check that an array is not empty. if diff:

The prediction seems to be correct. But none of the inputs are saved in db

Use the tracker API to retrieve values and check if the states are persisted if you restart the server

If you receive the old states then the tracker is stored in external tracker otherwise it is going to InMemory tracker

If it is the above case then you might be looking in a wrong collection or something

Yeah. The mongodb database is empty. The states are getting saved in memory. After restart the conversations get reset. If there something to be done to switch to mongodb. Any sample code available to make this work?

you don’t need to pass the tracker_store for training the model.

Can you provide the format of your endpoints.yml, what parameters did you send for Mongodb