Skip to content

RAG treats the retrieved passage as a latent variable

A language model that answers from its own weights cannot easily update what it knows or show where an answer came from, even when the answer is right. Lewis et al. add a retriever: for a question x, a dense index returns the top K passages, and a generator conditions on the question and each passage.

The paper treats the retrieved passage z as a latent variable and sums over the top K, weighting each passage by the retriever's probability p(z | x). In RAG-Sequence one passage is used for the whole answer, so the probability of an answer is approximated by the sum, over the top K passages, of p(z | x) times the generator's probability of the entire answer given that passage. In RAG-Token the sum is taken at every output token, so different tokens can lean on different passages.

A small made-up case shows the difference. Two passages get retriever weights 0.7 and 0.3. A two-token answer has generator probabilities 0.5 then 0.4 under the first passage, and 0.1 then 0.9 under the second. RAG-Sequence gives 0.7 × (0.5 × 0.4) + 0.3 × (0.1 × 0.9) = 0.167. RAG-Token gives (0.7 × 0.5 + 0.3 × 0.1) × (0.7 × 0.4 + 0.3 × 0.9) = 0.38 × 0.55 = 0.209.

Did it work? On Natural Questions the paper reports 44.5 exact match for RAG-Sequence. A closed-book T5-large with 770 million parameters scored 28.9. It also reports 11.8% accuracy on questions whose answer appears in no retrieved passage, where an extractive model would score 0%.

Lewis et al., NeurIPS 2020, §2.1, §4.1, and Appendix G