Mongodb Langchain Js Memory
agentsartificial-intelligencellmsmongodb-genai-showcasenotebooksgenerative-airag
Export
Adding Chat History to your RAG Application using MongoDB and LangChain.js
In this notebook, we will see how to use the new MongoDBChatMessageHistory in your RAG application.
Step 1: Set up environment
You may be used to Jupyter notebooks that use Python, but this notebook uses JavaScript, specifically Deno.
To run this notebook, you will need to install Deno and set up the Deno Jupyter kernel.
Here are the basic instructions:
- Install Deno:
- MacOS / Linux:
curl -fsSL https://deno.land/x/install/install.sh | sh - Windows:
irm https://deno.land/install.ps1 | iex
- MacOS / Linux:
- Install Python: Download and install from python.org
- Install Jupyter:
pip install jupyterlab - Install Deno Jupyter kernel:
deno jupyter --unstableordeno jupyter --unstable --installto force installation of the kernel.
[1]
Step 3: Download the dataset
We will be using MongoDB's embedded_movies dataset
[2]
[3]
[4]
Step 4: Create a simple RAG chain using MongoDB as the vector store
[5]
[6]
{ acknowledged: [33mtrue[39m, deletedCount: [33m1500[39m } [7]
{ acknowledged: true, insertedCount: 1500 }
[8]
[9]
[10]
[11]
[12]
[32m"Once a Thief is a good movie to watch when sad because it is an action/comedy/romance film that can "[39m... 103 more characters
Step 5: Create a RAG chain with chat history
[13]
[14]
[15]
[16]
[17]
[18]
[32m'The best movie to watch when feeling sad would likely be "Last Action Hero." This film combines acti'[39m... 326 more characters
[19]
[32m`In that case, you may find "Smilla's Sense of Snow" to be a good choice. This film is a mystery thri`[39m... 311 more characters
[20]
[32m'For a lighter movie option, you may enjoy "Nicotina." This crime caper set in Mexico City is filled '[39m... 372 more characters