langchain/docs
rongchenlin 9147a437f1
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)
2024-02-26 15:02:56 +00:00
..
api_reference docs: sorting Examples using ... section (#17588) 2024-02-21 17:04:23 -08:00
data 👥 Update LangChain people data (#17900) 2024-02-21 16:38:28 -08:00
docs docs: Fix the bug in MongoDBChatMessageHistory notebook (#18128) 2024-02-26 15:02:56 +00:00
scripts infra: add print rule to ruff (#16221) 2024-02-09 16:13:30 -08:00
src 👥 Update LangChain people data (#17743) 2024-02-20 18:30:11 -08:00
static docs: logo (#17972) 2024-02-22 15:20:34 -08:00
.local_build.sh docs: partner packages (#16960) 2024-02-02 15:12:21 -08:00
babel.config.js Restructure docs (#11620) 2023-10-10 12:55:19 -07:00
code-block-loader.js Restructure docs (#11620) 2023-10-10 12:55:19 -07:00
docusaurus.config.js docs: logo (#17972) 2024-02-22 15:20:34 -08:00
package-lock.json docs[patch]: search experiment (#14254) 2023-12-04 16:58:26 -08:00
package.json 👥 Update LangChain people data (#17743) 2024-02-20 18:30:11 -08:00
README.md docs: developer docs (#14776) 2023-12-17 12:55:49 -08:00
settings.ini Restructure docs (#11620) 2023-10-10 12:55:19 -07:00
sidebars.js docs: Toolkits menu (#16217) 2024-02-08 14:52:26 -08:00
vercel_build.sh docs: add LangGraph (#15682) 2024-01-08 08:38:14 -08:00
vercel_requirements.txt infra: docs build install community editable (#14739) 2023-12-14 16:13:09 -08:00
vercel.json Redirect the expression language guides (#17914) 2024-02-22 00:39:57 -08:00

LangChain Documentation

For more information on contributing to our documentation, see the Documentation Contributing Guide