Retrieval & language models · 2020 · Patrick Lewis et al.

Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks

Combine parametric generation with explicit non-parametric memory so evidence can be retrieved, updated, and inspected separately from model weights.

How to read the original

  1. Read Methods and Models, distinguishing RAG-Sequence from RAG-Token.
  2. Read Generator: BART and Training to identify which components supply probabilities and which are updated.
  3. Read the experiments as evaluations of a particular retrieval-generation system, not a guarantee of citation correctness.

External memory changes the probability model

The paper combines a learned retriever with a sequence generator and treats retrieved passages as latent alternatives. RAG-Sequence marginalizes one passage choice for a complete output; RAG-Token permits the latent passage choice to vary across output positions. This is more specific than the contemporary shorthand “paste search results into a prompt.” Read the placement of sums and products carefully because it determines which explanations the model can combine.

Original reconstruction: two passages and two output tokens

Let the retriever assign probabilities 0.6 to passage A and 0.4 to passage B, restricted to this toy candidate set. Consider a particular two-token output y1,y2. Given passage A, suppose the generator assigns probability 0.8 to y1 and 0.1 to y2 after the same observed prefix y1. Given B, the corresponding probabilities are 0.2 and 0.9. These conditional probabilities are hypothetical teaching values, not experimental measurements.

For RAG-Sequence, compute the full sequence likelihood under each passage first. A contributes 0.8×0.1=0.08; B contributes 0.2×0.9=0.18. Weighting and summing gives 0.6×0.08+0.4×0.18=0.12. Each term describes a complete output conditioned on one latent passage.

For RAG-Token, mix the alternatives at each output position before multiplying. The first-token mixture is 0.6×0.8+0.4×0.2=0.56. The second-token mixture, conditioned on the given prefix, is 0.6×0.1+0.4×0.9=0.42. The product is 0.2352. The different value is not a rounding discrepancy: changing the order of marginalization changes the model.

The token-level model can combine stronger support for the first token from A with stronger support for the second from B. That flexibility is not itself a truth guarantee. Two individually plausible fragments can form an unsupported combined claim, and the highest-probability passage need not entail the entire answer.

Separate retrieval coverage from generation behavior

Suppose a question requires a date contained only in passage C, which the top-k retrieval omitted. The generator may answer from parameter memory, guess, or abstain, depending on its behavior. A correct answer in this case does not show that retrieval succeeded. Conversely, retrieving C does not ensure the generator uses the date correctly.

Build a small evaluation with independently labeled evidence passages. Measure whether required evidence appears in the retrieved set, whether the answer is correct, and whether any displayed citation actually supports the associated claim. These quantities can disagree. Report retrieval misses separately from failures to use available evidence rather than merging them into one undiagnosable accuracy number.

Updating an index is not updating every guarantee

Replacing a passage can make new information available without retraining the generator, but stale parameter memory may still influence output. Conflicting documents need an explicit policy about dates, authority, and scope. A document accessible to the retrieval service may also be unauthorized for the current user, so permission filtering belongs in the system contract.

The paper’s latent-document formulation does not by itself provide a user-facing citation verifier or an access-control system. A production answer needs additional mechanisms if those properties are required. A good lab uses a tiny corpus where every retrieved passage and every generated claim can be inspected, then tests absent evidence, conflicting evidence, and an updated fact. The purpose is to understand which boundary failed, not to label every search-assisted answer grounded merely because text was retrieved.

Reconstruction exercise

Let two passages have retrieval probabilities 0.5 each. For a specified two-token output, passage A gives conditional token probabilities 0.9 then 0.1, while B gives 0.1 then 0.9. Compute the RAG-Sequence and RAG-Token likelihoods. Then describe a test where retrieval succeeds but answer support fails, and explain why answer correctness alone cannot diagnose the retriever.

Worked solution

RAG-Sequence assigns 0.5×(0.9×0.1)+0.5×(0.1×0.9)=0.09. RAG-Token mixes each position to probability 0.5, giving 0.5×0.5=0.25. The difference comes from allowing distinct latent passage contributions across positions rather than requiring each sequence term to use one passage throughout. For a support test, include a passage stating that a museum opened in 1980, retrieve it successfully, and inspect an answer claiming it opened in 1981 while citing that passage. Retrieval coverage passed but factual use and citation support failed. In the other direction, the generator might answer 1980 from parameter memory even when the passage was absent. Score evidence retrieval, answer correctness, and claim-level support separately. The small probability exercise compares models under fixed conditional tables; it is not evidence that the higher likelihood model always produces a more truthful answer.

Test the limits and transfer the idea

1. Derivation and calculation · allow 45 minutes

Explain how an answer can train a retriever

Use a fixed two-document candidate set for RAG-Sequence. The retriever probabilities are p(A)=0.8 and p(B)=0.2. For the observed complete answer y, generator likelihoods are L(A)=0.1 and L(B)=0.9. Treat these likelihoods as constants for this calculation. Let retriever scores s feed a softmax, and let the training loss be -log(sum_z p(z)L(z)).

Compute the answer likelihood and posterior document probabilities q(z|y). Derive the loss gradient with respect to each score and predict the direction of a small gradient-descent update. Explain why this signal does not constitute explicit document relevance labels or proof that the selected passage entails the answer. State what the paper keeps fixed during its reported end-to-end fine-tuning.

Get a starting hint

For the log marginal, the score gradient is posterior minus prior. Negating the log reverses that sign.

Compare your reasoning with the worked solution

The marginal likelihood is 0.8×0.1+0.2×0.9=0.26. Bayes normalization gives q(A|y)=0.08/0.26=4/13, about 0.30769, and q(B|y)=9/13, about 0.69231. The answer shifts posterior weight strongly toward B despite A's larger prior retrieval score.

For softmax p_i, the derivative of p_i with respect to score s_j is p_i(delta_ij-p_j). Differentiating the log marginal therefore gives p_j L_j/Z-p_j=q_j-p_j, where Z is the marginal. The negative-log-loss gradient is p_j-q_j. Its values are 0.49231 for A and -0.49231 for B. Gradient descent lowers A's score and raises B's score, to first order, making this observed answer more likely under the fixed likelihood table.

The signal rewards a document for helping the generator explain the target string. A spurious passage, memorized association, or annotation artifact can receive credit without providing sound evidence for the answer. The posterior is not an entailment certificate. The paper fine-tunes the query encoder and generator while keeping the document encoder and index fixed. Our derivation additionally freezes generator likelihoods and candidate membership to isolate the retriever derivative. Changing the retrieved top-k set is a discrete operation; this local derivative is not a derivative through every possible change of candidate set. Nor does one update prove that downstream retrieval improves.

Check your reasoning

  • Computes the marginal and both normalized posteriors.
  • Derives the gradient sign and update direction rather than guessing from prior rank.
  • Distinguishes latent training credit from evidence support and states fixed components.

2. Search counterexample · allow 40 minutes

Find the answer hidden by per-document beams

The paper distinguishes thorough and fast decoding for RAG-Sequence. Construct an original finite example with two equally weighted documents and exactly three possible complete answers X,Y,Z. Under A their probabilities are 0.45,0.40,0.15; under B they are 0.10,0.40,0.50.

Compute the marginal probability of every answer. Suppose each document's search returns only its single most probable complete answer. Which candidates enter the union? Can rescoring that union under both documents recover the true marginal winner? Then use two candidates per document and compare thorough rescoring with the approximation that an answer absent from a document's beam has probability zero. Explain what these results do and do not imply about the paper's practical beam searches.

Get a starting hint

Generating the candidate set and accurately scoring its members are separate approximations.

Compare your reasoning with the worked solution

The marginals are P(X)=0.5×0.45+0.5×0.10=0.275, P(Y)=0.40, and P(Z)=0.325. Y is the true winner even though it is not the top answer under either document. With one candidate per document, A returns X and B returns Z. The union {X,Z} omits Y. Thorough rescoring selects Z at 0.325, but cannot recover a candidate that was never generated.

With two candidates, A returns X,Y and B returns Z,Y, so the union includes all three. Thorough rescoring now finds Y with 0.40. The fast approximation scores X as 0.5×0.45=0.225, discarding its 0.05 contribution from B. It scores Z as 0.5×0.50=0.25, discarding its 0.075 contribution from A. Y remains 0.40 because both beams include it. In this example fast and thorough methods choose the same winner at width two, although their probability estimates differ. Those approximate scores sum to 0.875, not one; they are truncated contributions rather than a complete normalized answer distribution.

These are exact top-candidate lists over an invented three-answer universe. Real token-level beam search can miss even a document's true best complete sequence, adding another approximation. The example establishes a candidate-generation failure and a separate rescoring bias. It does not claim that larger beams always improve task accuracy, that the highest model probability implies factual truth, or that these values reproduce an experimental result from the paper.

Check your reasoning

  • Finds Y as the marginal winner and identifies why width one loses it.
  • Computes thorough and fast width-two scores, including omitted mass.
  • Separates finite-example conclusions from token-search and truth claims.

Check your understanding

Why are the two likelihood formulas different?

  • One replaces conditional token probabilities with unconditional frequencies.
  • One sums passage alternatives outside the whole token product; the other mixes them within each position.
  • Moving a sum through a product preserves the joint likelihood for every passage model.
  • RAG-Sequence assigns equal probability to every retrieved passage.
Explanation

The placement of marginalization changes the latent-document dependency structure.

A correct answer appears although required evidence was not retrieved. What can be concluded?

  • Retrieval recall must be perfect.
  • The citation necessarily supports every claim.
  • The corpus is complete.
  • Answer correctness alone does not establish retrieval success.
Explanation

Parameter memory or guessing can produce a correct answer despite a retrieval miss.

Original paper and sources

Patrick Lewis and coauthors. Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks. Advances in Neural Information Processing Systems, 2020.

Read the original paper →

Read the primary paper: NeurIPS