Self-RAG and CRAG explained: grading passages, corrective retrieval and web fallback
Plain RAG trusts whatever retrieval returns. Self-RAG and Corrective RAG add a check: grade the passages, then answer, refine, search again or fall back to the web. This guide explains both papers, runs a CRAG-style loop in Python and shows where the grader itself can fail.
- Reading time
- 14 min
- Sections
- 7
- Code examples
- 2
- Tables
- 4
- Sources
- 7
- Published
- 24 Nov 2026
- What changed
- TruLens 2.16.0 ships graders for the RAG triad
- Why it matters
- The lasting contribution of these papers is a pattern: grade, then branch.
- What to do
- Add a grading step after retrieval
A plain retrieval-augmented generation (RAG) pipeline has a blind trust problem. Whatever the retriever returns goes into the prompt, and the model does its best with it. If the passages are off-topic, out of date or contradictory, the model may still produce a fluent, confident and wrong answer. The pipeline never asks: was this evidence any good?
Two influential research designs added that question. Self-RAG, from Akari Asai and colleagues, trains a model to decide when to retrieve and to critique the passages and its own output with special reflection tokens. Corrective RAG (CRAG), from Yan and colleagues, adds a lightweight retrieval evaluator that grades the retrieved passages and triggers a corrective action: use them, refine them, or search the web instead. Their ideas, grading and branching, are now standard building blocks in production RAG, and the tools that supply graders and branching logic released new versions this autumn. This article explains both designs, implements a CRAG-style loop in runnable Python, and shows how the grader itself becomes the new weak point.
An analogy: plain RAG is a student who copies from whatever book the librarian hands over. CRAG is a student who first skims the book, decides whether it is the right one, and walks to another library if it is not. Self-RAG is a student trained to ask, sentence by sentence, "do I need a source here, and does my source actually say this?"
What happened
TruLens 2.16.0 ships graders for the RAG triad (19 October 2026)
TruLens, the open-source evaluation and tracing library, released 2.16.0 on PyPI on 19 October 2026. Its project description centres on the "RAG triad" of context relevance, groundedness and answer relevance, and shows a Selector API for scoring the relevance of each retrieved context to the question. It reports, as a project benchmark, a groundedness F1 of 0.81 on the LLM-AggreFact benchmark over an 11,000-example holdout, which it says is ahead of the fine-tuned Bespoke-MiniCheck-7B model on F1, precision and recall. Context relevance and groundedness are exactly the two checks that CRAG and Self-RAG put inside the pipeline rather than after it.
Haystack 3.5.0 adds to its branching toolkit (10 November 2026)
Haystack 3.5.0, released on 10 November 2026, includes a ConditionalRouter that sends data down different pipeline branches based on Jinja2 conditions, each route with a condition, an output, an output type and an output name. An optional output_passthrough flag passes complex objects through without template processing. This is the plumbing a corrective pipeline needs: "if the best grade is above the upper threshold, generate; if below the lower threshold, call web search; otherwise do both".
How Self-RAG works
Self-RAG (arXiv 2310.11511, ICLR 2024) trains a generator model whose vocabulary is extended with reflection tokens. The repository describes two models, a critic and a generator, both trained with standard next-token prediction on data where GPT-4 supplied the reflection labels. At inference the generator emits these tokens as it writes:
| Reflection token | Question it answers | Example values |
|---|---|---|
| Retrieve | Do I need to retrieve for the next segment? | [Retrieve], [No Retrieval] |
| IsRel | Is this passage relevant to the question? | [Relevant], [Irrelevant] |
| IsSup | Is my segment supported by the passage? | [Fully supported], partial, none |
| IsUse | How useful is the overall answer? | [Utility:1] to [Utility:5] |
Because these are ordinary tokens, their probabilities are available at every step. Self-RAG retrieves on demand: the repository's example shows the model answering a general question with [No Retrieval] and requesting retrieval for a question that needs factual grounding. When it retrieves several passages, it generates a candidate segment for each and runs a segment-level beam search that ranks candidates by their likelihood plus weighted critique scores. The repository's defaults are w_rel = 1.0, w_sup = 1.0, w_use = 0.5, a retrieval threshold of 0.2, a maximum depth of 6 and a beam width of 2.
A worked example with illustrative probabilities shows how the critique terms change the choice:
score = log p(segment) + w_rel × p(IsRel) + w_sup × p(IsSup) + w_use × p(IsUse)
| Candidate | log p | p(IsRel) | p(IsSup) | p(IsUse high) | Score |
|---|---|---|---|---|---|
| Answer from passage A | −4.0 | 0.95 | 0.90 | 0.8 | −1.75 |
| Answer from passage B | −3.2 | 0.40 | 0.20 | 0.9 | −2.15 |
| Answer without retrieval | −2.5 | 0.0 | 0.0 | 0.7 | −2.15 |
The answer without retrieval is the most fluent (highest log probability), but the answer grounded in passage A wins once relevance and support count. That is Self-RAG's core idea, a trained form of reflection: make "is this supported?" part of decoding, not a check after the fact. The cost is that you need a model trained this way; you cannot add reflection tokens to an API model by prompting alone. The Self-RAG simulation walks through the token decisions.
How CRAG works
CRAG (arXiv 2401.15884) works with any generator. Its README describes "a lightweight retrieval evaluator" that "assess[es] the overall quality of retrieved documents for a query, returning a confidence degree based on which different knowledge retrieval actions can be triggered". In the paper the evaluator is a fine-tuned T5-large model, and two thresholds split its confidence into three actions:
| Evaluator result | Action | What reaches the generator |
|---|---|---|
| At least one passage above the upper threshold: Correct | Refine the retrieved passages | Relevant sentences ("knowledge strips") from the corpus |
| All passages below the lower threshold: Incorrect | Discard them and search the web | Refined web results |
| In between: Ambiguous | Do both | Refined corpus strips plus refined web results |
The refinement step is a "decompose-then-recompose" algorithm: split each passage into small strips, grade each strip, keep only the relevant ones and join them. It removes the noise around a relevant sentence. The README states that web searches are used "as an extension for augmenting the retrieval results" because static corpora "can only return sub-optimal documents", and that CRAG is "plug-and-play" with other RAG methods, including Self-RAG (the authors evaluate a Self-CRAG variant). The corrective RAG simulation shows the three branches.
A CRAG-style loop in Python
The script implements the CRAG control flow with a simple keyword grader, so it runs without downloads. In production the grader would be a fine-tuned evaluator, a cross-encoder or an LLM judge. The grader here also halves its score when the question names a year that the passage does not contain.
import re
def grade(query, passage):
q = set(re.findall(r"\w+", query.lower())) - {"the", "of", "a", "is", "what", "in"}
p = set(re.findall(r"\w+", passage.lower()))
score = len(q & p) / len(q)
if {w for w in q if re.fullmatch(r"(19|20)\d\d", w)} - p:
score *= 0.5 # question names a year the passage lacks
return score
UPPER, LOWER = 0.6, 0.2
def crag(query, passages, web_search):
scores = [grade(query, p) for p in passages]
best = max(scores)
if best >= UPPER:
action, docs = "CORRECT", [p for p, s in zip(passages, scores) if s >= LOWER]
elif best <= LOWER:
action, docs = "INCORRECT", web_search(query)
else:
action, docs = "AMBIGUOUS", [p for p, s in zip(passages, scores) if s > LOWER] + web_search(query)
strips = [s for d in docs for s in re.split(r"(?<=\.)\s+", d) if grade(query, s) > LOWER]
return action, [round(s, 2) for s in scores], strips
WEB = {"heat pump tariff 2026": "Heat pump tariff for 2026: 0.21 EUR per kWh.",
"wind turbine permits": "Wind turbine permits are issued by the regional planning office."}
web = lambda q: ["(web) " + WEB[q]] if q in WEB else []
corpus = ["Heat pump electricity tariff: 0.19 EUR per kWh in 2025. Meters are read monthly.",
"Solar panels qualify for a 30 percent grant."]
for q in ["heat pump electricity tariff 2025", "heat pump tariff 2026", "wind turbine permits"]:
print(q, "->", crag(q, corpus, web))
| Question | Grades | Action | Evidence passed to the generator |
|---|---|---|---|
| heat pump electricity tariff 2025 | 1.0, 0.0 | Correct | "Heat pump electricity tariff: 0.19 EUR per kWh in 2025." |
| heat pump tariff 2026 | 0.38, 0.0 | Ambiguous | The 2025 sentence plus the web result "Heat pump tariff for 2026: 0.21 EUR per kWh." |
| wind turbine permits | 0.0, 0.0 | Incorrect | Only the web result on permits |
Three behaviours are worth noticing. In the first case refinement drops "Meters are read monthly", so the prompt carries only the sentence that matters. In the third case the corpus has nothing relevant, and instead of answering from a passage about solar grants, the pipeline goes to the web. The second case is the instructive one. Without the year rule, the keyword grader scored the 2025 passage 0.75 for a 2026 question and would have labelled it Correct, passing an out-of-date tariff as the answer. With the rule, the case becomes Ambiguous and the generator receives both the stale and the current figure. It must still pick the right one, which is why the prompt should tell it to prefer the source that matches the requested date.
Continue learning
How this article connects
6 pages link to or from it. Drag to turn, click a dot to open it.
What it means in practice
The lasting contribution of these papers is a pattern: grade, then branch. Most teams will not train a Self-RAG model, but almost every serious RAG system now grades retrieval in some way, with a reranker score, a context-relevance judge or a small classifier, and does something different when the grade is low: retrieve more, rewrite the query, search another source, or say "I don't know".
CRAG's three-way split is a practical template because it separates two failure modes. Low-confidence retrieval with a good fallback source (the web, a broader index) should trigger a search there. Low-confidence retrieval with no fallback should trigger an honest refusal. Mixing those up produces either needless web calls or confident answers from irrelevant text.
The grader is now the component to test. The worked example shows how a grader that matches topic but ignores dates, versions or entities can wave through the wrong passage. Graders need their own evaluation set, with near misses such as the wrong year, the wrong product version and the right topic with the wrong answer. Library graders such as those in TruLens come with published benchmark claims, but those are measured on public data; check them on yours. The site's LLM judge agreement simulation shows why judge reliability needs measuring.
Grading also has a price. A cross-encoder grader adds tens of milliseconds per batch of passages; an LLM judge adds a full model call, and strip-level refinement grades every sentence, which can mean dozens of grader calls per question. A sensible design grades passages with a fast model, refines only the passages that pass, and reserves LLM judges for the Ambiguous band, where a second opinion changes the action. These patterns belong to the wider family of advanced RAG techniques, and when the branching logic itself is handed to a model that chooses its next step, corrective retrieval becomes agentic RAG.
Self-RAG's idea of checking support sentence by sentence survives as post-generation groundedness checks: split the answer into claims, verify each against the context, and flag or remove unsupported ones. It is slower than decoding-time critique but works with any model.
What to do now
- Add a grading step after retrieval. Use your reranker score or a context-relevance judge, and log it for every query.
- Set two thresholds, not one. Calibrate an upper and a lower threshold on labelled questions so you get Correct, Ambiguous and Incorrect bands.
- Decide the fallback for each band. Web search, a broader index, a query rewrite or a refusal; make the choice explicit in a router.
- Refine passages into strips. Keep only relevant sentences or short spans before generation to cut noise and tokens.
- Build a grader test set with near misses. Include wrong years, versions and entities, and measure how often the grader is fooled.
- Tell the generator how to resolve conflicts. When both stale and fresh evidence arrive, the prompt should say which wins, for example the source matching the requested date.
- Check groundedness after generation. Verify each claim in the answer against the context and flag unsupported ones.
- Restrict web fallback. Allow-list domains, record which answers used the web, and show users when an answer came from outside the corpus.
- Measure the cost of branches. Track how often each band fires; frequent web fallbacks may signal gaps in your corpus.
Risks and open questions
The grader can be wrong in both directions. False positives pass bad passages, as the year example showed; false negatives trigger needless web searches and discard good evidence.
Web fallback brings untrusted content. Web pages can be wrong, stale, or written to manipulate models. Corrective retrieval widens the attack surface for prompt injection.
Self-RAG needs a specially trained model. Its reflection tokens come from fine-tuning. Prompted imitations of the tokens with general models are not the same method and need their own evaluation.
Thresholds drift. Grader score distributions change when you change the embedding model, reranker or corpus. Re-calibrate thresholds after every retrieval change.
Benchmark claims are context-specific. Results reported by papers and vendors, such as groundedness F1 on public datasets, may not transfer to your documents and languages.
Watch next: whether evaluation libraries' groundedness and relevance graders become standard in-pipeline routers rather than offline metrics, and how corrective designs combine with agentic RAG loops that can choose their own fallback sources.
Frequently asked questions
What is the difference between Self-RAG and CRAG?
Self-RAG trains the generator itself to decide when to retrieve and to critique relevance and support with special reflection tokens. CRAG keeps any generator and adds a separate retrieval evaluator that grades passages and triggers refinement or web search. CRAG is easier to add to an existing pipeline.
Do I need web search to use CRAG?
No. Web search is the fallback in the paper, but any second source works, such as a broader index, another database or a query rewrite. If there is no trustworthy fallback, the Incorrect branch should lead to an honest "not found" answer.
What model should grade retrieved passages?
A cross-encoder reranker, a small fine-tuned classifier or an LLM judge can all work. Choose by latency and accuracy on a test set that includes near misses. The CRAG paper used a fine-tuned T5-large evaluator.
Can I use Self-RAG with a hosted API model?
Not as published, because the method relies on a model fine-tuned with reflection tokens. You can approximate parts of it, such as asking whether retrieval is needed and checking support after generation, but those are prompted variants that need their own evaluation.
How do I choose the upper and lower thresholds?
Score a labelled set of questions with your grader, then pick the upper threshold where passages above it are almost always relevant and the lower threshold where passages below it almost never are. Re-check both whenever retrieval components change.
Summary
Self-RAG and Corrective RAG stop RAG from trusting retrieval blindly. Self-RAG trains a model to emit reflection tokens that decide when to retrieve and score relevance, support and usefulness, then picks segments with a critique-weighted beam search; in the worked example a grounded answer beat a more fluent ungrounded one. CRAG adds a separate evaluator with two thresholds: Correct refines passages into relevant strips, Incorrect switches to web search, Ambiguous does both. The runnable loop showed both the benefit and the new risk: a grader that ignores dates passed a stale tariff until a year check moved the case to Ambiguous. With graders such as TruLens 2.16's and routers such as Haystack 3.5's ConditionalRouter available, the practical recipe is grade, branch, refine, and test the grader as carefully as the retriever.
Sources
- Paper arXiv: Self-RAG: Learning to Retrieve, Generate, and Critique through Self-Reflection (Asai et al.)
- Code GitHub: Self-RAG README
- Paper arXiv: Corrective Retrieval Augmented Generation (Yan et al.)
- Code GitHub: CRAG README
- Code PyPI: trulens project description and release history
- Code PyPI: haystack-ai release history
- Code GitHub: Haystack ConditionalRouter source
Cite this article
Kelahmet, Ö. C. (2026, November 24). Self-RAG and CRAG explained: grading passages, corrective retrieval and web fallback. Özer Cem KELAHMET. https://www.ozercemkelahmet.com/articles/self-rag-crag-grading-corrective-retrieval
BibTeX
@online{kelahmet2026self,
author = {Kelahmet, {\"O}zer Cem},
title = {{Self-RAG and CRAG explained: grading passages, corrective retrieval and web fallback}},
year = {2026},
month = {nov},
url = {https://www.ozercemkelahmet.com/articles/self-rag-crag-grading-corrective-retrieval}
}Version historyfirst version
- Published
Factual corrections are listed here with what changed. Wording and formatting edits are not listed.