Skip to content
Arslan Vuzmal Lone
Research paper · Retrieval · NeurIPS 2020

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

Explained by Arslan Vuzmal Lone · Published 9 October 2026 · Rewritten 18 October 2026 with the paper’s own tables
01 · The short answer

What the paper did, in five lines

Direct answer
  • 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.
02 · The paper

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.

Why “knowledge-intensive”
The tasks in the paper are ones a person could not reasonably do without looking something up: answering trivia, writing a Jeopardy clue about a named entity, checking whether a claim is supported by Wikipedia. That is also a fair description of most questions a company assistant gets.
03 · How it works

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.

One question through RAGStep 1 of 4
Step 01

Encode the question

A BERT-base query encoder turns x into a dense vector q(x).

Figure 1:The RAG pipeline: the question is encoded, the index is searched, and the generator writes the answer from the question plus each retrieved passage. Drawn from §2 and §3 of the paper.

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.

pη(z∣x)∝exp⁡(d(z)⊤q(x))p_\eta(z \mid x) \propto \exp\big(\mathbf{d}(z)^\top \mathbf{q}(x)\big)

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.

RAG layer stack
QuestionQuery encoderIndexGeneratorAnswer

The input x is the question.

Step through the five stages. The descriptions cite the paper’s sections.
The number of cards drawn for the index is illustrative.

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.

pRAG-Seq(y∣x)≈∑z∈top-kpη(z∣x)∏iNpθ(yi∣x,z,y1:i−1)p_{\text{RAG-Seq}}(y \mid x) \approx \sum_{z \in \text{top-}k} p_\eta(z \mid x) \prod_{i}^{N} p_\theta(y_i \mid x, z, y_{1:i-1})

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.

pRAG-Tok(y∣x)≈∏iN∑z∈top-kpη(z∣x) pθ(yi∣x,z,y1:i−1)p_{\text{RAG-Tok}}(y \mid x) \approx \prod_{i}^{N} \sum_{z \in \text{top-}k} p_\eta(z \mid x)\, p_\theta(y_i \mid x, z, y_{1:i-1})

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.

RAG-Sequence
0.198
Σ p(z) · p(t₁|z) · p(t₂|z): one document writes the whole answer
RAG-Token
0.274
Π Σ p(z) · p(tᵢ|z): each token can lean on a different document

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.

Figure 2:RAG-Sequence and RAG-Token on a two-document, two-token toy answer. Illustrative: you set the probabilities.
04 · Training and decoding

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).

05 · The experiments

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:

TaskWhat the model must doDatasetsMetric
Open-domain QAAnswer a factual questionNatural Questions, TriviaQA, WebQuestions, CuratedTrecExact match
Abstractive QAWrite a full-sentence answerMS-MARCO NLGBLEU-1, ROUGE-L
Question generationWrite a Jeopardy clue for an answer entityJeopardy (SearchQA split)BLEU-1, Q-BLEU-1, human judges
Fact verificationLabel a claim as supported, refuted or not enough infoFEVER (3-way and 2-way)Label accuracy
Source: Lewis et al. (2020), §3.1–3.4
Dataset sizes. WebQuestions and CuratedTrec are small, so the paper initialises those models from the Natural Questions RAG model.
DatasetTrainDevTest
Natural Questions79,1698,7583,611
TriviaQA78,7868,83811,314
WebQuestions3,4183622,033
CuratedTrec635134635
Jeopardy question generation97,39213,71426,849
MS-MARCO153,72612,468101,093 (hidden subset used)
FEVER 3-way145,45010,00010,000
FEVER 2-way96,9666,6666,666
Dataset sizes. WebQuestions and CuratedTrec are small, so the paper initialises those models from the Natural Questions RAG model.Source: Lewis et al. (2020), Table 7
06 · Results

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.

T5-11B · Closed book34.5
T5-11B + SSM · Closed book36.6
REALM · Open book40.4
DPR · Open book41.5
RAG-Token · RAG44.1
RAG-Sequence · RAG44.5

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.

Figure 3:Open-domain QA test scores, exact match. Choose a dataset.
ModelNQTQA (open / Wiki test)WQCT
T5-11B (closed book)34.5– / 50.137.4–
T5-11B + SSM (closed book)36.6– / 60.544.7–
REALM (open book)40.4– / –40.746.8
DPR (open book)41.557.9 / –41.150.6
RAG-Token44.155.2 / 66.145.550.0
RAG-Sequence44.556.8 / 68.045.252.2
Source: Lewis et al. (2020), Table 1

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

* uses gold context or evidence. FEVER is a classification task, on which the two RAG variants are equivalent, so they share one score.
ModelJeopardy B-1Jeopardy QB-1MS-MARCO R-LMS-MARCO B-1FEVER 3-wayFEVER 2-way
State of the art––49.8*49.9*76.892.2*
BART15.119.738.241.664.081.1
RAG-Token17.322.240.141.572.589.5
RAG-Sequence14.721.440.844.272.589.5
* uses gold context or evidence. FEVER is a classification task, on which the two RAG variants are equivalent, so they share one score.Source: Lewis et al. (2020), Table 2

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).

452 pairs of generations, RAG-Token vs BART.
JudgementFactualitySpecificity
RAG better42.7%37.4%
BART better7.1%16.8%
Both good11.7%11.8%
Both poor17.7%6.9%
No majority20.8%20.1%
452 pairs of generations, RAG-Token vs BART.Source: Lewis et al. (2020), Table 4
A small inconsistency in the paper
The text of §4.3 says both models were factual “in a further 17% of cases”; Table 4 reports “Both good” for factuality as 11.7%. This page uses the table.
Ratio of distinct to total tri-grams: higher means less repetitive text. RAG gets more diverse without any diversity-promoting decoding.
ModelMS-MARCOJeopardy QGen
Gold (human-written)89.6%90.0%
BART70.7%32.4%
RAG-Token77.8%46.8%
RAG-Sequence83.5%53.8%
Ratio of distinct to total tri-grams: higher means less repetitive text. RAG gets more diverse without any diversity-promoting decoding.Source: Lewis et al. (2020), Table 5

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).

07 · Updating knowledge

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.

Wikipedia index used
Correct answer is the leader in
68%

Index and question year match: the model answers most of them correctly.

Source: Lewis et al. (2020), §4.5 “Index hot-swapping”.

Figure 4:Index hot-swapping: accuracy for each combination of index and answer year.

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”.

08 · What matters inside

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.

Development set. FEVER scores are shared by both variants. Selected columns; the paper’s table also reports Jeopardy QB-1, MS-MARCO B-1 and FEVER 2-way.
ModelNQTQAWQCTJeop B-1MSM R-LFEVER-3
RAG-Token-BM2529.741.532.133.117.555.575.1
RAG-Sequence-BM2531.844.136.633.811.156.5–
RAG-Token-Frozen37.850.137.151.116.755.972.9
RAG-Sequence-Frozen41.252.141.852.611.856.7–
RAG-Token43.554.846.551.917.956.274.5
RAG-Sequence44.055.844.953.415.357.2–
Development set. FEVER scores are shared by both variants. Selected columns; the paper’s table also reports Jeopardy QB-1, MS-MARCO B-1 and FEVER 2-way.Source: Lewis et al. (2020), Table 6

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).

09 · Limits

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.

Retrieval sets the ceiling
If the right passage is not retrieved, the generator can only fall back on its weights. The FEVER check found a gold article in the top 10 in 90% of cases, which also means 10% of the time it was not there.
Public, encyclopaedic text
Every result comes from Wikipedia and public benchmarks. Company documents are messier: duplicates, outdated versions, tables and scans. Results on them have to be measured, not assumed from this paper.
Frozen documents, frozen weaknesses
Keeping the document encoder fixed makes the index swappable, but it also means the document side never adapts to the task.
Cost of decoding
Thorough Decoding for RAG-Sequence needs extra forward passes for every candidate under every document, and open-domain QA results for RAG-Sequence used 50 documents. Answers are not free to produce.
10 · In business

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.

Customer support

Answers from the help centre and policies, with the source linked and a handoff when nothing relevant is found.

Internal knowledge

Staff ask HR, IT and process questions in plain words instead of searching folders.

Sales and quoting

Product details and pricing rules pulled from current documents, not from memory.

What to measure before trusting it
On your own documents: how often the right passage is in the top few results, how often the answer is supported by the passages it cites, and how often it correctly says it does not know. The paper measured the equivalents on Wikipedia; your numbers will differ.
11 · Glossary

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).
12 · Check yourself

Three questions

Check your understanding3 questions
  1. Q1.In the paper’s setup, which component is kept fixed during fine-tuning?

  2. Q2.With a 2018 index, how often did RAG name the correct 2016 world leader?

  3. 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).
13 · Cite

Cite this paper

BibTeX
@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. [1]
  2. [2]
  3. [3]
  4. [4]
Written by
Arslan Vuzmal Lone

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.

AI Workflow Audit · €390 · Credited toward build · or email arslanvuzmallone@gmail.com