A powerful, production-ready Retrieval-Augmented Generation (RAG) system built with LangGraph, Gemini, and Streamlit. This project features a self-correction loop that grades document relevance and fallbacks to web search when information is missing.
- Self-Correction Architecture: Uses LangGraph to grade retrieved documents and automatically trigger web search if context is insufficient.
- Conversational Memory: Maintains the last 5 turns of conversation for seamless follow-up questions.
- Multi-Query Retrieval: Automatically generates variations of your question to improve context coverage.
- Quota Optimized: Implements Batch Grading and defaults to Gemini 3.1 Flash Lite to save 80%+ of API quota.
- Modern Web UI: A beautiful Streamlit interface with live "reasoning" logs and file upload support.
- Full Citations: Every answer includes metadata-backed citations from your documents.
- Orchestration: LangGraph
- LLM: Google Gemini (Flash 3.1 & 2.0)
- Vector Database: ChromaDB
- Web Search: Tavily AI
- UI Framework: Streamlit
git clone https://github.com/sathiya-22/self-correcting-rag.git
cd self-correcting-ragCreate a .env file in the root directory:
GOOGLE_API_KEY=your_gemini_key
TAVILY_API_KEY=your_tavily_key
# Optional: Override default models
# MODEL_GRADER=gemini-3.1-flash-lite-preview
# MODEL_GENERATOR=gemini-3.1-flash-lite-preview# Recommended: use a virtual environment
python -m venv venv
source venv/bin/activate
pip install -r requirements.txtstreamlit run app.pyapp.py: Streamlit web interface.graph/: Core LangGraph logic (nodes, edges, state).ingest.py: Document processing and vector ingestion.knowledge_base/: Drop your PDFs/DOCX files here.chroma_db/: Local vector storage.
MIT License. Free for personal and commercial use.