Transformers & Inference 2027-05-10 11 min read

A retrieval miss in a RAG pipeline throws no exception, it just produces a fluent, confident, wrong answer, and Lewis et al.'s original 2020 paper already named the real reason: a language model's parametric memory and a retriever's non-parametric memory are two structurally different kinds of knowledge that fail in different ways, which is exactly why RAGAS splits evaluation into retrieval metrics and generation metrics instead of grading the final answer alone

Lewis et al.'s original RAG paper (NeurIPS 2020): DPR plus BART, parametric and non-parametric memory combined by design, not an ad hoc workaround. The real bi-encoder-versus-cross-encoder tradeoff worked out mathematically, why every serious pipeline retrieves fast and reranks slow instead of picking one. HNSW and IVF as the two real approximate-nearest-neighbor algorithms behind every production vector index. RAGAS's four real metrics, faithfulness, answer relevancy, context precision, context recall, and why splitting them is what lets you tell a retriever bug from a generator bug instead of just a lower score. Real, concrete failure modes: chunking as the upstream bottleneck nothing downstream can fix, index staleness, and why a retrieval miss fails silently instead of throwing an error.

Everything trained so far in this series lives in a model’s weights: pretraining puts general knowledge there, fine-tuning and RLHF shape how that knowledge gets used. None of that touches a real, practical problem: a model’s weights are frozen at whatever data existed when training stopped, can’t cite a source for what they claim, and can’t be updated without a new training run. Retrieval-augmented generation is the real, disclosed answer the field settled on, not as a workaround bolted on after the fact, but as a design that was explicit about the split from its very first paper: a language model’s own knowledge (parametric memory) and a retriever’s access to an external, updatable text collection (non-parametric memory) are two different kinds of memory with two different failure modes, and treating them as one thing is exactly what makes RAG systems hard to debug in practice.

The original idea: two kinds of memory, on purpose

Lewis et al.’s 2020 paper, the one that gave RAG its name, combines a dense passage retriever (DPR) with a BART generator, and its own framing is worth taking literally rather than treating “retrieval-augmented generation” as a generic label for “look things up first.” The retriever encodes a query and every candidate passage into the same vector space and returns the passages whose embeddings are closest to the query’s; the generator then conditions on both the original query and the retrieved passages to produce an answer. The paper’s own stated motivation is direct: knowledge-intensive tasks need access to specific, verifiable facts that a fixed set of model weights either doesn’t contain, has gone stale on, or can’t be checked against a source, and the fix isn’t a bigger model, it’s giving the model an updatable, external place to look things up, exactly the way a person would use a reference book instead of relying purely on memory.

Bi-encoders versus cross-encoders: the tradeoff every pipeline is built around

The single most important architectural fact in retrieval is a real speed-versus-accuracy tradeoff, and almost every design decision downstream exists because of it. A bi-encoder encodes the query and each candidate document separately, into independent vectors, so similarity is just a dot product or cosine similarity computed after the fact:

sim(q,d)=eqedeqed\text{sim}(q, d) = \frac{\mathbf{e}_q \cdot \mathbf{e}_d}{\|\mathbf{e}_q\|\,\|\mathbf{e}_d\|}

Because every document’s embedding can be computed once, offline, and stored, a bi-encoder lets you pre-index an entire collection and search it with fast nearest-neighbor lookup at query time. A cross-encoder instead feeds the query and a candidate document into the model together, as one input, letting every token in the query attend to every token in the document before producing a single relevance score. That joint attention makes cross-encoders measurably more accurate, they can catch subtle relevance signals a pair of independent embeddings simply can’t represent, but it also makes them impossible to pre-index: a relevance score only exists once you have a specific query and a specific document in hand together, meaning scoring NN documents against one query costs NN full forward passes through the model, every time.

That’s the real reason production retrieval is a two-stage pipeline, not a single model: a bi-encoder retrieves a fast, cheap shortlist (say, the top 100 candidates from millions) across the whole collection, and a cross-encoder reranks only that shortlist, spending its expensive, accurate joint attention on a hundred candidates instead of a million. Neither stage alone is the right tool: an all-cross-encoder pipeline doesn’t scale to a large collection, an all-bi-encoder pipeline leaves real accuracy on the table that a reranking pass would have caught.

Indexing at scale: HNSW and IVF, the two real algorithms underneath every vector database

Once you have embeddings, finding the nearest ones to a query vector among millions or billions of candidates is its own real systems problem, exact nearest-neighbor search is O(N)O(N) per query, too slow at scale, so production systems use approximate nearest-neighbor (ANN) search instead, trading a small amount of recall for a large amount of speed.

HNSW (Hierarchical Navigable Small World) builds a multi-layer graph where each vector is a node, with sparser, longer-range connections in the upper layers and denser, short-range connections in the bottom layer. A query starts its search in the sparse top layer, quickly navigates to the right neighborhood, then descends layer by layer, refining, letting it reach a very good approximate answer in roughly logarithmic time relative to collection size instead of scanning everything. IVF (Inverted File Index) takes a different, clustering-based approach: cluster the entire collection ahead of time (typically with k-means), and at query time, only search inside the handful of clusters whose centroids are closest to the query vector, skipping the rest of the collection entirely. HNSW generally gives better recall at a given latency but costs more memory (it’s storing a graph, not just vectors); IVF is more memory-efficient and easier to shard across machines but is more sensitive to how well the clustering matches the query distribution. This isn’t a settled choice, either: FAISS (Meta’s library) implements both, and production vector databases like Pinecone, Weaviate, and Qdrant, along with pgvector for teams that would rather keep vectors inside an existing Postgres deployment than run a separate system, all make real, different tradeoffs between the two.

Chunking: the upstream bottleneck nothing downstream can fix

Before any embedding, index, or reranker runs, a document has to be split into retrievable pieces, chunking, and this step is the real bottleneck of most production RAG systems, not because it’s algorithmically hard, but because every failure it introduces is invisible to everything after it. A chunk boundary that splits a table from its caption, or a definition from the sentence that uses it, produces a fragment that no embedding model can rescue, an embedding is a compressed representation of what’s actually in the chunk, and it cannot represent context the chunk never contained. A reranker can only rerank chunks that were retrieved in the first place; it can’t resurface a chunk the initial retrieval step never returned. And the generator can only answer from what’s in its context; it can’t answer from information a bad chunk boundary silently discarded. The practical implication is that chunking strategy, fixed-size windows with overlap, recursive splitting that respects document structure (headers, paragraphs, code blocks), or semantic chunking that groups sentences by embedding similarity rather than a fixed character count, deserves real engineering attention up front, because a bug introduced at the chunking stage cannot be corrected at any later stage of the pipeline.

RAGAS: why RAG evaluation splits into four metrics, not one

Grading a RAG system’s final answer alone tells you that something is wrong without telling you what. RAGAS (Retrieval-Augmented Generation Assessment) is the real, now-standard framework built specifically to separate that failure into its actual components, four metrics split cleanly across the retriever and the generator:

MetricWhat it actually measuresWhich component it isolates
Context precisionWhat fraction of the retrieved chunks are actually relevantRetriever precision
Context recallWhat fraction of the information needed to answer was actually retrievedRetriever recall
FaithfulnessWhether the generated answer is actually supported by the retrieved contextGenerator, given good context
Answer relevancyWhether the generated answer actually addresses the question askedGenerator, given the question

The reason this decomposition matters in practice, not just as a taxonomy: context recall and faithfulness are answering two completely different questions that a single end-to-end accuracy score conflates. Low context recall with high faithfulness means the retriever is the problem, the model is being honest about context that simply didn’t contain the answer. High context recall with low faithfulness means the opposite, the right information was sitting right there in context and the generator hallucinated past it anyway, the exact model-honesty failure mode this series has already met from a different angle. Debugging a RAG system without this split means guessing whether to fix the retriever or the prompt; debugging with it means the failing metric tells you which one.

Real, concrete failure modes

  • Silent retrieval misses. A bad retrieval doesn’t raise an exception or return an obviously malformed result, it returns something, and a generator conditioned on subtly wrong or incomplete context tends to produce a fluent, confident, plausible-sounding answer anyway, the same silent-failure shape already named in the agents post: the system doesn’t know it failed, and neither, by default, does the user reading the output.
  • Index staleness. An index built once and never refreshed becomes a confident source of outdated information the moment the underlying documents change; unlike a model’s pretraining cutoff, which is at least a known, fixed date, an unmaintained index can silently drift out of sync with its source of truth with no built-in signal that it has.
  • Citation and traceability. One of RAG’s real practical advantages over relying on a fine-tuned model’s parametric knowledge is that a retrieved chunk can be shown to the user as a source, letting a claim be checked against the actual document it came from; a system that discards that traceability (returning only a synthesized answer with no chunk-level attribution) gives up one of the main reasons to use retrieval over fine-tuning at all.
  • Lost in the middle, again. Already derived in this series from the long-context side: a model’s attention over a long context is measurably U-shaped, favoring the beginning and end over the middle. That applies directly to RAG’s own output: stuffing ten retrieved chunks into a prompt doesn’t guarantee the fifth one gets used even if it contains the answer, which is a real argument for reranking retrieved chunks by relevance into the positions a model actually attends to well, not just retrieving the right ones.

When RAG beats fine-tuning, and when it doesn’t

This series already worked out the real cost tradeoff between long context and RAG; the tradeoff against fine-tuning is a different axis entirely, and the honest answer is that they solve different problems rather than compete for the same one. RAG is the right tool when the need is new or changing facts: the underlying knowledge base updates faster than a retraining cycle could keep up with, and a citation back to a real source matters for trust. Fine-tuning is the right tool when the need is new behavior: a different output format, a house style, tool-calling conventions, a domain-specific reasoning pattern, none of which a retrieved passage can teach, because retrieval only ever adds content to context, it doesn’t change how the model processes that content. In practice, real production systems increasingly use both together: fine-tune for behavior and format, retrieve for facts, because neither technique is a substitute for what the other one actually does.

Beyond the baseline architecture above, a few real, named refinements are worth knowing exist, without needing a dedicated deep-dive here: hybrid search (combining dense embedding similarity with sparse keyword methods like BM25, catching exact-match terms, like product codes or names, that embeddings alone sometimes blur past), HyDE (generating a hypothetical answer first and embedding that to search, rather than embedding the question directly, on the theory that an answer’s embedding is closer to a real answer’s embedding than a question’s is), and query rewriting or multi-hop retrieval for questions whose answer isn’t sitting in any single chunk but has to be assembled across several retrieval steps.

Try it yourself

Beginner. Given a query and three candidate documents, explain, step by step, what’s different about how a bi-encoder and a cross-encoder would each compute a relevance score for one (query, document) pair. Which one could you precompute and cache before the query ever arrives?

Intermediate. Design a chunking strategy for a technical PDF containing headers, paragraphs, and tables. Identify one concrete way a naive fixed-size chunker (say, 512 characters with no awareness of structure) could split a table from the sentence introducing it, and describe what a recursive, structure-aware chunker would do differently.

Advanced. Using RAGAS’s four metrics, sketch a debugging decision tree: given a RAG system with low end-to-end accuracy, what’s the first metric you’d check, and for each of the four possible high/low outcomes on context precision and context recall specifically, what does that combination tell you about where the actual bug lives?

What this takes to be frontier-job-ready

Retrieval is treated as core agentic infrastructure at the labs building production systems, not a bolt-on feature. OpenAI’s own posting for agentic post-training states the mandate directly: improving models “across factuality, instruction following, tool/function calling, multi-agent behavior,” naming factuality and tool-calling in the same sentence, which is exactly what a well-built retrieval system is in practice, a tool call whose entire purpose is improving factuality. The architectural fluency this post covers, why retrieval and reranking are separate stages, why a single accuracy number hides which stage actually failed, is the same fluency that mandate assumes rather than teaches from scratch.


The one-sentence version: Lewis et al.’s original RAG paper split a model’s knowledge into parametric memory (the weights) and non-parametric memory (a retriever’s index) on purpose, because the two fail in genuinely different ways, and every real design decision downstream, bi-encoders for fast recall paired with cross-encoders for accurate reranking, HNSW or IVF for approximate search at scale, RAGAS’s four-way split between context precision, context recall, faithfulness, and answer relevancy, exists to keep those two failure modes separable instead of collapsing them into one opaque final-answer score, because a retrieval miss throws no exception, it just produces a fluent, confident, wrong answer, and the only way to catch that is to have already built the evaluation that can tell the difference.