FlashPapers
NeurIPS 2020 Highlight

Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks

By 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, UCL, NYU)

TL;DR

RAG bridges the gap between parametric LLMs and external knowledge bases. By combining a pre-trained sequence-to-sequence model (BART) with a dense document retriever (DPR), RAG accesses 21 million Wikipedia passages on the fly to generate highly accurate, verifiable, and dynamically updatable responses without retraining.

Non-Parametric Memory End-to-End Differentiable Hot-Swappable Index State-of-the-Art QA

Why This Matters

Large Language Models (LLMs) are incredibly powerful, but they suffer from a fundamental flaw: they store their world knowledge entirely within their static parameters. This parametric memory is frozen at the moment of training. When asked to perform knowledge-intensive tasks, these models face severe bottlenecks:

  • Hallucinations When parameters fail to recall a fact, the model confidently fabricates plausible-sounding nonsense.
  • Stale Knowledge Updating facts (e.g., a new president) requires expensive retraining or fine-tuning of the entire model.
  • Zero Provenance The model cannot cite its sources, making its outputs difficult to verify or trust.

By introducing an external, non-parametric memory (a dense document index of Wikipedia), RAG allows the model to search, read, and write answers backed by real, verifiable documents.

The Big Idea

"We explore a general-purpose fine-tuning recipe for retrieval-augmented generation (RAG) — models which combine pre-trained parametric and non-parametric memory for language generation."

Unlike previous hybrid models that were limited to extractive QA (simply highlighting a span of text in a document), RAG is a sequence-to-sequence model. It can synthesize information from multiple sources, paraphrase, and generate completely free-form natural language. Crucially, the entire system is end-to-end differentiable: the generation loss propagates back to train the retriever to fetch better documents.

How It Works

RAG operates on a simple, elegant sequence-to-sequence workflow. Given an input query $x$, the model retrieves top-$K$ documents $z$ using a bi-encoder retriever, and then passes both $x$ and $z$ to a seq2seq generator to produce the final output $y$.

1. Dense Vector Space Retrieval (DPR)

The retriever uses Dense Passage Retrieval (DPR). Both the query $x$ and documents $z$ are mapped to a 768-dimensional space using BERT. The retrieval probability is the softmax of the inner product of their embeddings:

$$p_\eta(z|x) \propto \exp(\mathbf{d}(z)^\top \mathbf{q}(x))$$

Interactive Demo: Dense Vector Space Search

Drag the Query Vector (purple dot) around the 2D representation of the document space. Watch how the nearest Wikipedia passages are retrieved in real-time based on inner product similarity.

Query Vector
Retrieved Passages (Top-2)

2. Sequence vs. Token Marginalization

Once the top-$K$ documents are retrieved, how do we use them to generate text? The paper introduces two distinct architectures that marginalize over the latent documents $z$ in different ways:

RAG-Sequence

Single Document focus

Uses the same retrieved document to generate the entire sequence. It calculates the sequence probability for each document, then sums them up.

$$p(y|x) \approx \sum_{z} p_\eta(z|x) \prod_{i}^N p_\theta(y_i|x, z, y_{1:i-1})$$
RAG-Token

Multi-Document Synthesis

Can use a different document for each token. This allows the model to synthesize information from multiple sources to construct a single sentence.

$$p(y|x) \approx \prod_{i}^N \sum_{z} p_\eta(z|x) p_\theta(y_i|x, z, y_{1:i-1})$$

Interactive Generation: RAG-Token vs RAG-Sequence

Step through the generation of a response to the query: "Who wrote the novels 'The Sun Also Rises' and 'A Farewell to Arms'?". Observe how the document distributions shift dynamically.

Step: 0 / 6
Generated Output:
Document Posterior Probability $p(z|x, y_{1:i-1})$

3. Dynamic Knowledge Hot-Swapping

One of the most remarkable features of RAG is that its world knowledge can be updated instantly without retraining. Because the non-parametric memory is just an external index, we can "hot-swap" the index with a newer version (e.g., a 2016 Wikipedia vs. a 2018 Wikipedia) to reflect changes in the real world.

Interactive Demo: Hot-Swapping the Index

Select a query and toggle between the 2016 Index and the 2018 Index. Watch how the retrieved document and the generated answer change instantly while the model parameters remain completely frozen!

Retrieved Document Snippet

Generated Answer

Results & Performance

RAG sets a new state-of-the-art on several open-domain QA tasks, outperforming both traditional extractive models and massive parametric-only models like T5 (even with 11 Billion parameters).

Accuracy Comparison (Exact Match Score)

*T5-11B uses 11 Billion parameters (parametric memory only). RAG-Sequence uses a BART-large generator (400M parameters) + DPR retriever.

Limitations & Open Questions

While RAG represents a massive leap forward, the authors highlight several critical challenges:

  • Retrieval Collapse: During joint training, the retriever can sometimes "collapse" and learn to retrieve the exact same documents regardless of the input query. This is particularly prevalent in tasks like story generation where explicit factual grounding is less strictly enforced.
  • Computational Footprint: Storing and querying a 21-million-passage MIPS index requires significant memory. Even with quantization (FAISS), it requires approximately 36GB of RAM just to keep the index in memory.
  • Source Bias: RAG relies entirely on the quality and neutrality of its source corpus (Wikipedia). If the index contains biased, incomplete, or false information, the generator will faithfully propagate those errors.

Glossary

Parametric Memory

The knowledge stored implicitly within the weights (parameters) of a neural network, acquired during pre-training or fine-tuning.

Knowledge-Intensive Tasks

Tasks that humans could not reasonably be expected to perform without access to an external knowledge source, such as open-domain question answering or fact verification.

MIPS (Maximum Inner Product Search)

An algorithmic approach to quickly find the vector in a large database that has the highest dot product with a query vector, crucial for sub-linear time document retrieval.

Citation

@inproceedings{lewis2020retrieval,
  title={Retrieval-augmented generation for knowledge-intensive nlp tasks},
  author={Lewis, Patrick and Perez, Ethan and Piktus, Aleksandra and Petroni, Fabio and Karpukhin, Vladimir and Goyal, Naman and K{\"u}ttler, Heinrich and Lewis, Mike and Yih, Wen-tau and Rockt{\"a}schel, Tim and others},
  booktitle={Advances in Neural Information Processing Systems},
  volume={33},
  pages={9459--9474},
  year={2020}
}
Made with Flash Papers — make your own