mirror of https://github.com/hwchase17/langchain
docs: Fix the bug in MongoDBChatMessageHistory notebook (#18128)
I tried to configure MongoDBChatMessageHistory using the code from the original documentation to store messages based on the passed session_id in MongoDB. However, this configuration did not take effect, and the session id in the database remained as 'test_session'. To resolve this issue, I found that when configuring MongoDBChatMessageHistory, it is necessary to set session_id=session_id instead of session_id=test_session. Issue: DOC: Ineffective Configuration of MongoDBChatMessageHistory for Custom session_id Storage previous code: ```python chain_with_history = RunnableWithMessageHistory( chain, lambda session_id: MongoDBChatMessageHistory( session_id="test_session", connection_string="mongodb://root:Y181491117cLj@123.56.224.232:27017", database_name="my_db", collection_name="chat_histories", ), input_messages_key="question", history_messages_key="history", ) config = {"configurable": {"session_id": "mmm"}} chain_with_history.invoke({"question": "Hi! I'm bob"}, config) ``` ![image](https://github.com/langchain-ai/langchain/assets/83388493/c372f785-1ec1-43f5-8d01-b7cc07b806b7) Modified code: ```python chain_with_history = RunnableWithMessageHistory( chain, lambda session_id: MongoDBChatMessageHistory( session_id=session_id, # here is my modify code connection_string="mongodb://root:Y181491117cLj@123.56.224.232:27017", database_name="my_db", collection_name="chat_histories", ), input_messages_key="question", history_messages_key="history", ) config = {"configurable": {"session_id": "mmm"}} chain_with_history.invoke({"question": "Hi! I'm bob"}, config) ``` Effect after modification (it works): ![image](https://github.com/langchain-ai/langchain/assets/83388493/5776268c-9098-4da3-bf41-52825be5fafb)pull/18135/head
parent
e3b7779926
commit
9147a437f1
Loading…
Reference in New Issue