Featured image of post RAG: Why Knowledge Need Not Live in the Weights

RAG: Why Knowledge Need Not Live in the Weights

RAG combines a language model's parametric memory with searchable, updateable external memory. This article explains dense retrieval, latent-document marginalization, modern pipelines, and their failure boundaries.

At 9 a.m., a company raises its reimbursement limit from $3,000 to $5,000. If the answer exists only in model parameters, making the model reliably state the new number may require new data, more training, evaluation, and redeployment. If the answer comes from a searchable policy document, the organization can replace the document and rebuild its index. Both paths make a model “know” something, but their update cost, provenance, and failure modes are fundamentally different.

The important idea in retrieval-augmented generation, or RAG, is not that a chatbot gained a search box. RAG changes where knowledge lives. A language model no longer has to perform both jobs—remembering the world and composing an answer—alone. Relatively stable capabilities can remain in parameters, while facts that change often, belong to a private domain, or require provenance can live outside the model and be fetched when needed.

Today, “RAG” often means “search first, then paste passages into a prompt.” The 2020 paper defined something more specific: documents were latent variables, the retriever and generator were trained together, and probabilities were marginalized across candidate documents. That original design makes it easier to see what later production pipelines simplified and which risks the simplification introduced.

Two Memories, Not Merely a Larger Context Window

The paper calls the BART generator’s weights parametric memory and the Wikipedia text index non-parametric memory. The latter name does not mean that the retriever has no parameters. It means that the knowledge content is stored as readable text rather than compressed into neural-network weights.

Parametric memory is good at retaining language patterns, common associations, and capabilities acquired during training. It is read implicitly on every forward pass, with predictable latency and no external dependency. The cost is that an individual fact is difficult to locate, delete, or rewrite precisely. External memory has the opposite trade-off: people can inspect, add, remove, and permission documents, but the system must retrieve the right passages and the generator must use them correctly.

Figure 1: Parametric memory is written through training; external memory is written by editing and re-indexing; RAG reads both at answer time

RAG is therefore not an infinitely large context window. A context window determines how many tokens the model can see at once. RAG decides which tokens deserve space in that scarce window out of millions of candidates. The index may contain millions of passages, while only the top-k reach the generator. Retrieval performs selection; generation performs synthesis. Their errors must be diagnosed separately.

The Retriever Is a Learned Address Book

The original system uses Dense Passage Retrieval, or DPR. It has two BERT encoders: one maps a question x to a vector q(x), and the other maps a passage z to d(z). Their inner product produces relevance:

$$ p_\eta(z\mid x) \propto \exp\left(d(z)^\top q(x)\right) $$

Think of it as a semantic address book. Lexical retrieval rewards word overlap. Dense retrieval tries to place “Who wrote The Old Man and the Sea?” near a passage containing “Hemingway wrote The Old Man and the Sea,” even when their wording differs. Across several open-domain QA datasets, the DPR paper improved top-20 passage retrieval accuracy by 9–19 absolute percentage points over a strong Lucene-BM25 baseline. That does not mean vectors always beat keywords: in the RAG paper’s own ablation, entity-heavy FEVER claims favored BM25.

Index construction happens offline: split documents, compute each passage vector, then store the vectors in an approximate-nearest-neighbor index. Online, the system encodes only the question and uses maximum inner-product search, or MIPS, to fetch the top-k passages. The paper split a December 2018 Wikipedia dump into about 21 million disjoint 100-word passages and indexed them with FAISS.

Figure 2: The offline path chunks and indexes documents; the online path embeds a query, retrieves top-k passages, and lets the generator combine the question with evidence

Chunking is not a neutral preprocessing detail. Chunks that are too short separate definitions from their conditions and conclusions. Chunks that are too long ask one vector to represent several topics and waste generator context. Tables, code, dates, and heading structure can disappear under naive splitting. Many apparent “model errors” are decided before generation begins because the evidence was damaged or never entered the top-k.

Original RAG Was About Marginalization, Not Concatenation

Let x be the question, z a candidate document, and y the answer-token sequence. The retriever assigns pη(z|x); the generator assigns the probability of an answer given that document, pθ(y|x,z). RAG-Sequence treats one latent document as responsible for the complete answer:

$$ p(y\mid x) \approx \sum_{z\in \mathrm{top}\text{-}k} p_\eta(z\mid x)\,p_\theta(y\mid x,z) $$

The system does not select one winning passage and discard the rest. It considers the answer under each candidate and weights those paths by retrieval probability. A passage that makes the correct answer more likely receives more useful probability mass.

RAG-Token is finer grained. At every generated token, it can reweight the same candidate documents. This helps when an answer must combine evidence from several sources, but decoding and attribution become more complicated. In the paper’s Jeopardy-generation example, different documents dominate tokens belonging to different book titles, while parametric memory completes titles the model already knows.

Training requires question-answer pairs, but no label naming the correct document. The system minimizes answer negative log-likelihood, allowing the answer signal to train both the query encoder and the BART generator. The document encoder and index remain frozen so that the full corpus does not need to be re-embedded after every update. The retriever therefore learns more than generic semantic similarity: it learns which passages help this generation task produce its targets.

This distinction explains the gap between the paper and most current systems. Production RAG usually uses an independently trained embedding model, concatenates top-k passages into an LLM prompt, and does not backpropagate answer loss into the retriever or explicitly marginalize multiple document paths. It inherits the external-memory idea but decomposes an end-to-end probabilistic model into replaceable retrieval, reranking, prompting, and generation services. That is easier to build and works with arbitrary LLMs, but the modules no longer optimize themselves jointly toward one objective.

It Improves the Knowledge Interface, Not Truth Itself

The original results show that external memory can help. In a human evaluation of 452 pairs of Jeopardy generations, annotators judged RAG more factual than plain BART in 42.7% of pairs; they preferred BART’s factuality in only 7.1%, while both were factual in another 17%. These numbers describe one model, dataset, and task, so they are not a universal hallucination-reduction rate. They do demonstrate that retrieved text can fill factual gaps in parametric memory.

Another result is more cautionary. On Natural Questions, RAG answered 11.8% of examples correctly even when none of its retrieved passages contained the answer string. Parametric memory can supply what retrieval omitted; that is the power of hybrid memory. But a system that presents a nearby document as the source of the whole answer can create false attribution. Retrieving a source does not mean every claim in the answer is supported by that source.

Replacing an index is not the same as replacing truth. The paper swaps 2016 and 2018 Wikipedia indexes to show that accessible knowledge can change without retraining. If the newer documents are stale, contradictory, or poisoned, RAG merely delivers the error more efficiently. It creates an updateable interface, not an oracle.

Three Gates, Three Different Ways to Fail

Treating RAG as merely “a vector database plus an LLM” encourages teams to blame every failure on the model. A more useful debugging method follows the data through three gates.

The first gate is corpus and retrieval. Does the answer exist in the corpus? Were permission filters applied before vector search? Did chunking preserve its conditions? Did the right passage reach top-k? This layer needs recall@k, hit-rate, and access-control tests—not a score for writing style.

The second gate is context assembly. Are retrieved passages repetitive, contradictory, or drowned out by low-quality text? Does a reranker put decisive evidence where the model can use it? “Lost in the Middle” shows that long-context models are sensitive to position and often perform worse when relevant information sits in the middle of a long input. Ten more passages can add ten units of noise rather than ten units of help.

The third gate is generation and attribution. Does the model answer only what the evidence supports? Does it stop when evidence is insufficient? Do citations actually entail adjacent claims? Answer correctness, citation completeness, and citation faithfulness are separate measurements. An answer can be right with a wrong citation, or correctly cite evidence and still reason incorrectly.

Figure 3: Final RAG errors can begin in corpus/retrieval, context assembly, or generation/attribution; each layer needs different measurements

The layers also hide one another’s failures. A fluent generator can conceal a retrieval miss. Tuning only against final-answer scores can persuade a team that a larger model will repair a missing corpus. RAG’s real engineering benefit is that it can turn some invisible causes of “why the model said this” into observable intermediate states: what was retrieved, in what order, and which claims cited it. That benefit exists only if the system records and evaluates those states instead of declaring itself grounded as soon as documents enter a prompt.

When Knowledge Belongs Outside the Model

Knowledge is a strong RAG candidate when it changes frequently, belongs to a private organization, requires permission boundaries, needs provenance, or is too large to write into parameters fact by fact. Product manuals, policies, tickets, research papers, and codebases share this property. The decisive feature is not that there is a lot of text; it is that answers must bind to a managed version of knowledge.

There are equally clear cases where RAG should not be the default. If a task depends on a stable skill rather than searchable facts—changing writing style, following a fixed output format, or learning a control policy—fine-tuning or explicit program constraints may be more direct. If strict transactional consistency matters, as with balances, inventory, or authorization, call a structured database or business API rather than convert records into prose and ask a model to infer the result. If the corpus does not contain the answer, increasing top-k only increases noise.

The most reliable mental model is not “an external brain for the LLM.” It is a knowledge read implemented as costly, fallible, auditable I/O. Model parameters still interpret the question, synthesize evidence, and express an answer. The external index supplies replaceable candidate facts. Combining them does not guarantee truth, but it turns “what happens when the world changes?” from a request to retrain the whole model into a system interface that can be designed, updated, and evaluated independently.

References

  1. Lewis et al., Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks, NeurIPS 2020.
  2. Karpukhin et al., Dense Passage Retrieval for Open-Domain Question Answering, EMNLP 2020.
  3. Johnson, Douze, and Jégou, Billion-scale Similarity Search with GPUs, IEEE Transactions on Big Data, 2019.
  4. Guu et al., REALM: Retrieval-Augmented Language Model Pre-Training, ICML 2020.
  5. Liu et al., Lost in the Middle: How Language Models Use Long Contexts, TACL 2024.
  6. Hugging Face, RAG Model Documentation.