Corrective RAG Adaptive QA System
1. Project Overview
An adaptive Retrieval-Augmented Generation (RAG) system that adds a self-evaluation step: if local retrieval is weak, it automatically triggers Tavily web search to fetch better context, reducing hallucination and “forced answers.” Built with LangGraph to model the end-to-end QA state machine.
Key stack: Python, LangGraph, OpenAI API, ChromaDB, Tavily Search, FastAPI, Streamlit.
2. Architecture
Flow: Query → Retrieve from ChromaDB → Grade relevance →
Relevant? → Generate answer
Not/uncertain? → Tavily web search → Rerank → Generate answer.
State machine implemented via LangGraph; vector store persisted under ./chroma_db for reuse.
3. Core Features
- Corrective retrieval: Grades documents; falls back to web search when needed.
- Tool orchestration: LangGraph manages retrieval, grading, generation steps.
- Multi-interface:
- CLI (
python main.py) - Streamlit UI (
streamlit run app.py) - FastAPI service (
uvicorn api_server:app --reload, docs at/docs)
- CLI (
- Rebuild switch:
FORCE_REBUILD_VECTOR_STORE=trueto force vector store refresh.
4. How to Run
pip install -r requirements.txt- Set
OPENAI_API_KEY(and Tavily key if available). - Choose an interface:
- CLI:
python main.py - Streamlit:
streamlit run app.py - FastAPI:
uvicorn api_server:app --reload
- CLI:
5. Highlights
- Dramatically lowers hallucination via relevance grading + web fallback.
- Modular graph nodes make it easy to extend tools or change LLM backends.
- Persistent vector store speeds cold starts; rebuild toggle supports fresh ingests.