Advanced RAG/Advanced Patterns
Advanced11 min

Self-Corrective RAG: Grade, Rewrite, Re-Retrieve

Corrective RAG adds document grading and question rewriting to the retrieval loop — if retrieved documents don't answer the question, the system rewrites the query and tries again.

Quick Reference

  • Self-Corrective RAG = retrieve → grade documents → generate OR rewrite query → re-retrieve
  • Document grading uses structured output (GradeDocuments) to score relevance before generation
  • If documents fail grading, the query is rewritten and retrieval runs again with the improved query
  • Prevents hallucination from irrelevant context — the LLM only sees high-quality documents
  • Implement as a LangGraph cycle: retrieve → grade → conditional edge → generate or rewrite
  • Typically improves answer quality by 20-35% over naive RAG on ambiguous queries

Why Standard RAG Fails

QueryRetrieveHybrid search + rerankGrade DocumentsStructured output: relevant?Relevant?YesGenerateAnswer with citationsNoRewriteImprove queryre-retrieveAnswer

Retrieve → grade → generate if relevant, rewrite and re-retrieve if not (max 2 retries)

Standard 2-step RAG (retrieve → generate) has a critical weakness: it trusts whatever the retriever returns. If the query is ambiguous, poorly worded, or the relevant documents use different terminology, the retriever returns irrelevant chunks. The LLM then either hallucinates an answer from bad context or produces a generic non-answer. Self-Corrective RAG adds a feedback loop that catches this before generation.

StepStandard RAGSelf-Corrective RAG
1. RetrieveRetrieve top-K docsRetrieve top-K docs
2. ValidateSkip — trust retrieverGrade each document for relevance
3a. If goodGenerate answerGenerate answer
3b. If badGenerate anyway (hallucinate)Rewrite query → re-retrieve → grade again
Result60-70% answer quality85-95% answer quality on ambiguous queries