This is a demo of a chatbot assistant using retrieval augmented generation (RAG).
The client is built with Angular and Angular Material. The server is built with Express.js and uses MongoDB Atlas for storing the vector data. The embeddings are generated with Google Cloud embeddings model. The conversation model uses Gemini 1.0 Pro model. The app also utilizes Langchain.
-
Node.js LTS.
-
Google Cloud account with Vertex AI APIs enabled.
Follow the steps below to set up the chat assistant for local development.
-
Create a MongoDB Atlas account and deploy a free database. Complete the quickstart guide — create a database user and allowlist your IP address.
-
Clone the repository.
git clone https://github.com/mongodb-developer/Google-Cloud-RAG-Langchain.git rag-chatbot cd rag-chatbot
-
Create a
.env
file with the following content:ATLAS_URI=<your-atlas-connection-string>
-
Run the embedding script to vectorize the PDF data and store it in MongoDB Atlas.
rag-chatbot/
npm run embed-documents
-
Go back to MongoDB Atlas and verify that the data has been stored in the
context
collection. -
Switch to the Atlas Search tab and click
Create Search Index
. SelectJSON Editor
in the Atlas Vector Search section. This is the last option in the list. -
From the left sidebar, select the
chat-rag
database and thecontext
collection. -
Add the following JSON schema:
{ "fields": [ { "numDimensions": 768, "path": "embedding", "similarity": "euclidean", "type": "vector" } ] }
-
Wait for the status to change to
Active
.
-
Start the application with the following command:
rag-chatbot/
npm start
-
Open a browser and navigate to
http://localhost:4200
. -
Try asking the chatbot questions like "What is the coverage of my insurance policy?" or "What are the specifics of my car insurance?". Use the
RAG
toggle to switch between retrieval augmented generation and retrieval only.
This demo is inspired by the Chat Application with RAG Feature Toggle and Backend Server.
Stanimira Vlaeva |
Use at your own risk; not a supported MongoDB product