Search

Search papers and lessons

Self-RAG: Learning to Retrieve, Generate, and Critique through Self-Reflection

Akari Asai, Zeqiu Wu, Yizhong Wang et al. · 2023

Self-RAG trains a language model to decide when to retrieve, to judge its retrieved passages and its own answer, by writing special reflection tokens, so it can cite evidence and tune its behaviour at inference time.

On this page

  • Colour = topic mix
  • Neural network basics
  • Calculus
  • Discrete math
  • Linear algebra
  • Probability
  • Language & LLMs
  • ReadReady to readNot yet

TL;DR

A language model can invent facts, and standard retrieval-augmented generation (RAG) fetches a fixed number of documents whether or not they help. Self-RAG trains a model to make these decisions itself. It writes special reflection tokens that say whether retrieval is needed, whether a passage is relevant, whether the answer is supported by it, and how useful the answer is. The tokens are learned from a critic whose labels come from GPT-4, so no reinforcement learning loop is needed. On the paper's tasks, the 7B and 13B models outperformed standard RAG systems and several larger models on factuality and citation quality.

Builds on: Retrieval-Augmented Generation, Autoregressive Model, Reward Model, Instruction Tuning · Leads to: models that interleave retrieval and self-critique during generation, rather than retrieving once before answering

Why it mattered

Chatbots built on large models are used for research, health-adjacent questions, law and news, where a wrong answer with a confident tone does harm. Retrieval was the standard fix: put relevant documents in the prompt and ask the model to answer from them. But the standard recipe retrieves a fixed number of passages for every query, including questions the model could answer alone, and it trusts every passage, including irrelevant ones. It also gives no way to check whether the answer follows from the sources.

Self-RAG made retrieval an on-demand step and made the model's own judgement visible in the output. Users can see which claims are supported, and developers can trade retrieval cost against accuracy at inference time.

The problem

Start with RAG as it was used. Given a question xx, a retriever R\mathcal{R} finds the top KK passages D\mathbf{D} from a large collection. The language model then reads xx and D\mathbf{D} and writes an answer yy. Three things go wrong.

First, retrieval always happens. For a question like "what is the capital of France", the passages add cost and can distract the model. Second, the top passages are not always relevant, and the model cannot tell a good passage from a bad one. Third, the answer may contain claims that no passage supports, yet nothing in the output marks them.

Two existing fixes each solve one part. Reinforcement learning from human feedback, with a reward model and PPO training, can teach a model to prefer good answers, but it is expensive and the critic is hidden. Fine-tuning on retrieved data teaches the model to use passages, but not to judge them. The question for Self-RAG was whether a single language model could retrieve, generate and critique within one left-to-right pass.

How it works

Think of Self-RAG as a generator that writes a sentence, then decides what to do next. Each sentence is called a segment. The generator writes ordinary text and special tokens from one expanded vocabulary, so there is no separate controller.

flowchart TB
  Q["Question x and previous segments"] --> R{"Retrieve? token"}
  R -- "No" --> G1["Write next segment"]
  R -- "Yes" --> RET["Fetch top K passages d"]
  RET --> P["For each passage: write segment, then critique it"]
  P --> J["Score each candidate: relevance, support, usefulness"]
  J --> B["Keep best candidates by segment-level beam search"]
  G1 --> NEXT["Next segment, until end"]
  B --> NEXT
  1. Read the question and what has been written so far. The model has the input xx and any earlier segments y<ty_{<t}.

  2. Decide whether to retrieve. The model predicts a retrieval token with one of three values: Yes, No, or Continue (keep using evidence already retrieved). A No means the next segment needs no outside facts, and the model writes it directly.

  3. Retrieve when asked. On Yes, a retriever fetches the top KK passages, with KK a small fixed number.

  4. Generate once per passage. For each passage dd, the model writes a candidate continuation, conditioned on xx, dd and y<ty_{<t}. This is parallel, one candidate per passage.

  5. Critique each candidate. The model writes an IsRel token (relevant or irrelevant to xx), an IsSup token (fully, partially or not supported by dd), and an IsUse token on a scale of 1 to 5.

  6. Score and select. Each candidate gets a segment score that combines its generation probability with the probabilities of the desirable critique tokens, each weighted by a setting chosen at inference. A segment-level beam search keeps the best few candidates.

  7. Repeat until the end. The chosen segment is appended and the loop returns to step 2. The final output is a sequence of segments, each with its evidence and its critique.

Worked examples

Example
1. Tiny: a retrieval decision

Setting: the model is asked whether to retrieve before writing the next segment. We use a simple rule for this example: retrieve when the normalised probability of the Yes token is above a threshold of 0.2.

  1. Compare the probability of Yes with the threshold.
  2. With probability 0.35: 0.35>0.200.35 > 0.20, so retrieval is triggered.
  3. With probability 0.10: 0.10<0.200.10 < 0.20, so the model writes the next segment without retrieval.
  4. Interpretation: a lower threshold retrieves more often, and a higher threshold retrieves less.

Answer: with 0.35 the model retrieves; with 0.10 it does not.

Example
2. Standard: scoring one candidate

Setting: for one passage, the critic gives IsSup probabilities of 0.6 for fully supported, 0.3 for partially supported and 0.1 for no support. The support weight in the segment score is 0.5.

  1. The support score for the desirable value is its probability divided by the sum over all support values: ssup=0.6/(0.6+0.3+0.1)=0.6s^{\text{sup}} = 0.6 / (0.6 + 0.3 + 0.1) = 0.6.
  2. The weighted contribution is 0.5×0.6=0.300.5 \times 0.6 = 0.30.
  3. A second candidate with IsSup probabilities 0.2, 0.3, 0.5 has ssup=0.2s^{\text{sup}} = 0.2 and a weighted contribution of 0.5×0.2=0.100.5 \times 0.2 = 0.10.
  4. The first candidate has the higher support contribution, so it is favoured when the segment-level search compares the two.
  5. Interpretation: the score rewards candidates whose evidence is clearly strong, and the weight sets how much that matters against the generation probability.

Answer: the first candidate scores 0.30 on support and the second 0.10, so the first is kept.

Example
3. Realistic: how the inference weights change behaviour

Setting: a long-form answer task where every claim must carry a citation. The support weight is raised from 0.5 to 1.0 for this run, and the retrieval threshold is set to 0 so the model retrieves for every segment.

  1. Raising the support weight pushes the search toward candidates whose evidence supports them, which tends to raise citation precision.
  2. The same change can lower fluency, because the search prefers segments that carry citations even when a plainer sentence would read better.
  3. Lowering the threshold to 0 forces retrieval for every segment, so every segment has evidence to cite.
  4. Interpretation: the user chooses a point on the trade-off between precision and fluency, and between retrieval cost and factual coverage, without retraining the model.

Try it: with the support weight at 1.0 and a candidate whose support score is 0.8, what is the weighted support contribution? Answer: 1.0×0.8=0.801.0 \times 0.8 = 0.80.

The math

Self-RAG uses two trained models. The critic C\mathcal{C} predicts reflection tokens rr given the input and output. The generator M\mathcal{M} predicts the output and the reflection tokens, given the input and retrieved passages.

Definition: Reflection tokens

Special tokens added to the vocabulary of the generator. Four types are used: a retrieval token (Yes, No, Continue), a relevance token (relevant, irrelevant), a support token (fully supported, partially supported, no support), and a usefulness token (1 to 5). A segment is written as text interleaved with these tokens.

Training the critic (offline, before generation)

The critic is initialised from a pretrained language model, here Llama 2 7B, and trained on data labelled by GPT-4. Given input xx, output yy and a reflection token rr, the objective is maximum likelihood on the labels:

max⁡C  E((x,y),r)∼Dcriticlog⁡pC(r∣x,y).\max_{\mathcal{C}} \; \mathbb{E}_{((x,y),r) \sim \mathcal{D}_{\text{critic}}} \log p_{\mathcal{C}}(r \mid x, y).

Here E\mathbb{E} is an average over the training pairs, and log⁡pC(r∣x,y)\log p_{\mathcal{C}}(r \mid x, y) is the log of the probability the critic gives the correct token. Maximising it pushes the critic to predict the GPT-4 label.

Training the generator

The generator learns from a corpus that already contains passages and reflection tokens, produced offline by the retriever and the critic. It is trained with the ordinary next-token objective over the expanded vocabulary:

max⁡M  E(x,y,r)∼Dgenlog⁡pM(y,r∣x).\max_{\mathcal{M}} \; \mathbb{E}_{(x, y, r) \sim \mathcal{D}_{\text{gen}}} \log p_{\mathcal{M}}(y, r \mid x).

The retrieved passage text is masked out of the loss, so the model is not trained to reproduce passages; it is trained to write the answer and the tokens around them. Because the critic runs offline, no reward model is needed during generator training, which is the cost saving over PPO.

Scoring a segment (step 6 of the walkthrough)

For a critique type GG with NGN^G possible values, the score of the most desirable value r^\hat{r} at segment tt is

stG=pt(r^)∑i=1NGpt(ri).s_t^G = \frac{p_t(\hat{r})}{\sum_{i=1}^{N^G} p_t(r_i)}.

The segment score combines the generation probability of the segment with these critique scores, each multiplied by its weight wGw^G. The weights are settings that can be changed at inference time, which is how the model is steered without retraining.

Results

Setup. The generator is Llama 2 at 7B and 13B parameters. Training uses instruction-output data plus knowledge-intensive sources, and the critic is Llama 2 7B. Evaluation is zero-shot.

Tasks. The evaluation covers closed-set fact checking and reasoning, short-form question answering, and long-form generation. Long-form answers are scored on factuality, fluency and citation quality.

Against models without retrieval and against retrieval baselines. The paper reports that the 7B and 13B models outperform standard RAG systems and some larger models on factuality and citation metrics. It also reports that a proprietary retrieval-augmented model is still stronger on some tasks, so the claim is about open models at a smaller size, not a universal win. Read the exact numbers in the paper's tables rather than from this summary.

Ablations. The paper compares training without retrieval, training without critic tokens, and inference choices such as always using the top passages. Removing components lowers results, and using the top passages regardless of relevance hurts. This supports the claim that the critique tokens, not only the retrieval, carry much of the gain.

Limits. The model can still produce text that its citations do not fully support. The critic's labels come from GPT-4, so the critic inherits that model's errors. The evaluation covers a fixed set of tasks with a fixed retriever, so the results may not carry over to other retrievers or to open-ended chat.

Misreadings to avoid

It is tempting to think that Self-RAG is a bigger RAG system. In fact the model decides whether to retrieve at each segment, so a question it can answer alone triggers no retrieval.

It is tempting to think that the reflection tokens are a separate verifier that checks the answer afterwards. In fact the critic runs offline to label the training data, and the generator learns to write the tokens itself. At inference there is one model.

It is tempting to think that a reflection token makes the answer true. In fact the token reports what the model judges about the evidence. The model can still be wrong, as any generator can.

Use Self-RAG-style training when you need citations and control over retrieval cost, and when you can afford to label a training set with a stronger model. Do not use it as a way to avoid retrieval quality problems, because a poor retriever still gives poor evidence. A simpler alternative is standard RAG with a good reranker, which is cheaper to build and easier to debug.

Reading guide

Read the paper in this order, with the lessons it needs at each part:

Chain of ideas in this lesson: standard RAG retrieves blindly and cannot show its judgement; Self-RAG adds reflection tokens to the vocabulary; a critic labels a corpus offline; the generator learns to write the tokens; at inference, the model retrieves when it judges it needs to and scores its candidates with weights the user sets.

Check yourself

QuestionA segment's IsSup token has probabilities 0.5 for fully supported, 0.25 for partially and 0.25 for no support. What is the support score ssups^{\text{sup}} for the fully supported value?Show answer

The score is the probability of the desirable value divided by the sum over all values: 0.5/(0.5+0.25+0.25)=0.5/1.0=0.50.5 / (0.5 + 0.25 + 0.25) = 0.5 / 1.0 = 0.5.

QuestionThe retrieval threshold is 0.2. The normalised probability of the Yes token at some segment is 0.18. Does the model retrieve, and what changes if the threshold is raised to 0.3?Show answer

Since 0.18<0.200.18 < 0.20, the model does not retrieve at threshold 0.2. At threshold 0.3 it still does not retrieve, because 0.18<0.300.18 < 0.30. Raising the threshold makes retrieval rarer; lowering it makes retrieval more frequent.

QuestionWhy is the retrieved passage text masked out of the generator's training loss?Show answer

The passages are inputs the model should use, not text it should learn to produce. If the loss included them, the model would be trained to reproduce retrieved text, which would teach copying rather than answering and critiquing. Masking keeps the loss on the answer and the reflection tokens.

QuestionApplied scenario: a team wants a chatbot for policy questions that cites its sources. A reviewer notes that the model's citations sometimes do not support the claims. Using the paper's framework, what should the team check first?Show answer

The support token is the component designed to catch this. The team should check how well the critic's support labels agree with their own judgement on a sample, and whether the support weight at inference is high enough to favour supported candidates. They should also check the retriever, because a poor passage cannot support a correct claim. Self-RAG outputs can still be only partly supported, so a human review step is still needed.

Sources

  • Asai, Wu, Wang, Sil, Hajishirzi (2023), Self-RAG: Learning to Retrieve, Generate, and Critique through Self-Reflection, arXiv:2310.11511. https://arxiv.org/abs/2310.11511

Read the full paper

Akari Asai, Zeqiu Wu, Yizhong Wang et al., 2023. arXiv:2310.11511

Self-RAG paper explained · ungoon.me