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)
  • Rebuild switch: FORCE_REBUILD_VECTOR_STORE=true to force vector store refresh.

4. How to Run

  1. pip install -r requirements.txt
  2. Set OPENAI_API_KEY (and Tavily key if available).
  3. Choose an interface:
    • CLI: python main.py
    • Streamlit: streamlit run app.py
    • FastAPI: uvicorn api_server:app --reload

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.

https://github.com/lijinxuan1101/Corrective-RAG