Retrieval-Augmented Generation, explained
Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks · Patrick Lewis, Ethan Perez, Aleksandra Piktus, Fabio Petroni, Vladimir Karpukhin, Naman Goyal, Heinrich Küttler, Mike Lewis, Wen-tau Yih, Tim Rocktäschel, Sebastian Riedel, Douwe Kiela · Facebook AI Research, University College London, New York University · NeurIPS 2020
What the paper did, in five lines
- A language model keeps what it learned in its weights: it cannot be updated without retraining, cannot point to a source, and can produce fluent answers that are wrong.
- RAG adds a search step. A retriever (DPR) finds relevant passages in 21 million chunks of Wikipedia; a generator (BART) writes the answer from the question plus those passages.
- Both parts start pre-trained and are fine-tuned together, with no labels saying which passage is the right one. The model learns to retrieve whatever helps it answer.
- It set new best results on three of four open-domain question-answering benchmarks, and human judges found its Jeopardy questions more factual and more specific than BART’s.
- Swapping the Wikipedia index for an older one changed the model’s answers about world leaders to match, with no retraining. That is the property businesses use today.
The problem it set out to solve
By 2020, large pre-trained language models had shown they absorb a surprising amount of factual knowledge during training. The paper’s abstract names three things they still could not do well. They could not reliably access and manipulate that knowledge, so on knowledge-intensive tasks they lagged behind systems built for the task. They could not show provenance, meaning where an answer came from. And they could not have their world knowledge updated without being trained again.
Models with a differentiable link to an external memory existed, but, as the authors put it, they had “only been investigated for extractive downstream tasks”: systems that find and copy a span of text from a document. RAG asks whether the same idea works when the model has to write the answer.
The paper frames this as two kinds of memory. The parametric memory is the generator’s weights. The non-parametric memory is a dense vector index of Wikipedia that the model searches. The second can be read, checked and replaced; the first cannot. A model that uses both should be able to keep the fluency of a large language model and gain the traceability of a search engine.
Two parts: a retriever and a generator
Given an input x (a question), RAG retrieves text passages z and uses them as extra context when generating the output y. There are two components, both taken off the shelf and then fine-tuned together.
Encode the question
A BERT-base query encoder turns x into a dense vector q(x).
The retriever: DPR
The retriever is Dense Passage Retrieval (DPR), a bi-encoder: one BERT-base model encodes documents, another encodes queries, and relevance is the inner product of the two vectors (§2.2). The paper initialises it from a DPR model already trained to find passages that answer TriviaQA and Natural Questions, and uses that same model to build the index.
The retriever’s probability for passage z given question x grows with the inner product of their vectors.
- d(z)
- BERT-base document encoder applied to passage z
- q(x)
- BERT-base query encoder applied to the question
- η
- retriever parameters
Finding the top k passages with the highest inner product is a maximum inner product search (MIPS) problem, which can be solved approximately in sub-linear time. The index uses FAISS with a Hierarchical Navigable Small World approximation (§3).
The generator: BART
The generator is BART-large, a pre-trained sequence-to-sequence transformer. Section 2.3 gives it 400M parameters; the appendix counts 406M trainable parameters for BART-large and 110M for each BERT-base encoder. To give BART a retrieved passage, the paper simply concatenates it with the question.
The input x is the question.
Two ways to combine passages
The retrieved passage is treated as a hidden (latent) variable: the model is never told which passage is right, so it sums over the top k it found. The paper defines two ways of doing that sum (§2.1).
RAG-Sequence uses the same passage for the whole answer. It computes the probability of the full answer under each passage, then takes a weighted average.
Average, over retrieved passages, of the probability of the whole answer given that passage.
- y_i
- the i-th token of the answer
- θ
- generator (BART) parameters
RAG-Token moves the sum inside the product: each output token can be drawn from a different passage. A Jeopardy clue that combines two facts from two articles is the paper’s example of where that helps.
For each token, average over passages; then multiply across tokens.
Two documents were retrieved. The answer has two tokens. Document 1 supports the first token well, document 2 the second. Move the sliders and compare the two ways the paper combines documents.
Illustrative. The numbers are whatever you set; the formulas are the paper’s §2.1, simplified to two documents and two tokens with no conditioning on earlier tokens.
What is trained, and how answers are produced
Training uses pairs of inputs and outputs only: a question and its answer, a Jeopardy answer and its clue, a claim and its label. There is no direct supervision of which document should be retrieved. The objective is to minimise the negative marginal log-likelihood of each target, using Adam (§2.4).
Only two of the three networks are updated: the query encoder and BART. The document encoder is frozen, and with it the index. Updating it would mean re-encoding and re-indexing every passage periodically, as REALM does during pre-training; the authors report they “do not find this step necessary for strong performance”. This is the decision that makes the index swappable later.
Decoding differs between the two variants (§2.5). RAG-Token is a standard sequence-to-sequence model with a modified token probability, so an ordinary beam search works. RAG-Sequence is harder: the probability of an answer does not break into per-token pieces. The paper runs beam search once per document and then scores every candidate under every document (“Thorough Decoding”), or skips the extra forward passes by assuming a candidate that did not appear in a document’s beam has near-zero probability there (“Fast Decoding”).
Practical details from the appendices: models were trained with Fairseq in mixed precision across eight 32GB NVIDIA V100 GPUs, though the authors note training and inference can run on one GPU. The index vectors sat in CPU memory, about 100 GB for all of Wikipedia, reduced to 36GB with FAISS compression. For open-domain QA test scores, RAG-Token used 15 retrieved documents and RAG-Sequence 50 with Thorough Decoding; for generation tasks both used 10 documents and a beam size of four (Appendices A and C).
One Wikipedia index, four kinds of task
Every experiment uses the same knowledge source: the December 2018 Wikipedia dump, split into disjoint 100-word chunks, 21M documents in total (§3). During training the model retrieves the top 5 or top 10 documents. The tasks span four kinds of knowledge-intensive work:
| Task | What the model must do | Datasets | Metric |
|---|---|---|---|
| Open-domain QA | Answer a factual question | Natural Questions, TriviaQA, WebQuestions, CuratedTrec | Exact match |
| Abstractive QA | Write a full-sentence answer | MS-MARCO NLG | BLEU-1, ROUGE-L |
| Question generation | Write a Jeopardy clue for an answer entity | Jeopardy (SearchQA split) | BLEU-1, Q-BLEU-1, human judges |
| Fact verification | Label a claim as supported, refuted or not enough info | FEVER (3-way and 2-way) | Label accuracy |
| Dataset | Train | Dev | Test |
|---|---|---|---|
| Natural Questions | 79,169 | 8,758 | 3,611 |
| TriviaQA | 78,786 | 8,838 | 11,314 |
| WebQuestions | 3,418 | 362 | 2,033 |
| CuratedTrec | 635 | 134 | 635 |
| Jeopardy question generation | 97,392 | 13,714 | 26,849 |
| MS-MARCO | 153,726 | 12,468 | 101,093 (hidden subset used) |
| FEVER 3-way | 145,450 | 10,000 | 10,000 |
| FEVER 2-way | 96,966 | 6,666 | 6,666 |
What the paper found
Open-domain question answering
Table 1 compares RAG with “closed-book” models that answer from their weights alone (T5-11B, with and without salient span masking) and with “open-book” retrieve-and-extract systems (REALM, DPR). Both RAG variants beat every closed-book model, and RAG set new best scores on Natural Questions, WebQuestions and CuratedTrec. On TriviaQA’s standard open test set, DPR stayed ahead.
Exact match on the test set, higher is better. Models missing from a tab have no score for it in the paper. Source: Lewis et al. (2020), Table 1.
| Model | NQ | TQA (open / Wiki test) | WQ | CT |
|---|---|---|---|---|
| T5-11B (closed book) | 34.5 | – / 50.1 | 37.4 | – |
| T5-11B + SSM (closed book) | 36.6 | – / 60.5 | 44.7 | – |
| REALM (open book) | 40.4 | – / – | 40.7 | 46.8 |
| DPR (open book) | 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 |
Two details in §4.1 matter more than the headline. First, RAG can produce a correct answer even when no retrieved document contains it word for word: on Natural Questions it scores 11.8% on such cases, where an extractive model would score 0%. Second, the comparison with size is stark. The appendix notes that T5-large, at 770M parameters the closest T5 model in size to RAG, scores 28.9 exact match on Natural Questions, against 44.5 for RAG-Sequence with 626M trainable parameters.
Generation and fact verification
| Model | Jeopardy B-1 | Jeopardy QB-1 | MS-MARCO R-L | MS-MARCO B-1 | FEVER 3-way | FEVER 2-way |
|---|---|---|---|---|---|---|
| State of the art | – | – | 49.8* | 49.9* | 76.8 | 92.2* |
| BART | 15.1 | 19.7 | 38.2 | 41.6 | 64.0 | 81.1 |
| RAG-Token | 17.3 | 22.2 | 40.1 | 41.5 | 72.5 | 89.5 |
| RAG-Sequence | 14.7 | 21.4 | 40.8 | 44.2 | 72.5 | 89.5 |
On MS-MARCO, RAG-Sequence beats BART by 2.6 BLEU and 2.6 ROUGE-L points. It does not reach the state of the art, but those systems are given the gold passages that contain the answer, and many MS-MARCO questions cannot be answered from Wikipedia at all (§4.2). On Jeopardy, RAG-Token is best on both metrics. On FEVER, RAG gets within 4.3% of pipeline systems that are trained with supervision about which evidence to retrieve; RAG gets no such supervision.
What human judges said
Automatic metrics reward word overlap, not truth. So the authors asked people to compare 452 pairs of Jeopardy clues, one from BART and one from RAG-Token, for factuality and for specificity (§4.3).
| Judgement | Factuality | Specificity |
|---|---|---|
| RAG better | 42.7% | 37.4% |
| BART better | 7.1% | 16.8% |
| Both good | 11.7% | 11.8% |
| Both poor | 17.7% | 6.9% |
| No majority | 20.8% | 20.1% |
| Model | MS-MARCO | Jeopardy QGen |
|---|---|---|
| Gold (human-written) | 89.6% | 90.0% |
| BART | 70.7% | 32.4% |
| RAG-Token | 77.8% | 46.8% |
| RAG-Sequence | 83.5% | 53.8% |
Does it retrieve the right evidence?
FEVER comes with human-annotated gold evidence, which lets the authors check retrieval directly. The top retrieved document came from a gold article in 71% of cases, and a gold article was among the top 10 retrieved in 90% of cases (§4.4).
Swap the index, change the answers
The experiment that best explains why RAG matters outside research is the shortest in the paper. The authors built a second index from a December 2016 Wikipedia dump, listed 82 world leaders who changed between 2016 and 2018, and asked the Natural Questions RAG model “Who is {position}?” for each, once with each index (§4.5).
The authors asked the same RAG model “Who is {position}?” for 82 world leaders who changed between 2016 and 2018, and swapped only the document index. Pick an index and the year whose answers count as correct.
Index and question year match: the model answers most of them correctly.
Source: Lewis et al. (2020), §4.5 “Index hot-swapping”.
With matching index and year the model was right 70% of the time (2016) and 68% (2018). With the wrong index, accuracy fell to 12% and 4%. The model weights were identical in all four runs. The answers followed the documents, which is the point: the authors conclude that RAG’s world knowledge can be updated “by simply replacing its non-parametric memory”.
Ablations: learned retrieval, BM25 and how many documents
Table 6 reports development-set scores for three versions of each model: with BM25 word-overlap search in place of DPR, with the retriever frozen, and with the full fine-tuned retriever.
| Model | NQ | TQA | WQ | CT | Jeop B-1 | MSM R-L | FEVER-3 |
|---|---|---|---|---|---|---|---|
| RAG-Token-BM25 | 29.7 | 41.5 | 32.1 | 33.1 | 17.5 | 55.5 | 75.1 |
| RAG-Sequence-BM25 | 31.8 | 44.1 | 36.6 | 33.8 | 11.1 | 56.5 | – |
| RAG-Token-Frozen | 37.8 | 50.1 | 37.1 | 51.1 | 16.7 | 55.9 | 72.9 |
| RAG-Sequence-Frozen | 41.2 | 52.1 | 41.8 | 52.6 | 11.8 | 56.7 | – |
| RAG-Token | 43.5 | 54.8 | 46.5 | 51.9 | 17.9 | 56.2 | 74.5 |
| RAG-Sequence | 44.0 | 55.8 | 44.9 | 53.4 | 15.3 | 57.2 | – |
Fine-tuning the retriever helps on every task, and most on open-domain QA. BM25 is far behind on question answering but is the best of the three on FEVER, whose claims are mostly about named entities and suit word overlap (§4.5). That result is worth remembering for any business system that has to match product codes, names or reference numbers.
On the number of documents: models trained with 5 or 10 retrieved passages performed about the same. At test time, retrieving more passages steadily improved RAG-Sequence on Natural Questions, while RAG-Token peaked at 10 (Figure 3 of the paper).
Where it falls short
The paper’s own broader-impact section is direct about one limit: Wikipedia, “or any potential external knowledge source, will probably never be entirely factual and completely devoid of bias”. A model that answers from documents inherits their errors. The rest of these limits follow from the setup.
What a business should take from it
Most “answer from our documents” assistants follow the shape this paper made standard: search first, then write the answer from what was found. Three results translate directly.
Updating is an editing job, not a training job. The hot-swap test shows answers following the index. For a company, keeping the assistant current means keeping the documents current and re-indexing them.
Sources can be shown. Because each answer is conditioned on retrieved passages, a system can show which ones it used, and a person can check them. That is what makes it usable for policy, support and internal knowledge.
Keyword search still has a place. BM25 beating learned retrieval on FEVER is the paper’s own evidence that exact-term matching matters for names and identifiers. Most practical systems combine the two.
Answers from the help centre and policies, with the source linked and a handoff when nothing relevant is found.
Staff ask HR, IT and process questions in plain words instead of searching folders.
Product details and pricing rules pulled from current documents, not from memory.
The terms on this page
- Parametric memory
- What a model knows because it is stored in its weights. Changing it means training the model again.
- Non-parametric memory
- Knowledge held outside the model, here a searchable index of Wikipedia passages. It can be read, checked and replaced without touching the model.
- Retriever
- The part that finds passages relevant to the input. In this paper, DPR: two BERT-base encoders, one for questions and one for passages.
- Generator
- The part that writes the output. In this paper, BART-large, given the question joined to one retrieved passage at a time.
- Bi-encoder
- A retriever that encodes questions and passages separately, so every passage can be encoded once, in advance, and stored in an index.
- Maximum inner product search (MIPS)
- Finding the stored vectors with the largest dot product with the question vector. Done approximately, for speed, with FAISS and an HNSW graph.
- Latent variable
- Something the model uses but is never told the right value of. Here, which passage is the useful one; the model sums over the top k instead.
- Marginalisation
- Adding up the probability of an answer across all the passages it could have come from, each weighted by how likely that passage is.
- Exact match (EM)
- The share of answers that match a reference answer exactly after normalisation. Used for the open-domain QA results in Table 1.
- BLEU-1 and ROUGE-L
- Overlap scores between generated and reference text: BLEU-1 counts matching single words, ROUGE-L the longest common word sequence.
- Q-BLEU-1
- A version of BLEU that gives more weight to matching entities, used for the Jeopardy question-generation task.
- Hot-swapping
- Replacing the document index at test time without retraining, to change what the model knows (§4.5).
Three questions
Q1.In the paper’s setup, which component is kept fixed during fine-tuning?
Q2.With a 2018 index, how often did RAG name the correct 2016 world leader?
Q3.On which task did replacing RAG’s learned retriever with BM25 do best?
Questions people ask
- What is retrieval-augmented generation in one sentence?
- A language model that searches a document collection for passages relevant to the question, then writes its answer conditioned on those passages, so its knowledge can be updated and traced by changing the documents rather than retraining the model.
- Did this paper invent “retrieve, then read”?
- No. Retrieve-and-read systems such as DPR and REALM came first. What Lewis et al. added was a general fine-tuning recipe in which a pre-trained retriever and a pre-trained sequence-to-sequence generator are trained together end to end, for generation tasks as well as extractive question answering.
- What is the difference between RAG-Sequence and RAG-Token?
- RAG-Sequence lets one retrieved passage drive the whole answer and then averages over passages. RAG-Token can lean on a different passage for each word it writes. On Jeopardy question generation RAG-Token scored higher; on open-domain question answering the two were close, with RAG-Sequence slightly ahead on most datasets (Table 1, Table 2).
- Which parts of the system are trained?
- The query encoder and the BART generator. The document encoder and the index stay fixed, which means the 21M passages do not have to be re-encoded during training (§2.4).
- Does RAG stop a model from making things up?
- It reduces it in the paper’s tests but does not stop it. Human judges preferred RAG for factuality in 42.7% of Jeopardy pairs against 7.1% for BART (Table 4), and the authors note that any knowledge source, Wikipedia included, can be wrong or biased.
- Can I update what a RAG model knows without retraining?
- That is what the hot-swap experiment tested. Replacing a 2018 Wikipedia index with a 2016 one changed answers about world leaders to match the older index, with no change to the model (§4.5).
Cite this paper
@inproceedings{lewis2020rag,
author = {Patrick Lewis and Ethan Perez and Aleksandra Piktus and Fabio Petroni and Vladimir Karpukhin and Naman Goyal and Heinrich K{\"u}ttler and Mike Lewis and Wen-tau Yih and Tim Rockt{\"a}schel and Sebastian Riedel and Douwe Kiela},
title = {Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks},
booktitle = {Advances in Neural Information Processing Systems 33 (NeurIPS 2020)},
year = {2020}
}Sources and primary references
- [1]Lewis et al. (2020), Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks, arXiv:2005.11401· Accessed 18 October 2026
- [2]Full text, version 4 (PDF): all tables on this page were transcribed from it· Accessed 18 October 2026
- [3]Karpukhin et al. (2020), Dense Passage Retrieval for Open-Domain Question Answering, arXiv:2004.04906· Accessed 18 October 2026
- [4]Lewis et al. (2019), BART, arXiv:1910.13461· Accessed 18 October 2026
AI automation engineer based in Budapest. Builds lead qualification, document reading, voice and messaging systems for small teams, with the code for each on GitHub.
Related reading & systems
Want an assistant that answers from your documents?
Book a 20-minute call. I will look at your documents and tell you honestly whether a retrieval-based assistant would work on them.