~/projects/corrective-rag.md
Corrective RAG
Grades what the retriever returns before trusting it. Weak context triggers a rewritten web search.
- CORRECT / INCORRECT score thresholds
- 0.7 / 0.3
- verdict routes
- 3
- graph nodes
- 6
Repository (opens in a new tab)All projects
How it works
- CORRECT: retrieve → evaluator → refine → generate → END
- INCORRECT: retrieve → evaluator → rewrite query → web search → refine → generate → END
- AMBIGUOUS: retrieve → evaluator → rewrite query → web search → refine → generate → END
What it does
- A retrieval evaluator scores every chunk from 0 to 1: CORRECT above 0.7, INCORRECT when all are below 0.3, otherwise AMBIGUOUS.
- Knowledge refinement: splits context into sentence strips, filters them, and recomposes before answering.
- Answers come only from the refined context, with citations (file and page, or URL), and say so when context is insufficient.
- All Gemini calls go through one batched path that retries 429s, 5xx errors and timeouts with backoff and jitter.
Stack
- LangGraph
- LangChain
- Gemini
- Pinecone
- Ollama
- Tavily
- Streamlit