Find answers from the community

Updated 2 months ago

Remembering User History and Conversation in a Chatbot

At a glance

The community member has created a chatbot using the LlamaIndex ChatEngine and wants to remember the user if they had previously used the chatbot, and show them the last history of their conversation. Currently, the community member gets a new conversation ID when a new connection is made from the same user. The community member wants to remember the user, and asks if they can do so using the user's IP address or any other way, and show them all the previous conversations they had.

In the comments, a community member suggests that the chat history of a user can be stored on the server side, and then loaded back when the same user comes back. They provide some example code to extract the chat history, and either pass it in the chat or set the chat memory. Another community member suggests that the chat history should be stored behind some ID, and that ID should be provided in the API request.

There is no explicitly marked answer in the comments.

I have created a chatbot using llama index chatengine…Now I want to remember the user if he had previously used the chatbot and show him the last history of conversation he had

Currently, I get a new conversation I’d when new connection is made from same user. I want to remember the user, can I remember from IP or any other way and show him all the conversations he had before
@Logan M
W
L
2 comments
You can store the chat of a user at your side and then load it back when same user comes back.

Plain Text
# Extract chat history of a user
chat_history = chat_engine._memory.get()

# once the same user comes back ( using some sort of Identifier ) 
# You can either pass it in chat or set the chat memory 
resp = chat_engine.chat(message=message, chat_history=chat_history)

# OR 
chat_engine._memory.set(chat_history)
You should store the chat history behind some id, and the id should be provided in the api request
Add a reply
Sign up and join the conversation on Discord