This repository provides a clean implementation of a Retrieval-Augmented Generation (RAG) system using MongoDB Atlas as a Vector Database and LlamaIndex for orchestration.
- Vector Ingestion: Process local documents and store them as high-dimensional vectors in MongoDB.
- Semantic Retrieval: Uses MongoDB Atlas Vector Search to find relevant context.
- Contextual Generation: Powered by OpenAI to provide accurate answers based on your private data.
load_data.py: Script to initialize the vector store and upload your document embeddings.rag.py: The query engine used to ask questions against the indexed data.key_param.py: Configuration file for API keys and connection strings.
- Python 3.9+
- A MongoDB Atlas Cluster (M0 tier or higher).
- An OpenAI API Key.
You must create a Vector Search index in your MongoDB Atlas dashboard. Use the name vector_index and ensure the path is set to embedding with 1536 dimensions (for OpenAI embeddings) using cosine similarity.
Run the following commands to set up your environment:
- git clone https://github.com/muhammadcaeed/rag_with_mongodb.git
- cd rag_with_mongodb
- pip install llama-index pymongo llama-index-vector-stores-mongodb llama-index-embeddings-openai
Update your key_param.py file with your specific credentials including your MONGO_URI, OPENAI_API_KEY, and the specific Database and Collection names you intend to use.
- Load your data: Place your source documents in a folder named
/dataand runpython load_data.py. - Query the system: Once indexed, run
python rag.pyto start the interactive query engine.