English Retrieval Backend: RAG + MongoDB + Gemini 1.5 Pro + Semantic Router + Reflection

This demo will be presented at Google I/O Extended Surabaya 2024

  • Slide

  • Code to build Vector Search

  • Code to run RAG pipeline in Google Colab

Chatbot Architecture

Demo

Set up

1. Installation

This code requires Python >= 3.9.

pip install -r requirements.txt

2. Environment Variables

Create a file named .env and add the following lines, replacing placeholders with your actual values:

MONGODB_URI=
EMBEDDING_MODEL=
DB_NAME=
DB_COLLECTION=
GEMINI_KEY=
  • MONGODB_URI: URI of your MongoDB Atlas instance.
  • EMBEDDING_MODEL: Name of the embedding model you're using for text embedding.
  • DB_NAME: Name of the database in your MongoDB Atlas.
  • DB_COLLECTION: Name of the collection within the database.
  • GEMINI_KEY: Your key to access the Gemini API.

3. Data

Sample data here

Make sure you create a Vector Search Index. Follow this video.

4. Edit your Prompt in serve.py

In the serve.py file, you can see that we used the prompt like this. This prompt was enhanced by adding information about your products to it.

Become a sales consultant for a phone store. Customer's question: {query}\nAnswer the question based on the following product information: {source_information}.
  • query: Query from the user.
  • source_information: Information we get from our database.

The full prompt will look like this:

Become a sales consultant for a phone store. Customer's question: Could you provide more detailed information about the Tracfone Samsung A15 4G?
Answer the question based on the following product information:
 1) Name: Tracfone Samsung A15 4G , 128 GB, LTE, 6GB RAM, Black - Prepaid Smartpone [Locked to Tracfone Wireless}, Price: $149.00, Rating: 4.0
 2) Name: Tracfone Samsung Galaxy A14, 5G, 64GB, Black - Prepaid Smartphone [Locked to Tracfone], Price: $99.88, Rating: 4.1
 3) Name: AT&T Samsung Galaxy A15 5G, 128GB, 4GB RAM, Black - Prepaid Smartphone, Price: $139.00, Rating: 2.9
 4) Name: AT&T Samsung Galaxy A15 5G, 128GB, 4GB RAM, Black - Prepaid Smartphone, Price: $139.00, Rating: 2.9
 5) Name: Tracfone Motorola moto g 5G (2024), 64GB, Gray - Prepaid Smartphone [Locked to Tracfone], Price: $99.88, Rating: 3.8
 6) Name: AT&T Samsung Galaxy A14 5G, 64GB Black - Prepaid Smartphone, Price: $69.88, Rating: 3.7
 7) Name: AT&T Samsung Galaxy A14 5G, 64GB Black - Prepaid Smartphone, Price: $69.88, Rating: 3.7
 8) Name: Tracfone BLU View 5, 64GB, Black - Prepaid Smartphone [Locked to Tracfone], Price: $29.88, Rating: 3.4
 9) Name: Tracfone BLU View 5 Pro, 64GB, Black - Prepaid Smartphone [Locked to Tracfone], Price: $69.88, Rating: 3.8
 10) Name: Tracfone Motorola moto g Play 4G (2024), 64GB, Black - Prepaid Smartphone [Locked to Tracfone], Price: $49.88, Rating: 3.8.

The prompt is then fed to LLMs.

5. Run server

python serve.py

6. Testing API

Testing on web-app. Link