DEV Community

Devanshu Biswas
Devanshu Biswas

Posted on

Corrective RAG (CRAG): Grade the Retrieval, Then Fix It

Plain RAG has a fatal flaw: if retrieval returns garbage, the model confidently answers from garbage. Corrective RAG (CRAG) adds a self-check — grade the retrieved docs, and if they're bad, fix course before answering.

🔧 Run the pipeline: https://dev48v.infy.uk/prompt/day12-corrective-rag.html

The extra step: a retrieval evaluator

After retrieving, a lightweight grader scores each document's relevance to the question and assigns one of three verdicts:

  • Correct → use the docs as-is.
  • Incorrect → discard them and trigger a web search for fresh knowledge.
  • Ambiguous → combine retrieved docs + web results.

Knowledge refinement

Before generating, CRAG decomposes the kept documents into small "strips," drops the irrelevant ones, and recomposes only what matters — so the model sees signal, not noise.

Why it beats vanilla RAG

The model never has to answer from bad context. When your index doesn't have the answer, CRAG knows and goes looking, instead of hallucinating.

🔨 Full walkthrough (retrieve → grade → branch → refine → generate) with a live branching demo: https://dev48v.infy.uk/prompt/day12-corrective-rag.html

Part of PromptFromZero. 🌐 https://dev48v.infy.uk

Top comments (0)