mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-05 04:38:26 +00:00
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) ```  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): 
This commit is contained in:
parent
e3b7779926
commit
9147a437f1
@ -180,7 +180,7 @@
|
||||
"chain_with_history = RunnableWithMessageHistory(\n",
|
||||
" chain,\n",
|
||||
" lambda session_id: MongoDBChatMessageHistory(\n",
|
||||
" session_id=\"test_session\",\n",
|
||||
" session_id=session_id,\n",
|
||||
" connection_string=\"mongodb://mongo_user:password123@mongo:27017\",\n",
|
||||
" database_name=\"my_db\",\n",
|
||||
" collection_name=\"chat_histories\",\n",
|
||||
|
Loading…
Reference in New Issue
Block a user