Back to paper library

Self-RAG

Three Daily Reflections

Original paper

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

Paper authors

Akari Asai · Zeqiu Wu · Yizhong Wang · Avirup Sil · Hannaneh Hajishirzi

Publication
ICLR 2024Conference
First submitted to arXiv
arXiv:2310.11511
Cite this paper · BibTeX

The citation identifies the linked source version. It cites the original paper and its authors.

@misc{retrievalaugmentedgenerationselfrag2023,
  title = {{Self-RAG: Learning to Retrieve, Generate, and Critique through Self-Reflection}},
  author = {Akari Asai and Zeqiu Wu and Yizhong Wang and Avirup Sil and Hannaneh Hajishirzi},
  year = {2023},
  eprint = {2310.11511},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2310.11511}
}
On this page

By 2023, standard RAG had settled on a fixed recipe that retrieves the top KK documents whatever the user asks, prepends them to the question, and lets the language model answer.

This approach has three often-overlooked problems.

First, some questions need no lookup at all. Ask the model to write “My Most Memorable Summer,” and fetching five documents from a database will only get in the way.

Second, retrieved documents may be irrelevant. Ask “How did US states get their names?” and the retriever might return “The Most Popular Baby Names in Texas,” because both mention names and states.

Third, the model may ignore even relevant documents. Without explicit training to follow the documents, the model may cite them while writing things they never say—or even contradict.

This paper comes from the University of Washington, the Allen Institute for AI (AI2), and IBM Research. The authors want the model to decide for itself whether to retrieve, to evaluate what comes back, and to check what it has written.

Defining the Problem

Start with the paper's first figure. Traditional RAG is on the left; the proposed Self-RAG is on the right:

Traditional RAG versus Self-RAG: fixed top-K retrieval and generation on the left; on-demand retrieval, parallel generation, and reflection-token evaluation to choose the best segment on the right
Figure 1 from the paper, excerpted from page 2 of the v1 PDF, CC BY 4.0. Traditional RAG is on the left and Self-RAG on the right. The bottom row is a writing task that needs no retrieval.

Look at the left side first. The question is “How did US states get their names?” The retriever returns three documents. The first says 11 of the 50 states are named after people; the second discusses popular baby names in Texas; the third says California was named after a fictional island in a Spanish novel.

Given all three, the model writes that “California was named after Columbus,” marked with a red underline and Contradictory because it directly conflicts with the third document. Another sentence says Texas and Utah were named after Native American tribes, marked No information in passages, since none of the three documents mentions that.

The bottom row makes the problem even plainer: traditional RAG retrieves three documents even for the summer essay.

The question the authors want to solve is:

  • Can a single language model judge when to retrieve, whether the retrieved information is useful, and whether its own writing is supported?

Solving the Problem

Reflection Tokens

The authors add a set of special tokens to the model's vocabulary, called reflection tokens. As the model generates text, it also generates these tokens at appropriate points, rather like grading itself while writing.

There are four types:

TokenWhat it examinesPossible valuesMeaning
RetrieveQuestion and text written so faryes / no / continueWhether to retrieve now
IsRelQuestion, documentrelevant / irrelevantWhether the document helps answer the question
IsSupQuestion, document, output segmentfully / partially / no supportWhether the document supports this output
IsUseQuestion, output5 / 4 / 3 / 2 / 1How useful the answer is overall

Compiled from Table 1 of the paper.

The last three are collectively called critique tokens and perform the evaluation. Retrieve decides whether to look something up.

Walking Through Inference

Return to the right side of the figure and follow the same question.

Self-RAG generates text in segments. In the paper's experiments, each segment is a sentence.

Step 1: Should I retrieve? The model first writes, “US states' names have various origins.” It then generates a Retrieve token, deciding that the next part needs factual support, and calls the retriever to obtain three documents.

Step 2: Generate in parallel. Each document is separately appended to the question. The model generates three candidate next sentences in parallel and gives each document and candidate critique tokens:

  • Document 1: Relevant; “11 of the 50 states are named after people”; Supported.
  • Document 2: Irrelevant; “Texas was named after a Native American tribe”; unsupported.
  • Document 3: Relevant; “California's name comes from the 16th-century novel Las Sergas de Esplandián”; Partially.

Step 3: Score and choose the best. The candidate from Document 1 is relevant and fully supported, so it ranks first. Document 3 comes second and Document 2 last. The model adopts the first candidate and continues, retrieving again when needed.

For the writing task at the bottom, the model generates No Retrieval at the outset and writes directly, like an ordinary language model.

How Is the Score Calculated?

The authors express the ranking in Step 3 as a score. For each candidate segment yty_t paired with document dd:

f(yt,d)=p(yt∣x,d,y<t)+S(Critique)f(y_t,d)=p(y_t\mid x,d,y_{<t})+\mathcal{S}(\text{Critique})

The first term is the probability of generating the sentence. The second is a weighted sum of critique-token scores:

S(Critique)=∑G∈{IsRel, IsSup, IsUse}wG stG\mathcal{S}(\text{Critique})=\sum_{G\in\{\text{IsRel},\,\text{IsSup},\,\text{IsUse}\}} w^G\, s^G_t

Here stGs^G_t is the probability of the most desirable value in that token group: Relevant for IsRel, fully supported for IsSup, or 5 for IsUse, normalized within the group.

Let's work through some hypothetical numbers. The paper's default weights are wIsRel=1.0w^{\text{IsRel}}=1.0, wIsSup=1.0w^{\text{IsSup}}=1.0, and wIsUse=0.5w^{\text{IsUse}}=0.5. Suppose two candidates have these critique-token probabilities:

CandidateIsRel = RelevantIsSup = fullyIsUse = 5
Using Document 10.900.800.60
Using Document 30.850.300.70

Their critique scores are:

S1=1.0×0.90+1.0×0.80+0.5×0.60=2.00S3=1.0×0.85+1.0×0.30+0.5×0.70=1.50\begin{aligned} \mathcal{S}_1 &= 1.0\times0.90+1.0\times0.80+0.5\times0.60=2.00\\ \mathcal{S}_3 &= 1.0\times0.85+1.0\times0.30+0.5\times0.70=1.50 \end{aligned}

If the sentences' generation probabilities are similar, Document 1's candidate wins.

The weights can be adjusted at inference time without retraining. If your application strongly requires every sentence to have a source, raise wIsSupw^{\text{IsSup}} to 2.0. The gap grows from 0.5 to 1.0: 2.80 versus 1.80.

You can also impose a hard rule that discards any candidate generating IsSup = No support.

For retrieval, besides letting the model directly generate Retrieve=Yes, you can set a threshold so that retrieval happens only when the normalized probability of Retrieve=Yes exceeds δ\delta. A lower threshold means more frequent retrieval.

In the actual search, the authors use beam search of width 2 at the segment level, with greedy decoding for tokens inside each segment.

How Does the Model Learn to Grade Itself?

At inference time, the model seems to know how to judge and score things on its own. How are those abilities trained?

The authors use two steps.

Step 1: Train a critic model C\mathcal{C}. Manually annotating reflection tokens for every sentence would be expensive, so the authors ask GPT-4 to do it. They write an instruction for each token type—for example, “Given an instruction, decide whether finding external documents on the web would help produce a better response”—and add a few demonstrations. They collect 4,000 to 20,000 examples per token type and fine-tune a Llama 2-7B model. The resulting critic agrees with GPT-4 on over 90% of cases in most token categories.

Step 2: Use the critic to rewrite training data, then train the generator M\mathcal{M}. Run 150,000 instruction–response pairs through the critic sentence by sentence. Insert Retrieve and retrieved documents wherever retrieval is needed, IsRel after each document, IsSup after each sentence, and IsUse at the end of the whole answer.

The processed data looks like this, simplified from Figure 2:

text
Input: How did US states get their names?

Output: [Retrieve]<p>Of the fifty states, eleven are named after an individual person</p>
        [Relevant] 11 of 50 states' names come from person. [Supported]
        [Retrieve]<p>LOUISIANA: Named in honor of Louis XIV of France.</p>
        [Relevant] For instance, Louisiana was named after King Louis XIV, and
        Georgia was named after King George II. [Partially] [Utility:5]

Then comes ordinary language-model training on next-token prediction, except that retrieved documents between <p> and </p> are excluded from the loss, because they come from the retriever and are not something the model should learn to write.

After training, the generator produces these tokens itself. The critic is no longer called at inference time.

The authors also compare this with RLHF. PPO training repeatedly calls a reward model. Self-RAG instead writes critiques into the training data beforehand and uses the standard language-model objective, at much lower cost.

Discussion

Experimental Setup

Every evaluation is zero-shot, with task instructions but no demonstrations.

  • Closed-set tasks: PubHealth for public-health fact verification and ARC-Challenge for science questions, scored by accuracy.
  • Short answers: A long-tail PopQA subset of 1,399 questions about obscure entities whose Wikipedia pages receive fewer than 100 monthly views, plus 11,313 questions from TriviaQA-unfiltered. An answer is correct if a reference answer appears in the output.
  • Long-form generation: FactScore evaluates factuality in biographies. ASQA long-answer QA additionally evaluates citation precision and recall.

The generators are Llama 2-7B and 13B. The retriever is an off-the-shelf Contriever-MS MARCO, returning the top five documents by default. Biographies and open-domain QA additionally use the top five web search results.

Main Results

Table 2 compares many models. Here are some particularly informative rows:

ModelPopQAPubHealthBiography FactScoreASQA citation precision
ChatGPT29.370.171.8—
ChatGPT + retrieval50.854.7—65.1
Llama2-chat 13B + retrieval51.852.179.919.8
Llama2-FT 7B + retrieval48.764.378.25.0
Self-RAG 7B54.972.481.266.9
Self-RAG 13B55.874.580.270.3

Compiled from Table 2 of the paper.

Several things stand out.

Retrieval can hurt. Adding retrieval to ChatGPT raises PopQA from 29.3 to 50.8: obscure facts really do need looking up. But PubHealth falls from 70.1 to 54.7. That is the first problem from the opening: forcing retrieval where it is unnecessary can be harmful.

Citation precision shows the largest gap. Ordinary RAG baselines mostly sit between single digits and about 20%; Self-RAG 13B reaches 70.3, above even ChatGPT with retrieval at 65.1. Citation precision asks whether a sentence citing a document is fully supported by that document.

The training data alone cannot explain the gain. Llama2-FT 7B uses the exact same 150,000 instruction examples as Self-RAG, but without reflection tokens or retrieved documents; retrieval is added at test time. It trails Self-RAG 7B on every metric except ASQA str-em and ROUGE, where it is slightly higher: 31.0 versus 30.0 and 35.8 versus 35.7.

Self-RAG does not win everywhere. ChatGPT scores 74.3 on TriviaQA and 75.3 on ARC-Challenge, ahead of Self-RAG 13B's 69.3 and 73.1. ChatGPT with retrieval also has higher ASQA correctness (str-em) and citation recall.

Which Design Choices Help?

Self-RAG analysis: (a) training and inference ablations, (b) effects of IsSup weights on citation precision and MAUVE, and (c) effects of the retrieval threshold on accuracy and retrieval frequency
Figure 3 from the paper, excerpted from page 9 of the v1 PDF, CC BY 4.0. (a) Ablations; (b) inference-time weight adjustment; (c) retrieval-threshold adjustment.

(a) Ablations. To save resources, these experiments use a 7B model trained on 50,000 examples, tested on PopQA (PQA), PubHealth (Med), and ASQA (AS).

  • Removing the critic during training (No Critic: attach one retrieved document to every example without reflection tokens) drops ASQA from 32.1 to 18.1.
  • Always using only the top-ranked document at inference (Retrieve top1, the closest to traditional RAG) drops PopQA from 45.5 to 41.8 and ASQA to 28.6.
  • Disabling retrieval entirely (No retrieval) leaves PopQA at 24.7, while PubHealth barely changes at 73.0.

The last result echoes the main findings, which showed that PopQA needs lookup and PubHealth mostly does not.

(b) Adjusting IsSup weights. The horizontal axis is wIsSupw^{\text{IsSup}}. Increasing it raises citation precision but lowers MAUVE, a fluency metric. The authors explain that longer, more fluent sentences are more likely to include content not fully supported by their citations. This is the promised ability to adjust model behavior without retraining.

(c) Adjusting the retrieval threshold. A higher threshold lowers retrieval frequency. Retrieving less barely affects PubHealth accuracy, but substantially hurts PopQA.

Other Observations

  • More training data helps. Increasing from 5,000 to 150,000 examples produces particularly clear gains on PopQA and ASQA. The authors think further scaling could help.
  • A small human evaluation. The authors manually inspect 50 examples each from PopQA and the biography outputs. Predicted IsRel agrees with human judgments in 95.0% and 90.0% of cases, respectively; IsSup agreement is 90.0% and 85.0%.
  • Inference cost. Each retrieval processes multiple documents in parallel, generates multiple candidates, and runs segment-level beam search. The authors use vLLM for acceleration, but report no latency or cost comparison with traditional RAG. Actual deployment requires its own measurements.

Conclusion

Self-RAG hands several hard-coded RAG decisions back to the model:

  1. Whether to retrieve: Retrieve enables on-demand retrieval; writing tasks can skip it.
  2. Which document helps: IsRel evaluates each retrieved document.
  3. Whether the writing is grounded: IsSup checks whether each sentence is supported.
  4. Whether the answer is useful overall: IsUse evaluates overall answer quality.

GPT-4 annotates these tokens; the annotations are distilled into a critic, written into training data, and eventually learned by the generator itself. At inference, token probabilities form scores, and weights adjust the model's trade-offs without retraining.

In the paper's experiments, Self-RAG 7B and 13B outperform the ChatGPT and Llama2-chat comparisons with reported scores on PopQA, PubHealth, biographies, and ASQA citation precision. ChatGPT remains ahead on tasks such as TriviaQA and ARC-Challenge.

Always retrieving the top KK documents used to be RAG's default. The next time you design a RAG pipeline, first ask whether to look something up and whether what comes back is usable; each of these calls for a judgment of its own.