mirror of
https://github.com/hwchase17/langchain
synced 2024-10-31 15:20:26 +00:00
9147a437f1
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) |
||
---|---|---|
.. | ||
api_reference | ||
data | ||
docs | ||
scripts | ||
src | ||
static | ||
.local_build.sh | ||
babel.config.js | ||
code-block-loader.js | ||
docusaurus.config.js | ||
package-lock.json | ||
package.json | ||
README.md | ||
settings.ini | ||
sidebars.js | ||
vercel_build.sh | ||
vercel_requirements.txt | ||
vercel.json |
LangChain Documentation
For more information on contributing to our documentation, see the Documentation Contributing Guide