This project is a Retrieval-Augmented Generation (RAG) system template. It leverages Google Gemini for generation and embeddings, and MongoDB Atlas as the vector store to manage and retrieve context for answering user queries.
Slides for the GHW stream can be found here
- Vector Store: Uses MongoDB Atlas Vector Search to store and retrieve document embeddings.
- Embeddings: Powered by Google's
model/embeddings-001. - LLM: Uses Google's
gemini-2.5-flashmodel for generating responses. - Framework: Built using LangChain and Streamlit.
Before running the application, ensure you have the following:
- Python 3.8+ installed.
- A MongoDB Atlas cluster with a vector search index configured.
- A Google Cloud Project with the Generative AI API enabled and an API key.
-
Clone the repository:
git clone <your-repo-url> cd <your-repo-directory>
-
Create and activate a virtual environment (recommended):
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
This project uses streamlit.secrets for managing sensitive configuration. You typically need to configure two main components: MongoDB and Google AI.
-
Create a secrets file: Create a folder named
.streamlitin your project root and add a file namedsecrets.toml:# .streamlit/secrets.toml MONGO_URI = "mongodb+srv://<username>:<password>@<cluster>.mongodb.net/?retryWrites=true&w=majority"
-
Environment Variables: The LangChain Google integration typically requires the
GOOGLE_API_KEYenvironment variable. You can set this in your terminal or add it to a.envfile (if you extend the setup to load it):export GOOGLE_API_KEY="your-google-api-key"
-
MongoDB Atlas Setup: Ensure your MongoDB collection (
vector_store_database.embeddings_stream) has a Vector Search Index namedvector_index_ghw.- Database Name:
vector_store_database - Collection Name:
embeddings_stream - Index Name:
vector_index_ghw
Example Index Definition:
{ "fields": [ { "numDimensions": 768, "path": "embedding", "similarity": "cosine", "type": "vector" } ] } - Database Name:
The core logic is contained in backend.py. You can import these functions into a Streamlit frontend or another Python script.
ingest_text(text_content): Takes a string of text, creates a document, calculates its embedding, and stores it in MongoDB.get_rag_response(query): Performs a similarity search for the top 3 relevant documents in MongoDB and uses the Gemini LLM to answer thequerybased on that context.