Vibe Engines
YouTube
Paper 03~8 min readNeurIPS 2020
Paper Breakdown

Retrieval-Augmented
Generation, explained.

A language model is a brilliant student who took a closed-book exam on the entire internet — and now answers everything from memory, blurring details and inventing the rest. This 2020 paper handed that student a library card: retrieve the right pages first, then answer. It's the idea behind every "chat with your docs" product you've used.

The delta

What changes against retrieval alone: the retrieved text is generated from

Rungs 1 to 7 find documents. A user with a question then has to read them. And a language model asked the same question answers from its parameters, which is a fixed, undated, unattributable store — it cannot be updated without training, and it cannot say where anything came from.

The change is to wire the two together and train them as one system: retrieve passages with a dense retriever, condition a generator on the question and the retrieved text, and treat the retrieved document as a latent variable — so the generator's loss propagates back into the retriever, teaching it to fetch what actually helps generation rather than what looks similar to the question.

The property that follows is the one the whole industry took: the model's knowledge lives in an index you can edit. Swap a document and the answer changes with no gradient step; the answer can cite the passage it came from; and a claim can be checked against a source. That is a different kind of system from one that has memorised, and it is why this rung is the architecture behind essentially every deployed question-answering product. The paper also distinguishes marginalising over documents once per sequence from doing it per token — the latter lets a single answer draw on several passages, which matters exactly where one passage does not contain the whole answer.

01

The closed-book problem

By 2020, large language models could answer trivia surprisingly well — from memory alone. All their knowledge was crammed into their weights during training, a process the authors call parametric memory. Impressive, but it has three deep flaws.

It's lossy: facts get blurred into a statistical haze, so the model confidently makes things up — hallucinates. It's frozen: to teach it something new, or fix a wrong fact, you have to retrain. And it's opaque: it can't tell you where an answer came from, because there is no "where" — just a fog of weights.

02

The big idea: give it a library card

The paper's fix is elegant: don't force the model to memorize everything. Pair it with a searchable external collection — the authors used all of Wikipedia — that it can look things up in on demand. They call this searchable index non-parametric memory.

Now answering a question becomes two steps instead of one: retrieve the most relevant documents, then generate an answer grounded in them. The model no longer has to be the encyclopedia; it just has to know how to read one.

The RAG loop
Query→ Retriever→ Top-k docs→ Generator→ Grounded answer
03

The retriever: matching on meaning

Old-school search matched keywords — miss the exact word and you miss the document. RAG uses dense retrieval (DPR): a neural encoder turns the query into a vector and every document into a vector, and "relevant" simply means "close in vector space." Ask about "the capital of France" and it finds the passage about Paris even if the word "capital" never appears.

All of Wikipedia is pre-encoded once into a vector index. At query time, the retriever encodes the question and pulls the top-k nearest passages — a handful of the most relevant pages, in milliseconds.

Worth knowing

This vector-search step is exactly what a vector database does today. The RAG paper is why "embed your documents, then do nearest-neighbor search" became the backbone of modern AI applications.

04

The generator: answer from evidence

The retrieved passages are handed to a generator — a sequence-to-sequence model (BART in the paper) — alongside the original question. The generator writes its answer conditioned on that evidence, effectively reading the passages and composing a response instead of dredging one up from memory.

Crucially, retriever and generator are trained together, end to end. The generator's success signal flows back and teaches the retriever what "relevant" really means for producing good answers — the two halves learn to cooperate.

05

RAG-Sequence vs RAG-Token

The paper offers two flavors. RAG-Sequence commits to one set of retrieved documents and writes the entire answer from them — simple and coherent. RAG-Token is more fluid: it can lean on a different document for each token it generates, so a single answer can stitch together facts from several sources.

Ask "Where were these two authors born?" and RAG-Token can pull one author's birthplace from one passage and the other's from another, mid-sentence. More flexible, slightly more expensive.

The difference is exactly where the sum over documents sits. Both marginalize over the retrieved set z, but RAG-Sequence sums outside the product over answer tokens; RAG-Token sums inside:

That placement is the whole story. RAG-Sequence forces one document to account for every token, so an answer whose facts are split across two passages is penalized. RAG-Token lets each token pick its own document, so the split answer stays likely. The runnable version below puts numbers on the two-authors case — RAG-Token scores it ~2.8× higher.

Since then

What the authors admit, and what happened next

The reduction in fabrication is partial and not a guarantee, which the paper is careful about and the marketing was not. Grounding a generator in retrieved text makes it more likely to say what the text says; nothing forces it to. A model can still misread a passage, blend it with parametric knowledge, or produce a citation that does not support the sentence attached to it — and that last failure is worse than an uncited error, because it comes with a credential.

The system also inherits every weakness of its retriever. If the passage is not retrieved the answer cannot be grounded in it, and the retriever's out-of-domain fragility from rung 6 becomes the whole system's fragility. In practice most disappointing deployments of this architecture are retrieval failures wearing a generation costume.

How it held up: it is the default architecture for putting a language model on top of a corpus, and the reason the vector-database industry exists. What changed is that the joint training this paper introduced is mostly not done any more — the common deployment is an off-the-shelf retriever and an off-the-shelf model glued by a prompt, which is simpler and gives up the paper's most interesting mechanism. And the top-k framing has a structural limit that rung 9 names: some questions are not answered by any k passages.

SOLVE IT YOURSELF

Where RAG-Sequence and RAG-Token split

Retrieval is an inner-product top-k with a softmax prior; the two marginalizations are three lines each. The demo is the paper's own "where were these two authors born?" case: doc A knows author one's birthplace, doc B knows author two's, neither knows both. RAG-Sequence — which makes a single document explain the whole answer — scores it 0.09; RAG-Token, free to switch documents per token, scores it 0.25, about 2.8× higher. That gap is the reason RAG-Token exists. Change the per-document token probabilities and watch which scheme wins.

YOUR TASK

Write the body of rag_sequence. Everything else in the file is already written; this is the function the paper is about. Press ▶ Run to check it against the 5 assertions below — they start red.

WHAT IT HAS TO SATISFY — 5 ASSERTIONS
  1. Softmax is a valid distribution
  2. Retrieve picks the k highest inner products
  3. RAG-Sequence marginalizes whole sequences
  4. RAG-Token marginalizes per token
  5. Split-fact answers favor RAG-Token
CPython · WebAssembly
06

The real results

RAG set new state-of-the-art on open-domain question answering — Natural Questions, TriviaQA, WebQuestions — beating both pure parametric models and earlier retrieve-and-read pipelines. Just as telling: its answers were more specific, more factual, and less prone to hallucination, and because every answer traced back to real passages, they could be cited.

ApproachKnowledge lives in…Update knowledge
Closed-book LLMFrozen weights (parametric)Retrain the model
Fine-tuningFrozen weights (parametric)Retrain / re-tune
RAGEditable index (non-parametric)Edit a document — instant

That last row is the quiet superpower: swap in a fresh Wikipedia dump — or fix one wrong document — and the model's knowledge updates immediately, no retraining required.

07

Why it still matters

Every "chat with your PDF," every enterprise knowledge assistant, every AI search box that cites its sources is a descendant of this paper. The specific models have changed — bigger generators, better embedding models, hybrid keyword-plus-vector retrieval, re-rankers, agentic multi-hop retrieval — but the core loop is unchanged: retrieve, then generate.

RAG reframed knowledge as something a model looks up rather than something it is. That separation — reasoning in the weights, facts in an index you control — is the single most important pattern in applied AI today.

Worth knowing

Building a RAG system today means choosing an embedding model, a vector database, a chunking strategy, and a re-ranker — then evaluating retrieval quality. Every one of those decisions traces back to the two-step loop this paper introduced.

Check yourself

5 questions on this paper

Answer each one out loud before you open it. Recalling an answer is what makes it stick; recognising one you have just read is not. Your score is kept on this device.

What is Retrieval-Augmented Generation (RAG)?

Show answer

RAG is a technique, introduced in a 2020 paper, that pairs a language model with a retriever over an external document collection. Instead of answering only from what it memorized during training, the model first fetches the most relevant documents for a query and then generates its answer conditioned on them — so knowledge lives in a searchable index it can look things up in, not just in frozen weights.

Why does RAG reduce hallucination?

Show answer

A pure language model answers from a blurry compression of its training data and will confidently invent facts it never really learned. RAG grounds each answer in specific retrieved passages, giving the model real evidence to quote and letting the system cite sources — which sharply reduces fabricated facts and makes answers checkable.

What is the difference between RAG and fine-tuning?

Show answer

Fine-tuning bakes new knowledge into the model's weights through more training — expensive, slow to update, and hard to attribute. RAG keeps knowledge in an external index you can edit instantly: add, remove, or correct a document and the model's answers change immediately, with no retraining. Fine-tuning changes behavior and style; RAG changes what the model knows.

What is dense passage retrieval?

Show answer

Dense retrieval encodes both the query and every document into vectors with a neural encoder, then finds the closest document vectors to the query vector — matching on meaning rather than exact keywords. The RAG paper used DPR (Dense Passage Retrieval) over a vector index of Wikipedia to fetch the top-k passages for each query.

What is the difference between RAG-Sequence and RAG-Token?

Show answer

RAG-Sequence picks a set of retrieved documents and generates the whole answer conditioned on the same documents. RAG-Token can attend to different retrieved documents for different tokens of the answer, letting a single response weave together facts from several sources — more flexible, at a little more cost.

Where this sits

From a word vector to RAG

The longest ladder here, and the most linear: nine papers that carry one idea — text as geometry — from a 2013 word embedding to a graph-structured retrieval system.

  1. 1Word2Vec2013
  2. 2GloVe2014
  3. 3Sentence-BERT2019
  4. 4Product Quantization2011
  5. 5HNSW2016
  6. 6Dense Passage Retrieval2020
  7. 7ColBERT2020
  8. 8Retrieval-Augmented Generation2020
  9. 9GraphRAG2024

All 110 papers, in 19 ladders →

Finished this one? 0 / 110 Paper Breakdowns done

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Paper Breakdowns