Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks
TL;DR. RAG combines a dense retriever (DPR) with a seq2seq generator (BART-large) in one model and fine-tunes them jointly. The retrieved passage is a latent variable: the model sums over the top- passages, weighting each by the retriever’s probability. The retriever therefore learns from answer likelihood alone, with no relevance labels. RAG set the state of the art on three open-domain QA datasets. It also produced more factual text than BART alone, and its knowledge could be updated by swapping the index.
Why it matters now. The name now covers almost any pipeline that pastes retrieved text into a prompt. The original is a trained architecture, so this page is about what that architecture does and which findings carry over. The ideas you already know from IR (dense bi-encoders, MIPS, BM25 baselines) appear here only briefly. The new parts are the latent-variable objective and the two ways to marginalise.
Key idea
Section titled “Key idea”Retriever. . Both and are BERT-base encoders initialised from DPR. The index holds 21M 100-word chunks of the December 2018 Wikipedia dump, searched with FAISS HNSW.
Generator. is BART-large (400M parameters). It reads concatenated with one passage .
Two ways to combine them, using the top- passages:
RAG-Sequence picks one passage for the whole answer. RAG-Token can switch passages at each token, which helps when an answer joins facts from different documents.
Training. Minimise with Adam. Only and BART are updated. The document encoder and index stay frozen, which avoids REALM’s periodic re-indexing; .
Why the retriever learns. Write . Then
the posterior minus the prior. This is exact for RAG-Sequence when is a softmax over the top- scores. Passages that explain the answer better than the retriever expected get pulled closer to the query.
Decoding. RAG-Token decodes with ordinary beam search. RAG-Sequence needs a beam per document, followed by either:
- “Thorough Decoding”: rescore every candidate under every document; or
- “Fast Decoding”: assume probability 0 for candidates not generated from a given document.
A worked example (toy numbers, not from the paper). Take with and , and a one-token answer . If and :
- Both variants give . For one-token targets, such as FEVER labels, the two variants are identical.
- The posterior on is , above its prior of 0.3.
- The gradient on is therefore about . Training moves the query embedding toward .
The paper’s own illustration is Figure 2. For the Jeopardy input “Hemingway”, RAG-Token’s posterior is high on document 1 while generating “A Farewell to Arms” and on document 2 for “The Sun Also Rises”. It flattens after the first token of each title, because BART can finish the title from its own weights.
What changed vs. prior work, and what didn’t.
| Extractive open QA (DPR, REALM) | Closed-book (T5) | RAG | |
|---|---|---|---|
| Output | span from a passage | generated text | generated text |
| Uses an index | yes | no | yes |
| Retriever trained by | relevance labels (DPR) or masked-LM pre-training (REALM) | — | answer likelihood, query side only |
| Can answer if no passage contains the answer | no | yes | yes (11.8% on NQ) |
| Knowledge update | re-index | retrain | swap the index |
Key results
Section titled “Key results”Open-domain QA (Table 1, test exact match). TQA is shown as the standard / Wiki test split.
| Model | NQ | TQA | WQ | CT |
|---|---|---|---|---|
| T5-11B (closed book) | 34.5 | – / 50.1 | 37.4 | – |
| T5-11B + SSM (closed book) | 36.6 | – / 60.5 | 44.7 | – |
| REALM | 40.4 | – | 40.7 | 46.8 |
| DPR (extractive) | 41.5 | 57.9 / – | 41.1 | 50.6 |
| RAG-Token | 44.1 | 55.2 / 66.1 | 45.5 | 50.0 |
| RAG-Sequence | 44.5 | 56.8 / 68.0 | 45.2 | 52.2 |
Generation and classification (Table 2, test).
- Jeopardy question generation (BLEU-1 / Q-BLEU-1): BART 15.1 / 19.7; RAG-Token 17.3 / 22.2; RAG-Sequence 14.7 / 21.4.
- MS MARCO NLG (ROUGE-L / BLEU-1): BART 38.2 / 41.6; RAG-Sequence 40.8 / 44.2. The supervised state of the art, which uses gold passages, reaches 49.8 / 49.9.
- FEVER (3-way / 2-way accuracy): RAG 72.5 / 89.5 vs BART 64.0 / 81.1. The state of the art is 76.8 / 92.2, and it uses retrieval supervision that RAG does not.
- Retrieval quality on FEVER: the top retrieved passage comes from a gold article 71% of the time, and a gold article is in the top 10 in 90% of cases.
Human evaluation (Table 4, Jeopardy). Annotators judged RAG more factual than BART in 42.7% of pairs and BART more factual in 7.1%.
Retriever ablation (Table 6, dev). NQ exact match for RAG-Sequence:
- BM25: 31.8.
- Frozen DPR: 41.2.
- Fine-tuned query encoder: 44.0.
On FEVER-3, BM25 wins: 75.1 vs 74.5 (RAG-Token columns).
Number of passages (Figure 3). Retrieving more passages at test time improves NQ monotonically for RAG-Sequence. RAG-Token peaks at 10. The reported RAG-Sequence open-QA test results use 50 passages.
Limitations & open questions
Section titled “Limitations & open questions”- One retrieval, from the input. The query is fixed to . Multi-hop questions whose second entity appears only in a retrieved passage are out of reach. IRCoT and agents address this by re-querying.
- Frozen document side. The retriever adapts only through . Whether co-training with periodic re-indexing would help at this scale is left open; REALM suggests it can.
- Small generator, fixed snapshot. BART-large has little parametric knowledge compared with today’s LLMs. The balance between parametric and retrieved knowledge shifts with model size, so the 11.8% “answer not in any passage” figure will not transfer.
- Cost of marginalising. RAG-Sequence runs the generator once per passage, and Thorough Decoding adds extra forward passes. With 50 passages at test time, this is expensive.
- Open question: joint retriever–generator training was dropped by most 2023+ systems in favour of frozen LLMs. Which of RAG’s gains came from training, and which from retrieval alone? There is no clean comparison at LLM scale.
Connections
Section titled “Connections”- Retrieval background: DPR is a single-vector bi-encoder; compare late interaction in ColBERTv2. Multi-hop retrieval before LLMs: Baleen.
- After, retrieving more than once: IRCoT (re-query with each reasoning sentence), DSP (programmatic multi-hop pipelines).
- After, deciding whether to retrieve: Self-RAG (reflection tokens for retrieval and support).
- After, the model writes the queries: ReAct, Toolformer, WebGPT, Search-o1, and RL-trained searchers such as Search-R1.
- Reading problems in prompt-only RAG: Lost in the middle.
- Evaluating attribution: citation and attribution evaluation, TREC RAG.
Questions to think through
These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.
- Derive / compute
Take k = 2 retrieved documents with retriever probabilities p(z1|x) = 0.6 and p(z2|x) = 0.4, and a two-token answer. Under z1 the generator gives the tokens probabilities 0.9 then 0.1; under z2 it gives 0.2 then 0.8. Compute p(y|x) under RAG-Sequence and under RAG-Token, then compute the RAG-Sequence posterior over documents and the gradient of log p(y|x) with respect to each document's retrieval score.
What a strong answer covers
- RAG-Sequence: 0.6 × (0.9 × 0.1) + 0.4 × (0.2 × 0.8) = 0.054 + 0.064 = 0.118.
- RAG-Token: (0.6 × 0.9 + 0.4 × 0.2) × (0.6 × 0.1 + 0.4 × 0.8) = 0.62 × 0.38 = 0.2356. RAG-Token is higher because it can take token 1 from z1 and token 2 from z2.
- RAG-Sequence posterior: p(z1|x,y) = 0.054 / 0.118 ≈ 0.46 and p(z2|x,y) = 0.064 / 0.118 ≈ 0.54.
- With p(z|x) a softmax over scores s_z = d(z)·q(x), the gradient of log p(y|x) with respect to s_z is posterior minus prior: about −0.14 for z1 and +0.14 for z2.
- So the query encoder is pushed toward the document that best explains the answer, with no relevance labels. This is the whole retriever training signal.
- Mechanism
RAG trains the query encoder and BART but keeps the document encoder and the 21M-passage index frozen, and it never sees a relevance label. Explain what signal reaches the retriever, why freezing the document side is a sound trade-off, and what the index hot-swap experiment (70% and 68% matched vs 12% and 4% mismatched) shows about where the knowledge lives.
What a strong answer covers
- The only signal is the marginal likelihood of the target. Documents that raise p(y|x,z) gain posterior mass, and the query encoder moves toward them (posterior minus prior).
- Updating the document encoder would require re-encoding and re-indexing 21M passages during training, as REALM does. Freezing it keeps the index fixed; the paper found this unnecessary for strong results.
- The retriever starts from DPR, which was already trained on NQ and TriviaQA, so the frozen document side is already in a good space.
- Hot-swap: with a 2016 index RAG answers 70% of 2016 world-leader questions; with a 2018 index, 68% of 2018 ones. Mismatched pairs give 12% and 4%.
- So the time-sensitive facts are read from the index, not from BART's weights. You can update knowledge by replacing the index, without retraining.
- What if…
Table 6 swaps RAG's retriever. On NQ exact match, RAG-Sequence goes from 31.8 with BM25 to 41.2 with a frozen DPR retriever to 44.0 when the query encoder is fine-tuned. On FEVER-3, BM25 is the best variant (75.1 vs 74.5 for the trained retriever). Explain each gap and what it says about when learned dense retrieval matters.
What a strong answer covers
- BM25 → frozen DPR (+9.4 on NQ): dense retrieval trained on QA pairs matches paraphrased questions to answer passages better than term overlap.
- Frozen → fine-tuned (+2.8 on NQ): end-to-end training adapts the query encoder to what helps the generator, not just to DPR's original relevance labels.
- FEVER claims are entity-centric, so exact term matching on entity names works well; the authors give this explanation for BM25 winning there.
- Lesson for IR: the value of a learned retriever depends on query style. Lexical baselines stay competitive when queries contain the key entities.
- The absolute gains are on dev sets and from single runs, so small differences such as 75.1 vs 74.5 are within noise.
- Critique
In 2025 "RAG" usually means retrieving top-k passages with an off-the-shelf retriever and pasting them into a frozen LLM's prompt. List the properties of Lewis et al.'s RAG that this recipe drops, and argue which of the paper's findings you can and cannot carry over to the prompt-only version.
What a strong answer covers
- Dropped: joint training, the latent-variable marginalisation over documents, the retriever learning from answer likelihood, and per-token document switching (RAG-Token).
- Also different: the generator here is a 400M BART, not a large instruction-tuned LM with strong parametric knowledge; and the corpus is a fixed Wikipedia snapshot.
- Carries over: retrieval improves factuality on knowledge-intensive tasks; knowledge can be updated by swapping the index; a better retriever helps.
- Does not carry over directly: the retriever-generator co-adaptation, the specific gains over closed-book T5, and the RAG-Sequence vs RAG-Token trade-off.
- Prompt-only RAG makes the generator's reading of the context unconstrained; position effects such as lost-in-the-middle and distraction by irrelevant passages are problems the original model partly trains away.
- Design
You must build a RAG system for a domain corpus (say, biomedical abstracts) with only 2,000 question-answer pairs and no relevance labels. Using RAG's design, decide which components to train, what k to use, whether to use RAG-Sequence or RAG-Token, and how you would check that the retriever is actually being used.
What a strong answer covers
- Start from a strong pre-trained dense retriever; keep the document encoder and index frozen to avoid re-indexing; fine-tune the query encoder and generator on the marginal likelihood.
- Compare with a BM25 retriever, as Table 6 does. Biomedical queries are often entity-heavy, where BM25 can win.
- k = 5–10 in training (the paper's range), tuned on dev. RAG-Sequence for short factual answers; RAG-Token when answers combine facts from several passages.
- Check use of retrieval: index hot-swap or corrupt-the-index tests, accuracy when the answer is in no retrieved passage (the paper reports 11.8% on NQ), and the document posterior per output.
- With only 2,000 pairs, overfitting the generator is the main risk; consider freezing it and training only the query encoder.
- Connect
RAG retrieves once from the input question, before generating. IRCoT, Self-RAG and RL-trained search agents all retrieve more than once or decide whether to retrieve. Explain which RAG assumption each of these relaxes, and why the latent-variable training of RAG does not scale to multi-step search.
What a strong answer covers
- RAG assumes one retrieval from the question suffices. IRCoT relaxes this by re-querying with each chain-of-thought sentence; this matters for multi-hop questions where the second-hop entity is not in the question.
- RAG always retrieves. Self-RAG learns when to retrieve and critiques relevance and support with reflection tokens.
- RAG writes no queries; the query is the input. Search agents (ReAct, Search-o1, Search-R1) write their own queries.
- Marginalising over k documents is tractable for one retrieval step. Over T steps the number of document paths grows as k to the power T, and query writing is a discrete decision, so later work uses prompting, distillation or RL instead of exact marginal likelihood.