Self-RAG: a model that decides when to retrieve and checks itself
Self-RAG lets the model choose whether to look things up, judge each passage, and check its own answer against the evidence. Use it when answers must be supported and not every question needs a search.
Self-RAG in 60 seconds
- What: a model trained to emit reflection tokens that control retrieval and critique its own output.
- Four judgements: is retrieval needed, is this passage relevant, is my text supported by the passage, and is the answer useful.
- Payoff: retrieval only when it helps, and answers that are checked against sources.
- Catch: the original method needs a specially trained model; most teams approximate it with prompts and a verification step.
- Watch for: extra latency from several candidate generations and judgements that are only as good as the judge.
Where this type fits
Self-RAG sits in the quality-loop family, next to corrective, advanced, and HyDE retrieval. What sets it apart is where the loop lives: inside the generation process, not around it. See the overview of RAG types for the other families.
The problem it solves
Standard RAG has two blind spots. It retrieves whether or not retrieval helps, so a question such as write a friendly greeting for a customer pulls in documents that only clutter the prompt. And it trusts whatever it retrieves, so a passage that looks related but says something different can lead the model into a confident mistake.
Picture a writer with an editor sitting on their shoulder. Before each claim the editor asks: do you need a source for this? Is the source you picked actually about this? Does your sentence say what the source says? Basic RAG has no editor. A pipeline with an external grader, as in corrective RAG, has an editor who reviews the pile of sources once, before the writing starts. Self-RAG puts the editor inside the writing, so checks happen at the level of each segment of the answer.
There is a second motive: cost and speed. If a model can tell that a question needs no lookup, it skips search and the extra tokens. Applied across many requests, selective retrieval keeps the system lean without giving up grounding where it matters.
How it works
The method comes from Self-RAG: Learning to Retrieve, Generate, and Critique through Self-Reflection (Asai et al., 2023). The authors train a single model to produce, along with ordinary text, special reflection tokens. These tokens are the model's own notes about retrieval and quality, and they are what the control logic reads.
- Decide on retrieval: while generating, the model emits a token that says whether a search is needed for the next segment.
- Retrieve: if yes, the system fetches several passages for the question and the text so far.
- Judge relevance: for each passage the model emits a relevance token, marking whether the passage is useful for the question.
- Generate per passage: the model writes a candidate segment conditioned on each passage in parallel.
- Judge support: each candidate gets a token saying whether the claims are supported by its passage, fully, partly, or not at all.
- Judge usefulness: each candidate also gets a rating for how useful the whole response is to the question.
- Select: the system ranks candidates using the reflection tokens, keeps the best segment, and continues until the answer is complete.
The reflection tokens act like a scoreboard. Because they are produced by the model itself, the decision to search, the grading of passages, and the support check happen in one forward process instead of in separate service calls. At inference time the system can also weight the judgements: if you care more about factual support than fluency, you rank candidates by the support token first.
Write-ups differ on what Self-RAG is. Some popular descriptions present it as a loop of self-checking and query rewriting that any model can run. The paper describes something narrower and more specific: a model trained with reflection tokens. Most teams do not train such a model. They approximate the idea with prompts that ask a general model to judge passages, plus a separate verification step on the draft. That approximation is useful, but it is a cousin of the method, and it lacks the trained, calibrated judgements. This page covers both and flags which is which.
A worked example
Acme runs an internal policy assistant. Two questions arrive in the same minute.
- Question A: Rewrite this sentence to sound more polite. Retrieval decision: not needed. The model answers directly. No search, no extra tokens.
- Question B: How many days of parental leave does Acme offer, and can they be split? Retrieval decision: needed.
- Retrieve: three passages return: the leave policy (section 4), a manager handbook note on scheduling, and an old FAQ from before the policy changed.
- Relevance: the policy is judged relevant, the handbook note partly relevant, the old FAQ relevant on topic but a poor match on content.
- Candidates: the model writes one answer segment per passage. From the policy: 16 weeks, may be taken in two blocks within the first year. From the FAQ: 12 weeks, one block. From the handbook note: nothing definite.
- Support check: the policy candidate is fully supported. The FAQ candidate is supported by its own passage but ranked below because relevance and recency signals are weaker. The handbook candidate is flagged as not supported.
- Select: the policy candidate wins. The system appends it, cites section 4, and the answer finishes.
{
"retrieve": "yes",
"candidates": [
{ "source": "leave-policy", "relevant": "yes", "supported": "fully", "useful": 5 },
{ "source": "old-faq", "relevant": "partly", "supported": "fully", "useful": 3 },
{ "source": "manager-note", "relevant": "partly", "supported": "no", "useful": 2 }
],
"selected": "leave-policy"
}Building it
Below is the prompt-based approximation, which any general model can run. It follows the same four judgements but replaces trained tokens with explicit judge calls. All model and search functions are placeholders.
# Placeholders: llm.generate(), embed(), vector_store. Replace with your own.
MAX_SEGMENTS = 6 # stop long answers from looping forever
MAX_PASSAGES = 3
MIN_SUPPORT = 0.7
def judge(prompt):
# Ask the model for a single number; fall back to a neutral score.
raw = llm.generate(prompt) # placeholder
try:
return min(1.0, max(0.0, float(raw.strip())))
except ValueError:
return 0.5
def needs_retrieval(question, draft):
p = ('Question: ' + question + '\nAnswer so far: ' + draft +
'\nDoes the next sentence need an outside source? Reply 0 to 1.')
return judge(p) > 0.5
def next_segment(question, draft):
if not needs_retrieval(question, draft):
return llm.generate('Continue briefly. ' + question + '\n' + draft), None
passages = vector_store.search(embed(question + ' ' + draft), k=MAX_PASSAGES)
best, best_score = None, -1.0
for ps in passages:
rel = judge('Is this passage relevant to: ' + question + '?\n' + ps.text)
if rel < 0.4:
continue # skip passages the judge calls irrelevant
text = llm.generate('Using only this passage, write the next sentence.\n'
+ ps.text + '\n' + question + '\n' + draft)
sup = judge('Passage:\n' + ps.text + '\nClaim:\n' + text +
'\nHow fully does the passage support the claim?')
score = 0.6 * sup + 0.4 * rel # weights favour support over relevance
if sup >= MIN_SUPPORT and score > best_score:
best, best_score = (text, ps), score
return best if best else (None, None)
def answer(question):
draft, sources = '', []
for _ in range(MAX_SEGMENTS):
seg, src = next_segment(question, draft)
if seg is None:
break # nothing supported: stop rather than invent
draft += ' ' + seg
if src:
sources.append(src.id)
if llm.generate('Is the answer complete? yes/no\n' + draft).strip() == 'yes':
break
return draft.strip() or 'I could not find a supported answer.', sourcesIf you do have a model trained for reflection tokens, the structure stays the same, but the judge calls disappear: the tokens arrive in the generation output and you parse them. Your code then becomes mostly a ranker and a loop controller.
Design decisions
- Trained model or prompts: start with prompts and a separate verifier. Train a reflection model only when volume, latency, and labelled data justify the effort, and budget for retraining as sources change.
- Judge placement: use a smaller model for relevance and support judgements and a larger one for writing. Judges are called many times, so their cost dominates.
- Parallelism: generate candidates per passage in parallel and bound the number of passages. Latency otherwise grows with passage count.
- Segment size: judge at sentence or short-paragraph level. Smaller units catch more errors but multiply calls.
- Access control: filter passages by user permissions before generation, not after, so unauthorised text is never seen by the model.
- Failure handling: if no candidate passes the support floor, return a refusal or an answer marked as unverified. Never fall back silently to ungrounded text.
- Versioning: record model, judge prompt, weights, and thresholds with each answer, since shifting any of them changes behaviour.
Measuring it
- Retrieval-decision accuracy: on questions labelled as needing or not needing a source, the share where the system chose correctly.
- Citation precision: the share of cited passages that actually contain the claim attached to them, checked by people on a sample.
- Faithfulness: the share of answer claims entailed by the retrieved passages. Compare against plain RAG on the same questions.
- Judge agreement: correlation between the model's support judgements and human labels, since all selection rests on them.
- Cost per answer: number of model calls and tokens, with latency percentiles, against plain RAG.
def decision_accuracy(examples):
# examples: (question, needs_source) pairs labelled by people.
correct = 0
for question, needs_source in examples:
predicted = needs_retrieval(question, '')
correct += (predicted == needs_source)
return correct / len(examples) if examples else 0.0When to use it, and when not to
| Situation | Use this type? | Why |
|---|---|---|
| Mixed traffic where many questions need no lookup | Yes | Selective retrieval saves tokens and keeps simple replies fast. |
| Answers must be traceable to sources | Yes | Per-segment support checks give a clear link from claim to passage. |
| You can train or fine-tune a model on reflection signals | Yes | The original method then works as designed. |
| You only have a general model and a tight latency budget | Use a light version | Approximate with one retrieval decision and one end-of-answer check. |
| Every question needs a lookup anyway | Probably not | The retrieval decision adds cost without saving any search. |
| Questions need long multi-source research | Consider agentic | Self-RAG polishes one pass; it does not plan a research path. |
Trade-offs
| Dimension | Effect | What to do about it |
|---|---|---|
| Quality | Better grounding and fewer unsupported claims when the judge is reliable. | Validate judgements against human labels before relying on them. |
| Latency | Several candidates and judgements per segment slow the answer. | Parallelise, bound passages, and use small judges. |
| Cost | Many more model calls than plain RAG; a trained model adds training cost. | Skip retrieval when not needed and cap segments. |
| Complexity | Training or prompt design, ranking weights, and a segment loop to maintain. | Begin with the prompt version and measure before training. |
| Failure modes | An overconfident judge approves bad claims; a cautious judge rejects good ones. | Calibrate thresholds and log all judgements for review. |
Compared with related types
Corrective RAG checks the retrieved documents once with an outside evaluator and then acts: refine, replace, or combine. Self-RAG checks continuously and also checks the output. Corrective RAG is easier to adopt with any model; Self-RAG gets more from a model trained for it.
Adaptive RAG also decides how much retrieval a question deserves, but it does so before any retrieval begins, using a classifier on the question. Self-RAG decides during writing. Advanced RAG improves the quality of what is retrieved without asking the model to critique itself.
What this means for your role
Common mistakes
Further reading
- Self-RAG: Learning to Retrieve, Generate, and Critique through Self-Reflection by Asai et al., 2023, the paper that introduced reflection tokens.
- Evaluation and observability for building the labelled sets that judges need.
- Fine-tuning and training if you consider training a reflection model.
Self-RAG turns checking into part of writing. Start with the cheap prompt version, measure the judge, and train only when the numbers say it is worth it.