00-START-HERE · 01-READING-ROUTES · 02_the_competing_answers_to_the_same_problem · 04_what_the_llm_brings_and_what_it_breaks This chapter gives one repeatable way to turn an underspecified retrieval design prompt into explicit choices, priced trade-offs, and a defensible interview answer.
TL;DR
- Start with five decisions in order: when to retrieve, where to retrieve, what query to issue, how to retrieve, and how to present evidence to the generator.
- Name a design’s maturity by the measured failure it fixes. Naive, advanced, and modular RAG describe graph connectivity, not engineer quality.
- Retrieved knowledge can enter as text, projected embeddings, or parameter updates. Text preserves citation, embeddings save input slots, and parameters trade query cost for update delay.
- Ask for chunk count, peak queries per second, and end-to-end latency before choosing an index. These numbers select the architecture rather than merely tune it.
- Price generation before optimizing search. In the worked sizing example, the idealized retrieval stack uses approximately of a full-answer budget; this does not establish p95.
- Separate candidate depth from presentation depth. Retrieving 50 and presenting 5 can preserve recall without paying generation cost for all 50.
- Treat adaptivity as a measured routing problem. Ship a router only when its accuracy or cost dividend clears its own break-even threshold.
The story
Picture a busy airport control tower that must answer one vague radio call: “Get this passenger to the right destination.” The weak controller starts naming equipment before asking where the passenger is going. The strong controller starts with five decisions. Does this passenger need a connecting flight at all? That is the retrieval gate, meaning the choice to search or answer from the model’s own knowledge. If a connection is needed, which airport should handle it? That is source selection among documentation, tickets, a wiki, or the open web. What should the flight plan say? That is query compression, expansion, rewriting, or decomposition. How should the tower find a route? That is scoring and indexing, meaning the machinery that ranks evidence and makes a corpus searchable. Which passengers and bags should enter the final cabin, and in what order? That is reranking, truncation, serialization, and prompt placement. Rebuilding the airplane is parameter training, not retrieval, so it sits outside the five decisions. The same airport explains maturity and interfaces. Naive RAG is a direct flight. Advanced RAG adds planning before takeoff and inspection before boarding. Modular RAG adds switches and return routes, but every stop adds delay and another failure point. The aircraft also has three loading doors. Text keeps readable passages, projected embeddings save input slots but lose quotable spans, and parameter updates add no context tokens but delay new facts until training. Before assigning a runway, the tower sizes chunk count, rush-hour query rate, and passenger wait time. A small airport scans every option exactly, a larger one needs a graph, and a still larger one compresses or shards. Passengers also differ. Some need no connection, some need one fact, some need several hops, and some carry a spreadsheet. Adaptivity is the dispatcher, whose gain is the gap between segment winners and the best single route. Misroutes give that gain back, so route only after the segment table proves break-even.
Decoder table
| Term | Plain-language decoding | Why it matters here |
|---|---|---|
| Retrieval-Augmented Generation (RAG) | A generator answers with information fetched from an external datastore. | It is the system being designed. |
| Query | The user’s information request or its retrieval-ready transformation. | It is the input to gating, routing, and search. |
| Corpus | The full collection of source material available for indexing. | Its token and chunk count determine architecture. |
| Token | One model input or output unit. | Prefill and decode cost scale with token counts. |
| Prompt | The serialized input given to the generator. | Evidence count and placement change its cost and behavior. |
| Model parameter | One learned numeric value in a model’s weights. | Parameter count drives model compute and adapter size. |
| Index | A data structure that makes a corpus searchable. | Its family determines memory, recall, and operations. |
| Vector database | A service that stores vectors and answers similarity queries. | The source compares it with an in-process exact array. |
| Context window | The maximum input and output token capacity available to a model. | A naive 8,000-token retrieval nearly fills an 8,192-token window. |
| Frequently asked questions (FAQ) | Repeated common questions served by a support system. | The source gives a small single-hop FAQ counterexample. |
| Hyperparameter | A setting chosen outside model training, such as HNSW search breadth. | It adds tuning and retuning work. |
| efConstruction | The HNSW parameter that controls graph construction effort. | It joins M and efSearch in the tuning surface. |
| Streaming | Returning generated tokens before the full answer is complete. | It changes the defended latency from completion time to first token. |
| Network hop | A request crossing from one process or service to another. | A managed vector service adds this dependency. |
| Eventual consistency | A state where replicas or stores may agree only after a delay. | A separate vector service can lag the source of truth. |
| Cache hit rate | The fraction of requests that can reuse cached computation. | Low reuse removes the value of document KV caches. |
| Schema | The required structure of an output. | Stable schema behavior can live in an adapter. |
| Wall-clock latency | Elapsed real time seen by the request. | Small arithmetic work can still take about in the router example. |
| Portable document format (PDF) | The document format in the sizing prompt. | Its layout extraction quality controls token estimates. |
| Millisecond (ms) | One thousandth of a second. | Most latency budgets in the chapter use this unit. |
| Queries per second (QPS) | Request throughput measured each second. | Peak QPS sizes machine bandwidth and replicas. |
| Generator | The model that produces the final answer. | It consumes the query and selected evidence. |
| Retriever | The function that searches a datastore for evidence. | Four of the five decisions shape its use. |
| Datastore | One or more external stores of searchable content. | Choosing among stores can prevent contradiction. |
| Gate | A rule that decides whether retrieval runs for a query. | Retrieval can hurt an answer that was already correct. |
| Closed-book answer | An answer produced without external retrieval. | It is the bypass branch of decision one. |
| Classifier | A model that assigns a query to a decision class. | It can implement retrieval gating or source routing. |
| Confidence threshold | A cutoff on the generator’s estimated certainty. | It is one gate family. |
| Perplexity threshold | A cutoff based on how surprising the generator finds the query or output. | It is another gate family named in the source. |
| Self-reflective retrieval | A scheme in which the model signals that it wants to search. | It makes the gate part of generation. |
| Search token | A generated control token that requests datastore access. | It expresses self-reflective retrieval. |
| Unified Active Retrieval (UAR) | A gate that combines intent, knowledge, time sensitivity, and self-awareness classifiers. | It supplies the worked gate pattern. |
| Large language model (LLM) | The language model used for control or answer generation. | Control calls and final generation have different costs. |
| Hidden state | An internal vector produced by a model layer. | UAR reads hidden states and embedding injection writes into them. |
| Frozen model | A model whose weights are not changed during a training step. | xRAG trains a projector while keeping endpoints frozen. |
| Source router | A controller that selects which datastore to query. | It avoids indiscriminate fan-out. |
| Fan-out | Searching several stores or shards at once. | It can improve recall but increase contradiction and merge work. |
| Contradiction rate | The probability that retrieved evidence conflicts with current truth. | It is the main risk of poor source selection in the worked example. |
| Query transformation | A function that converts the user input into a retrieval query. | It resolves missing context or complex information needs. |
| Compression | Removing irrelevant query content. | It is one query transformation. |
| Expansion | Adding related retrieval terms or context. | It is one query transformation. |
| Rewriting | Restating a query so the retriever can resolve it. | It helps conversational follow-ups. |
| Decomposition | Splitting one request into several sub-queries. | It can recover evidence spread across documents. |
| Scoring function | A rule that assigns relevance scores to query-document pairs. | It determines candidate ranking. |
| Sparse retrieval | Retrieval based on sparse lexical features. | Best Matching 25 and its learned successors are examples. |
| Inverted index | A mapping from terms to documents that contain them. | It makes sparse retrieval searchable. |
| Best Matching 25 (BM25) | The sparse scorer named in the source. | It represents a lexical retrieval family. |
| Sparse Lexical and Expansion model (SPLADE) | A learned sparse retrieval method named in the source. | It is a learned successor to BM25. |
| DeepImpact | A learned sparse retrieval method named in the source. | It is another learned successor to BM25. |
| Dense retrieval | Retrieval based on compact numeric vectors. | It supports single-vector approximate search. |
| Bi-encoder | A model that encodes queries and documents separately. | Separate vectors make large-scale retrieval practical. |
| Dense Passage Retrieval (DPR) | The dense single-vector retriever named in the source. | Its 21 million passage corpus anchors a sizing check. |
| Cross-encoder | A model that scores a query and document jointly. | It gives stronger reranking at a per-pair compute cost. |
| Late interaction | A design that encodes tokens separately, then combines query-document token matches late. | It preserves more detail than one vector per document. |
| Contextualized Late Interaction over Bidirectional Encoder Representations from Transformers (ColBERT) | The source’s multi-vector late-interaction retriever. | Its per-token vectors multiply index size. |
| Maximum similarity (MaxSim) | The ColBERT operation that keeps the strongest token match. | It combines the many token vectors. |
| Candidate depth | The number of items retrieved before reranking, written as k’. | It should be separate from presentation depth. |
| Presentation depth | The number of chunks actually placed in the generator input, written as k. | It drives prefill cost. |
| Reranker | A stage that reorders retrieved candidates with a stronger scorer. | It can preserve recall while shrinking the prompt. |
| Serialization | The format and order used to turn evidence into generator input. | It is part of decision five. |
| Prompt placement | Where evidence and the query appear in the input sequence. | It affects caching and generator behavior. |
| Time to first token | Delay from request arrival to the first generated token. | It is the main latency budget in section 3.1. |
| 95th percentile (p95) | A latency level that 95 percent of requests meet. | The worked service target uses it. |
| Service level objective (SLO) | A committed operating target such as p95 latency. | It constrains retrieval and presentation choices. |
| Floating-point operation (FLOP) | One numerical operation used to estimate model compute. | Prefill, reranking, and control work are priced with it. |
| Tera floating-point operations per second (TFLOP/s) | Trillions of FLOPs completed each second. | It converts model work into time. |
| Giga floating-point operations (GFLOP) | Billions of FLOPs. | It sizes the small routing encoder. |
| Bfloat16 (bf16) | A 16-bit numeric format used for model weights and arithmetic. | The first worked generator and accelerator use it. |
| 16-bit floating point (FP16) | A 16-bit floating-point format. | Later sizing and adaptivity examples use it. |
| 32-bit floating point (FP32) | A 32-bit floating-point format. | Flat vectors use four bytes per dimension. |
| Model FLOP utilization (MFU) | The share of peak arithmetic throughput achieved in practice. | The worked examples assume 40 percent. |
| Prefill | Processing all input tokens before decoding begins. | Retrieved text makes this stage expensive. |
| Decode | Producing output tokens one at a time. | Weight bandwidth often dominates it. |
| Prefix caching | Reusing computation for a shared prompt prefix. | It cannot recover a query placed after changing passages. |
| Graphics processing unit (GPU) | The accelerator running the model. | Daily costs are stated in GPU-hours. |
| A100 | The accelerator model used in the first and third worked examples. | Its throughput and memory anchor the arithmetic. |
| Memory bandwidth | How many bytes an accelerator or machine can move per second. | It bounds decode, scan, and random vector reads. |
| Hierarchical Navigable Small World (HNSW) | A graph-based approximate vector index. | It trades memory, tuning, and approximate recall for faster search. |
| efSearch | An HNSW parameter controlling search breadth. | It affects how many neighbors are touched. |
| M | The HNSW neighbor count per node. | It changes memory and search work. |
| Random-access bandwidth | Effective throughput for scattered memory reads. | It is lower than sequential peak bandwidth in the worked search. |
| Naive RAG | Retrieve, concatenate, then generate. | It is the baseline graph. |
| Advanced RAG | Naive RAG with pre-retrieval and post-retrieval processing. | It fixes measured candidate or augmentation failures. |
| Modular RAG | A library of modules connected as a graph that may branch or loop. | It adds routing and feedback when justified. |
| Retrieval failure | The answer evidence never enters the candidate set. | Later stages cannot recover from it. |
| Generation failure | The evidence is present but the generator reasons incorrectly. | A better retriever does not automatically fix it. |
| Augmentation failure | Evidence is badly ordered, redundant, noisy, or stitched. | It calls for post-retrieval processing. |
| Pre-retrieval slot | Processing before candidate retrieval, such as rewriting. | It repairs a wrong candidate set. |
| Post-retrieval slot | Processing after retrieval, such as reranking or filtering. | It repairs noise, redundancy, and ordering. |
| Control call | An LLM call for rewrite, route, judge, or stop decisions. | Each call adds latency and cost. |
| Intermediate generation | Reasoning text produced inside a retrieval loop. | Loops multiply this work by round count. |
| Recall@k | Whether relevant evidence appears within the first k candidates. | Comparing recall@5 and recall@50 locates ranking failures. |
| Multi-hop query | A question whose evidence spans more than one step or document. | It can justify decomposition or iteration. |
| Agentic design | A module graph that makes control decisions and may loop. | It needs measured value and stage instrumentation. |
| Injection interface | The point where retrieved knowledge enters the generator. | It fixes cost, update speed, and citation properties. |
| Tokenizer | The mapping from text into model input tokens. | Embedding injection bypasses it for documents. |
| Embedding | A numeric vector representing content. | It can index text or enter the generator through a projector. |
| Projector | A learned mapping from retrieval-vector space to generator hidden space. | It fixes modality mismatch. |
| Modality mismatch | A mismatch between the objective and geometry of two representation spaces. | Raw retrieval vectors are not native generator inputs. |
| Alignment data | Training examples that teach a projector how representations should correspond. | They are the expensive part of the projector project. |
| Instruction tuning | Training on examples that map instructions to desired behavior. | xRAG uses it with paraphrase objectives. |
| Attention sink | Concentration of attention on an early sequence position. | It helps explain why one projected state can be readable. |
| xRAG | The embedding-injection method named in the source. | It freezes encoder and generator, then trains the projector. |
| Low-Rank Adaptation (LoRA) | A low-rank matrix update attached to a base model. | File-level removability requires a separate, unmerged adapter. |
| Adapter | A small learned weight delta attached to a model. | It suits stable behavior better than fast-changing facts. |
| Rank | The inner dimension of a low-rank factorization. | It controls adapter parameter count. |
| Retrieval-Augmented Language Model pre-training (REALM) | Joint retrieval-aware pre-training with an external corpus. | REALM still retrieves at inference; it is not pure compilation of the corpus into weights. |
| Span-level citation | Linking an answer claim to exact readable source text. | Projected vectors cannot provide spans. |
| Key-value (KV) cache | Stored attention keys and values for earlier tokens. | Reusing document caches can save recomputation without changing interfaces. |
| Position identifier | The token position carried into attention. | Concatenated caches retain original positions and need correction. |
| Chunk | A retrievable slice of a document. | Chunk length and overlap determine index size. |
| Chunk overlap | Repeated content between adjacent chunks. | It increases the number of indexed vectors. |
| Peak query rate | The busiest queries per second, written as lambda. | It sizes throughput and replicas. |
| End-to-end latency | Total request time from query through answer. | It prevents local search optimization from hiding generation cost. |
| Exact scan | Comparing the query with every eligible vector. | It returns exact neighbors under the chosen metric, not guaranteed semantic evidence recall. |
| Approximate nearest neighbor (ANN) | Search that avoids comparing every vector. | It lowers search work at the cost of approximate recall. |
| Quantization | Compressing vectors into lower-cost codes. | It raises single-node capacity with lossy distances. |
| Product quantization (PQ) | Splitting a vector into subvectors and storing compact centroid codes. | The source uses 96 bytes per vector. |
| Inverted file with product quantization (IVF-PQ) | A coarse partitioned index with product-quantized vectors. | It is the one-node regime above HNSW capacity. |
| Facebook AI Similarity Search (FAISS) | The vector-search library whose HNSW memory formula is cited. | It supplies bytes-per-vector arithmetic. |
| Centroid | A representative vector used by quantization. | Centroid count affects the codebook. |
| Codebook | The stored set of quantization centroids. | It must be retrained when embedding distributions drift. |
| Random-access memory (RAM) | Memory available to hold an index on one node. | A usable budget sets two thresholds. |
| Shard | A partition of an index placed on a separate machine. | Crossing one-node capacity adds routing and merge systems. |
| Replica | Another copy of a service or index. | Peak load can require more copies. |
| Tombstone | A deletion marker retained until rebuild. | It is an HNSW operational cost. |
| Duty cycle | The share of one machine’s capacity used over time. | It shows that the support example fits one process. |
| Peak-to-mean ratio | Peak traffic divided by average traffic. | The worked sizing example assumes 5 times. |
| Per-tenant filtering | Restricting results to one customer’s data. | It can trigger a managed shared index earlier. |
| Mixture | A query stream made of distinct information-need segments. | One average configuration can be wrong for every segment. |
| Segment | A group of queries on which configurations behave similarly. | It forms a row in the payoff matrix. |
| Payoff matrix | Accuracy of each configuration on each segment. | It makes adaptive value computable. |
| Fixed policy | One configuration used for all segments. | It supplies the baseline accuracy Afix. |
| Oracle routing | Always choosing the best configuration for each segment. | It supplies the ceiling A*. |
| Adaptivity dividend | The gap D between oracle accuracy and best fixed accuracy. | It is the most accuracy a router can earn from the current menu. |
| Misroute penalty | Mean accuracy lost when the router chooses the wrong branch. | It determines router break-even. |
| Controller | The router that selects a branch. | Its quality and drift can erase adaptive gains. |
| Abstention | Falling back when router confidence is thin. | It can cap accuracy loss at the best fixed policy. |
| Off-distribution behavior | Behavior on traffic unlike the controller’s training data. | It causes operational pages and routing drift. |
| Parametric-sufficient query | A query the generator can answer from its weights. | Retrieval can disturb it. |
| One-shot RAG | One retrieval and generation pass. | It is the middle configuration in the adaptive menu. |
| Iterative RAG | Several retrieve-and-reason rounds. | It is accurate for some multi-hop queries but expensive. |
| Exact match | A strict answer-accuracy measure. | The opening adaptive system reports 63 percent overall. |
| Reflection token | A learned token signaling search or self-evaluation. | Self-RAG uses distilled reflection tokens. |
| Silver label | A generated supervision label rather than a directly human-authored one. | Adaptive-RAG uses it to train routing. |
| Interleaving Retrieval with Chain-of-Thought (IRCoT) | A style that alternates retrieval with reasoning steps. | Re-reading accumulated context raises loop cost. |
| Table-aware configuration | A branch that preserves row and column structure. | It can raise a weak segment rather than just reroute it. |
| TAPAS | A table-aware model line named in the source. | It represents a missing fourth branch. |
| TableFormer | A table-aware model line named in the source. | It also represents a missing fourth branch. |
| Service level agreement (SLA) | An externally meaningful service commitment. | The adaptive staff prompt treats latency as an SLA. |
Core mechanics
Mathematical conventions
Use decimal storage units, with . Model-forward work is the proxy , not measured latency. The A100 examples assume ; the later H100-style examples separately assume . A byte-stream estimate is an idealized bandwidth budget, not a latency guarantee. These models omit queueing, communication, attention-length effects and other overhead. Per-request arithmetic does not establish a p95 SLO or sustained throughput. Carry unrounded values through calculations, then round the displayed result.
3.1 The five retrieval decisions as an answer skeleton
The formal boundary
Let be user input, the datastore, generator weights, retrieved chunks, and the answer. A simple retrieval-then-generation pipeline is:
The five choices organize the retrieval contract; they are not a mathematical enumeration of every free parameter of a production system. The two-line abstraction also hides ingestion, security, caching, decoding, evaluation and serving policies. Changing generator weights is outside these five retrieval choices, not outside the full design space. The component walk loses because ingest, chunk, embed, index, retrieve, rerank, and generate appear in nearly every design. It cannot express the highest-leverage option, which is not retrieving. In the opening prompt, a candidate has 38 minutes and only “design retrieval for our support assistant.” The weak pattern spends 20 minutes naming six components and makes zero explicit decisions. The staff interviewer has seen the loop 40 times and listens for decision order.
The five decisions
| Decision | What it is | Why it exists | What breaks without it | Stated cost or complexity |
|---|---|---|---|---|
| 1. When | Compute a gate . | Some queries need retrieval and some are harmed by it. | Always retrieving flips roughly 10 percent of otherwise-correct answers to wrong in the cited Mallen et al. (2023) result. | A classifier, generator threshold, or search-token scheme adds control work. |
| 2. Where | Form , then select . | Different stores have different authority and freshness. | Conflicting stores give the generator a contradiction that it may resolve silently. | Routing is cheap in the example, but conflict is not. |
| 3. What | Form by compression, expansion, rewriting, or decomposition. | The literal query may omit conversational referents or hide multiple needs. | The correct evidence never enters the candidate set. | Rewriting can require another model decode. |
| 4. How | Choose scorer , index, and candidate depth . | The system needs a searchable ranking mechanism. | Recall, memory, and reranking cost become accidental. | Sparse, dense, cross-encoder, and late-interaction families have different compute and storage. |
| 5. Present | Order, rerank, truncate to , serialize, and place evidence. | The generator pays for every presented token. | Relevant evidence can be buried, duplicated, or made too expensive to process. | This decision owns and 82 percent of the first worked budget. |
Decision one has three gate families. A query classifier predicts whether search is needed. A generator confidence or perplexity threshold uses the model’s own signal. A self-reflective scheme lets the model emit a search token. Unified Active Retrieval combines four lightweight classifiers over frozen LLM hidden states. They are intent-aware, knowledge-aware, time-sensitive-aware, and self-aware, then joined in one decision tree. Decision four includes BM25, SPLADE, DeepImpact, DPR, joint query-document cross-encoders, and ColBERT. ColBERT stores one vector per token and aggregates token matches with MaxSim. The five items form a decision list, not a control-flow graph. Iterative and agentic systems can re-enter decisions one and three on every hop.
Worked support-assistant budget
The example has chunks of tokens, sustained queries per second, and queries per day. The generator has bf16 parameters. An A100 is the costing unit; its assumed dense peak is and sustained throughput at MFU is . The product target is p95 time to first token. The following is a serial work budget, not evidence that one card meets that throughput or tail target.
- Decision one reads a -token query: , or approximately , budgeted as .
- The final generator also reads the query; the separate gate and final call do not share that work in this layout.
- A measured bypass slice represents queries per day. Avoided right-to-wrong flips would be only under a matched counterfactual outcome model; a global rate alone does not imply avoided errors.
- Decision two reuses gate hidden states and is allocated for its classifier head.
- If each of three ticket chunks independently contradicts current documentation with probability , the probability of at least one such chunk is . Dependence changes this result, and contradictory evidence does not automatically produce a wrong answer.
- Decision three uses a -parameter bf16 rewriter on conversational follow-ups. Streaming its weights at gives a bandwidth proxy, or for decoded tokens, before prefill and other overhead.
- Decision four uses HNSW with and . Assume a separate budget of vector reads; is not a guaranteed number of visited nodes.
- Those reads move at . At an assumed effective random-read rate, this is approximately .
- Reranking pairs of tokens with a -million-parameter cross-encoder uses , or approximately . Search plus reranking is approximately ; allocate in the rounded budget.
- Decision five presents five chunks plus the query: and . The prefill proxy is approximately , budgeted as . The rounded serial budget is , with presentation contributing . Raising presentation depth to gives input tokens and approximately of prefill. Adding the same other-stage allowance gives approximately , or above the target even before queueing. At five chunks, daily prefill consumes approximately GPU-hours and costs at per GPU-hour; at twenty chunks, approximately GPU-hours and . The difference is approximately per day or over days. Crucially, prefill alone at five sustained QPS requires GPU-seconds per second: at least two such cards under this proxy, versus at least six at twenty chunks, before decode and other work. One card therefore cannot sustain the stated load. The peak-only parameter-work bound for tokens is within this dense arithmetic model, not a universal hardware-independent floor.
Practice defaults and deviations
- State “when, where, what, how, present” in about 60 seconds, then ask for corpus size, query rate, and latency. If the prompt pins one decision, name the other four in one sentence.
- Default to gating. Retrieve on every query when attribution is contractually required, because citation rather than accuracy then sets the rule.
- Default to one routed store per query. Fan out when stores are disjoint or a downstream reranker can arbitrate conflicts.
- Budget presentation first. In this example, present 5 after retrieving 50.
- Keep and separate. Without a reranker they collapse to the same value and the index must buy recall.
- Short 100-token chunks allow at the same prefill cost as five 400-token chunks.
3.2 Naive, advanced, and modular RAG as design maturity
Failure class before paradigm name
The opening maturity prompt arrives 25 minutes into a design loop. The bad reflex is to promise a rewriter, reranker, router, and loop because they sound advanced. The source gives a counterexample. Query decomposition and a cross-encoder tripled latency for an internal FAQ bot with single-hop questions and documents, while fixing a failure class the product did not have. Lewis et al. (2020) named the naive two-stage pattern. Retrieve passages, concatenate them, then generate. Gao et al. (2023) organize its failures into three classes.
| Failure class | What it is | Correct repair location | What breaks if misdiagnosed |
|---|---|---|---|
| Retrieval | The correct evidence is absent from candidates. | Before retrieval, through rewrite, expansion, or decomposition. | Every later stage chooses among wrong evidence. |
| Generation | Correct evidence is present, but reasoning fails. | In prompting or generator capability. | A better retriever leaves the failure unchanged. |
| Augmentation | Evidence is noisy, redundant, badly ordered, or stitched. | After retrieval and before generation. | Concatenation repeats or buries facts. |
The source’s generation example asks a model trained through 2023 for total H-1B filing cost in 2026. The correct pages are present, but the model lists base, training, and fraud-prevention fees without summing them. If all components occupy one chunk, a prompt instruction to sum adds zero modules and zero retrieval latency. Decomposition is justified only when the components are spread across documents. Advanced RAG fills a pre-retrieval slot and a post-retrieval slot. Modular RAG turns the modules into a graph that may route, branch, judge, and loop. Naive RAG is already the small module graph . Advanced RAG adds a rewriter and reranker to the same graph. The right design is the least connected graph that closes a measured failure.
Additive and multiplicative latency
Let be retrieval latency, final generation, one control call, reranking, an intermediate generation, and the number of sequential retrieve-reason rounds. The simplified serial budgets are:
Naive to advanced adds only when the unchanged stages really retain their latency. A loop pays for each control, retrieval, rerank and intermediate-generation round before the final answer. Parallel work contributes the maximum branch latency rather than the sum, but only with enough capacity and no additional contention.
Worked maturity budget
The example uses 10 million chunks at 400 tokens behind HNSW. Query embedding is and ANN search is , so retrieval latency is . A cross-encoder scores query-document pairs per second. A control LLM call is , final generation is , and an intermediate generation is . Generator input costs 3 dollars per million tokens. The control model costs dollars per million tokens.
- Naive presents chunks: . Its retrieved input tokens cost at the assumed per million input tokens.
- Advanced decomposes into three subqueries, retrieves for each in parallel, reranks , and keeps five. Assuming the parallel searches still finish in , total latency is .
- The final retrieved input is tokens costing , plus an assumed control allowance. This scoped component is approximately times lower than the naive component; output and other input charges are not included.
- Modular uses two retrieve-reason rounds at each, then final generation: , approximately times naive.
- Ten accumulated chunks cost in the final call's retrieved input alone. This is not the total loop bill: intermediate calls, repeated context, control and output tokens must also be counted. Advanced reduces the final retrieved-input component by for more modeled latency. The loop adds another and doubles that final-context component; its full token bill cannot be inferred from the final context alone. Adding the most modules does not prove that a system is more mature or more accurate.
Practice defaults and deviations
- Ship naive RAG first and call it naive. Add a module only for a measured retrieval, generation, or augmentation failure.
- Compare recall@5 with recall@50. High recall@50 and low recall@5 call for post-retrieval reranking. Low recall@50 calls for pre-retrieval repair or a corpus audit.
- Budget for each full control-model round trip. Under a one-second target, this example already fails because final generation alone is ; no additional sequential control call fits without changing that stage. Overlap and streaming change the metric and must be specified.
- Label a few hundred production queries to measure the multi-hop rate. Below roughly 20 percent, default to advanced RAG. Above that, route only the multi-hop slice through the loop.
- Log candidates, reranked results, and final context separately before adding another module. For a product with a target and a multi-hop slice, routing through and through gives mean latency . This does not establish a two-second p95 SLO. Even with deterministic branch times and no queueing, exceed two seconds and the mixture's p95 is . Define whether the SLO concerns a mean, a percentile, first token or completion before claiming compliance.
3.3 The three injection interfaces
One distribution, three entry points
Let be the query, selected documents, generator weights, hidden width, the retrieval encoder, and a projector. Three schematic injection paths are:
The text interface converts documents into tokens and concatenates them with the query.
The embedding interface projects retrieval vectors into generator hidden states and uses one input slot per document in the worked design.
The parameter interface compiles the corpus into a weight delta before the query arrives.
| Interface | What it is | Why it exists | What breaks without care | Stated cost or complexity |
|---|---|---|---|---|
| Text | Put retrieved text into the input sequence. | It needs no training and preserves readable spans. | Prefill repeats for every query and grows with chunk count and length. | Five 512-token chunks add input tokens and in the example. |
| Embeddings | Project one retrieval vector per document into hidden space. | It compresses input slots by the chunk length. | Raw vectors have the wrong objective, citations vanish, and multi-hop structure can be lost. | A million parameter projector and alignment corpus are required. |
| Parameters | Train a weight delta from the corpus. | It removes retrieved-content tokens from each query. | Fast-changing facts wait for retraining. | Per-query context cost is zero, but every update is a training run. |
Text and embedding arithmetic
Dense-transformer forward work is approximated as 2 FLOPs per parameter per token. For a 7 billion parameter generator, 5 chunks, and 512 tokens per chunk, retrieved prefill is FLOPs. At the assumed A100 sustained rate of , the retrieved-text term takes approximately . This is the document-prefill component, not total request latency. Five projected document vectors use five input slots rather than . Under the same parameter-work proxy, the retrieved-document component falls by . Query tokens, encoder and projector work, search, training, answer decoding and attention effects are outside this ratio; total end-to-end latency need not fall by that factor. A -dimensional fp32 vector has physical storage bits. A -token passage at an assumed four characters per token has about characters. Comparing storage bits with a historical estimate of one bit per character gives the numerical ratio . Float bit count is not a demonstrated usable information capacity, and the source-entropy assumption does not prove that a retrieval embedding preserves the passage. Capacity is therefore not settled by the bit-count comparison. Morris et al. (2023) demonstrate embedding inversion in their tested setting, including sequences around tokens; that does not establish near-exact reconstruction of a -token passage. Longer passages and different encoders require their own fidelity tests. Retrieval vectors are trained for ranking. Generator hidden states are trained for next-token prediction. xRAG, attributed to Cheng et al. (2024), freezes the retrieval encoder and generator, then trains only the projector using paraphrase-style and instruction-tuning objectives. A bias-free linear projector from to dimensions contains parameters, approximately of a B generator. A bias adds more. Parameter count alone does not price alignment-data creation or training. The source notes near-diagonal local attention in the first two layers and concentration on the first position from roughly layer two upward, citing Xiao et al. (2024). This attention-sink behavior makes one hidden-state slot a shape the transformer already reads.
Parameter arithmetic and losses
LoRA, attributed to Hu et al. (2021), represents a matrix update with stored factor values rather than full-matrix values. These are storage counts, not counts of independently editable facts. A separate, unmerged adapter can be removed as a file; arbitrary merged training updates do not retain that guarantee. REALM, attributed to Guu et al. (2020), jointly trains retrieval and generation with access to an external corpus. It still retrieves at inference; it is not evidence that a corpus has been compiled entirely into weights with no serving-time retrieval. The pure parameter-injection expression instead describes a separately trained weight delta, whose update cost and factual retention must be evaluated directly. Embedding injection loses when the product must quote source spans. It also weakens on multi-hop questions in the xRAG evaluation because one vector per document may not preserve cross-document structure. Parameter injection loses when corpus changes happen faster than retraining. Text loses when repeated chunks make prefill dominate the measured budget. Precomputed KV caches are not a fourth interface. They retain the text tokens and citation ability while memoizing computation. Concatenated per-document caches lose cross-document attention and retain original position identifiers, so both need correction.
Worked interface budget
The example uses 10 million chunks, 512 tokens per chunk, 5 retrieved documents, a 7 billion parameter generator with hidden size , a 768-dimensional retrieval encoder, and 1 million queries per day.
- Raw text uses retrieved-content slots, and approximately under the A100 proxy.
- At per GPU-hour, this component costs approximately per query, or for queries.
- Five projected slots use and approximately , costing approximately per million queries for this component.
- A projection has weights. Rank-eight factors store values, a -fold storage reduction for that update.
- Parameter injection adds no retrieved-content input tokens, but still incurs query/answer serving work and training on every refresh.
- A change rate of one document in per hour means changes per hour for this -document scale. It is an argument to price refresh and staleness, not a theorem that every parameter design is invalid.
- The retrieved-slot cost difference is approximately per day or per days, excluding training and the other serving components. The -fold result concerns input-slot arithmetic, not demonstrated reconstruction fidelity. A -token inversion experiment and a proposed -token chunk differ by in source length, but neither a recoverable compression guarantee nor a -fold fidelity gap follows from that comparison.
Practice defaults and deviations
- Default to text because it supports span citation, needs no training, and updates through the index.
- Measure prefill before changing interfaces. Suspicion is not enough.
- Reuse KV caches first when chunks repeat. A low cache-hit rate removes this advantage.
- Reject embedding injection when generated quotes need exact spans. Document-level metadata may be enough only when the generator never quotes.
- Use adapters for stable behavior such as tone, format, and schema, not hourly facts. Re-check the assumed change cadence every quarter.
- Treat a projector as a training project bound to one frozen encoder-generator pair. For customers requiring independently refreshed adapters every hour, a naive one-run-per-customer policy entails training runs per hour. Batching, shared training and update scheduling can change that count, but then tenant isolation and freshness guarantees also need scrutiny. A retrieval datastore with stable behavior adapters is the source's recommended starting point, not an arithmetic impossibility result for all other designs.
3.4 Size the problem before selecting the architecture
The three numbers
The opening design interview lasts 45 minutes. The weak candidate names HNSW, a 768-dimensional bi-encoder, and a top-20 cross-encoder by 90 seconds, then learns at minute 30 that the corpus has only articles. Ask first for chunk count , peak query rate , and end-to-end latency budget . Index family, quantization, shards, replicas, and reranker depth follow from them. Document count alone is misleading. Let document contain tokens, chunk length be , and positive stride be with . For fixed-stride chunks that stay inside each document and retain the final partial chunk, the exact count is:
One million -token tweets give one million chunks when each tweet is kept intact. One million filings of exactly tokens, and give chunks each, hence million chunks. Average lengths alone do not uniquely determine these document-wise ceilings. For extracted plain English text, the source uses roughly four bytes per token as a planning approximation. Characters and bytes differ for non-ASCII text; compressed PDF file size is not extracted-text size. Extraction, tables, OCR, language and tokenizer all affect the conversion.
Bytes per vector and architecture thresholds
At dimension , a flat FP32 vector uses bytes. The scoped HNSW estimate budgets fp32 vectors plus up to four-byte neighbor identifiers in the base layer. At and , this is . It omits upper layers, identifiers outside the links, allocator overhead, metadata and source text; it is not an all-in memory measurement. Product quantization with subvectors and centroids uses one-byte codes per vector, times smaller than the -byte raw payload. An fp32 codebook contains . IVF-PQ also needs identifiers, coarse centroids, inverted lists and other overhead; code bytes alone do not establish node capacity.
| Regime | Derived boundary | What exists there | What breaks on crossing |
|---|---|---|---|
| Flat exact | Up to approximately million vectors in the stated bandwidth budget | Exact top- under the chosen scoring function. | The idealized scan alone exceeds . |
| One-node HNSW | At most approximately million by vector-plus-base-link payload | A payload upper bound, before other memory. | Real capacity is lower once overhead and headroom are included. |
| One-node IVF-PQ | At most approximately million by codes alone | A code-only upper bound. | Identifiers, lists and headroom can force an earlier move. |
| Sharded or disk | When measured one-node memory or throughput is exhausted | Routing, merging or disk access become subsystems. | There is no universal -million-vector transition. |
At sequential bandwidth and a scan allowance, the byte budget is . The raw-vector limit is vectors. This ignores scoring arithmetic, filters, output selection and contention. Exact scan returns exact nearest neighbors under the same metric and tie/filter rules; it does not guarantee semantic evidence recall of one. The corresponding payload-only memory bounds are million HNSW vectors and million PQ codes. Their per-vector budget ratio is . Both are upper bounds before the omitted components, so neither is a hard production sharding threshold. Crossing a threshold changes the index family, recall behavior, build time, training requirements, and operating model. The three sizing numbers take under two minutes to compute. Between the HNSW and IVF-PQ regimes, rebuild time can move from seconds to hours. A 100 times larger-corpus follow-up tests this architecture change. It does not merely tune the same design. An uncompressed ColBERT-style representation with fp32 token vectors of dimensions uses per chunk. This is approximately times the -dimension single-vector payload; million such chunks use . Compression and implementation choices can change this substantially.
Generation-first latency budget
For a B generator at the assumed , parameter prefill work is approximately . A separate batch-one weight-stream model reads at , giving approximately per decoded token. The latter is a bandwidth proxy with no cache traffic or other overhead, not a measured latency or an impossibility bound for batching and quantized implementations. Five -token chunks plus instruction tokens give prefill tokens and approximately . A -token answer contributes approximately under the batch-one weight-bandwidth proxy. Embedding a -token query with a M encoder costs , or approximately of arithmetic. Here assume a separate M cross-encoder: reranking pairs of tokens uses , or approximately . This differs from the M reranker in section 3.1. Adding an assumed ANN allowance gives approximately for retrieval plus reranking, through prefill, and through the modeled full answer. Retrieval is approximately of that full-answer budget. None of these arithmetic sums determines p95. Choose the index for memory and cost unless retrieval dominates. The named exceptions are retrieval-only products, very large , and corpora above the sharding threshold where each query fans out.
Worked support-corpus sizing
The brief has support articles, 3 million queries per month, and an answer target of about 1 second. With exactly tokens per article, the support corpus contains source tokens. At and stride , each article yields four chunks, so . An average alone is insufficient if lengths are heterogeneous. The flat vector payload is . This is approximately of the raw scan budget, before other memory and work. Three million monthly queries are average queries per second over 30 days. A 5 times peak-to-mean ratio gives peak queries per second. One scan reads , giving at the assumed bandwidth. The unrounded peak rate is approximately QPS, for bandwidth duty , or . This leaves bandwidth headroom but does not establish an end-to-end service capacity or tail latency. HNSW vector-plus-base-link payload is . A search is an illustrative measured-or-to-be-benchmarked allowance, not a consequence of that byte count. It introduces , and tuning; deletion and rebuild policies depend on the implementation. Flat search uses the vector payload and the scan proxy. It has no ANN-approximation hyperparameters, but still has scoring, filtering, numerical and implementation choices. Exact top- agreement under that metric is not relevance recall of one. Refresh and deletion work must be priced for either design. Against the assumed HNSW search, flat scan adds , approximately of the HNSW-based full-answer proxy. Flat scan is a reasonable starting point here when its operational simplicity is worth that budget; this is not a general rule for every latency target. The scan-only limit is crossed at vectors. At four chunks per homogeneous article, the first article count above it is , approximately . Shrinking chunks to tokens at stride gives chunks per -token article, hence million vectors: close to, but still below, this idealized limit. The DPR reference has passages. At dimensions, fp32 vector payload is approximately ; vector-plus-HNSW-base-link budget is approximately ; -byte PQ codes use approximately . This is approximately times the support corpus's chunk count. These scoped sizes do not include complete index overhead.
Practice defaults and deviations
- Ask for tokens or text bytes rather than document count unless records are truly homogeneous.
- Default to exact search below a few million vectors. Deviate when approaches one machine.
- At bytes per vector and /s, one million vectors consume a full machine near 65 queries per second.
- In a retrieval-only product, even can be material because search is the whole budget.
- Quantize before sharding. A full-precision rerank of top candidates largely recovers the lossy distance. Deviate when exact filtering or high-churn per-tenant deletion makes codebook retraining costly.
- Budget from decode backward. A -token answer has an approximately batch-one weight-stream proxy under this configuration; benchmark actual decode and distinguish it from other batching or precision choices.
- With streaming, defend time to first token instead. The consistent retrieval-plus-prefill proxy is approximately before first-token and other serving overhead, not .
- Size the reranker with candidate depth and the index with corpus size ; generator presentation depth is a separate budget. Shard-local candidates multiply reranker depth by shard count. One million -dimension fp32 vectors occupy , while their -byte PQ codes occupy before overhead. If—and only if— refers to extracted plain text and an assumed is appropriate, it implies tokens, approximately long-document chunks at effective stride , and approximately of codes. A compressed PDF collection does not by itself establish this token count. The source also flags extraction quality. A PDF corpus is a layout-extraction problem before it is an index problem, so the token estimate inherits extractor quality. For the 800,000-chunk support corpus, a managed vector database adds a network hop, availability dependency, and eventual-consistency window relative to an in-process array. The exception should expire at million chunks, when per-tenant filtering arrives, or when more than one service needs the vectors.
3.5 Adaptivity as the default answer
Mixtures, menus, and ceilings
The opening shipped pipeline uses recursive character chunks of 512 tokens, one embedding model, HNSW, top 5, and a cross-encoder. Overall exact match is 63 percent, yet support users remain unhappy. Traffic separates into four needs. A fifth is parametric-sufficient, and retrieval can disturb it. Half is one fact in one paragraph. The remaining 30 percent is split between multi-hop evidence and tabular or numeric questions. Let segment weights sum to 1. Let be the accuracy of configuration on segment .
The best fixed policy chooses one column for all traffic.
Oracle routing chooses the best cell in every row.
The adaptivity dividend is zero exactly when one configuration is at least as good as every other configuration on each segment with positive weight. Let be the probability of choosing a row-optimal branch, and let be mean accuracy loss conditional on a misroute. Then . The conditional loss depends on the router's actual confusion pattern; a single aggregate route-accuracy value does not determine it. For , beating the best fixed column requires:
The numerator is only the improvement over the already-best compromise. The denominator includes every wrong route, including closed-book handling of a multi-hop query or an expensive loop on a known fact. The source names UAR’s four-criterion tree, Self-RAG’s distilled reflection tokens, and Adaptive-RAG’s silver-label supervision as examples of controller engineering. Always retrieve, rerank, and iterate is a legitimate fallback when is small and no buildable router clears break-even. It still pays the most expensive branch on all traffic and inherits the roughly 10 percent retrieval flip rate on identifiable parametric-sufficient queries.
Worked payoff matrix
| Segment and weight | No retrieval | One-shot RAG | Iterative RAG | Row winner |
|---|---|---|---|---|
| Parametric-sufficient, | No retrieval | |||
| Single-hop factoid, | One-shot RAG | |||
| Multi-hop, | Iterative RAG | |||
| Tabular or numeric, | Iterative RAG | |||
| Fixed-policy accuracy | Best fixed is iterative RAG |
Oracle routing scores 0.660. The dividend is , or accuracy points. The bottom row’s best score is only because none of the three text configurations preserves table structure. A fourth TAPAS or TableFormer-style branch raises that row rather than reallocating existing strengths. This principle applies to all five decisions. Retrieval gating is only the narrow paper usage of “adaptive retrieval.” Source choice, chunk size, hop count, query transformation, and injection interface can also vary by segment.
Worked adaptive latency and break-even
The matrix comes from queries per day, one week of logs, and offline runs of all three configurations. The generator has 7 billion parameters in FP16 and of weights. The separate adaptive example uses weight bandwidth and . Its decode proxy is approximately . For the following payoff calculation, keep explicitly rounded serial branch budgets , and as scenario inputs. These are not benchmarked p95 values.
- Configuration A budgets approximately for the -token question and for a -token answer, giving the rounded branch.
- Configuration B adds an assumed retrieval stack and an rounded allowance for retrieved tokens: .
- Configuration C uses three rounded retrieve-prefill cycles at , plus two -token intermediate steps budgeted at together: .
- The exact FLOP/bandwidth proxies would give slightly different component values; mixing them with these rounded branch totals would create false precision. For illustration, assume the same route accuracy on every segment and uniform choice between the two non-winning branches when a route is wrong. Then the segment losses are , , and . Their weighted conditional mean is . Different confusion matrices produce different losses. Under that misroute model, break-even is , or approximately . The rounded is a planning shorthand, not an exact cutoff or a universal router-quality requirement. Oracle mean latency under those branch budgets is . Relative to fixed iterative RAG, the saving is , or approximately . A serial router would bring the oracle-routed mean to . Real-router latency depends on its full confusion matrix; a mean does not prove a tail-latency SLO. The router is a 110 million parameter encoder over 32 query tokens. Its work is 7 GFLOP, described as microseconds of arithmetic and roughly wall-clock time. A table-aware fourth configuration raising the bottom row from to adds , or points. This beats the 2.9-point ceiling of a perfect router over the original three branches. The iterative-to-one-shot ratio is . Adaptive-RAG, attributed to Jeong et al. (2024), reports a multi-step baseline closer to an order of magnitude slower than a single step. At 5 rounds, iterative latency becomes , or times one-shot. IRCoT-style chains can cost more because they run to a step cap and reread accumulated context each round.
Practice defaults and deviations
- Build a segment table from a few thousand labeled production queries and run every candidate configuration on it.
- Before launch, ship the best fixed pipeline and make the segment table the first post-launch artifact.
- Keep the best fixed column until the router can clear the relevant threshold.
- A weaker router may still buy latency because a wrong cheap route can cost less than always running the expensive route.
- Enlarge the menu before tuning the controller when every branch is weak on one segment.
- State whether routing buys accuracy, latency, or cost. These currencies have different break-even points.
- Abstain into the best fixed column when controller margin is thin. If cost binds and that fallback is expensive, fall back cheap and alert on the accuracy change.
- Monitor route-distribution drift because traffic weights move with product launches. Replacing oracle routing with the best fixed iterative branch loses accuracy percentage points and adds to the scenario mean before router overhead. The source's does not follow from the displayed branch budgets. For a real router, compare measured accuracy and the latency distribution rather than substituting the oracle ceiling.
Diagrams
Figure 3.1
Diagram description and source
flowchart TD
Q["query x"] --> W["1. When: call retrieval at all, gate g(x), 4 ms"]
W --> H["2. Where: pick stores, under 1 ms"]
H --> T["3. What: form query q = Φ(x), 40 ms"]
T --> R["4. How: scorer, index, candidate depth k', 11 ms"]
R --> P["5. Present: order, truncate k' to k, serialize, 260 ms"]
P --> G["y = GENθ(x, c1, ..., ck)"]
W -. "g(x) = 0" .-> C["answer closed book"]
C -.-> G
style P stroke-width:4px
Figure : The five choices organize the simplified contract ; they are not all free parameters of production RAG. The labels use the rounded serial budget. Presentation is of that budget. Throughput and p95 still require separate capacity and latency measurements.
Figure 3.2
Diagram description and source
flowchart LR
subgraph N["Naive"]
NQ["Query"] --> NPRE["pre-retrieval slot: none"] --> NR["Retrieve"] --> NPOST["post-retrieval slot: none"] --> NREAD["Read, LLM"] --> NA["Answer"]
end
subgraph A["Advanced"]
AQ["Query"] --> APRE["Rewrite or decompose"] --> AR["Retrieve"] --> APOST["Rerank or filter"] --> AREAD["Read, LLM"] --> AA["Answer"]
end
subgraph M["Modular"]
MQ["Query"] --> MROUTE["Route or rewrite"] --> MRET["Retrieve vector, web, or graph"] --> MRERANK["Rerank or filter"] --> MREAD["Read, LLM"] --> MA["Answer"]
MREAD --> MJ["Judge: enough evidence?"]
MJ -- "no: loop" --> MROUTE
end
Figure : Advanced RAG is naive RAG with two empty slots filled. Modular RAG is those same slots plus routing and a feedback edge - the three names describe connectivity, not quality.
Figure 3.3
Diagram description and source
flowchart LR
TX["TEXT: retrieved chunk, c = 512 tokens"] --> TC["concatenate, kc = 2,560 tokens"]
TC -- "287 ms prefill, spans quotable" --> INPUT["frozen generator input sequence"]
EM["EMBEDDINGS: retrieved chunk, c = 512 tokens"] --> EP["encoder to 768 dimensions, projector to 4,096 dimensions"]
EP -. "5 slots, 0.56 ms, nothing to quote" .-> INPUT
PA["PARAMETERS: document set, offline"] --> PT["train weight delta, rank r"]
PT -. "0 tokens, changing means retraining" .-> WEIGHTS["frozen generator weight matrices W"]
INPUT --- WEIGHTS
Figure : Text and projected embeddings enter the input sequence; a separate adapter changes weights. The shown document-only prefill proxies are approximately versus . Their -fold slot-work ratio does not establish matching fidelity or a -fold total speedup. Zero retrieved tokens in the parameter path does not mean zero query or training cost.
Figure 3.4
Diagram description and source
flowchart BT
F["Exact scan: about 3.255M raw vectors within the assumed 50 ms bandwidth budget"] --> H["HNSW: about 19.23M vector-plus-base-link payload upper bound in 64 GB"]
H --> I["PQ: about 666.67M codes-only upper bound in 64 GB; real capacity lower"]
I --> S["Shard or use disk when actual memory, throughput, isolation or availability requires it"]
SUP["Support example: 800,000 document-bounded chunks"] -.-> F
DPRM["DPR: about 21.02M passages"] -.-> I
Figure : The illustrative limits are , and under the stated inputs. The latter two omit material index overhead, and exact neighbors do not imply semantic recall of one. Use document-wise chunk counts and measured workload constraints before choosing a regime.
Figure 3.5
A. Which configuration wins each segment
| Segment and weight | A. No retrieval | B. One-shot RAG | C. Iterative RAG |
|---|---|---|---|
| Parametric-sufficient, pi = | |||
| Single-hop factoid, pi = | |||
| Multi-hop, pi = | |||
| Tabular or numeric, pi = | |||
| Fixed-policy accuracy |
Oracle routing is 0.660. The dividend is 0.029.
B. What the router must achieve before it is worth having
Diagram description and source
flowchart LR
LOW["Below 84.62% row-winner accuracy under the stated uniform-misroute model"] --> BREAK["Break-even: realized accuracy 0.631"]
BREAK --> ORACLE["Perfect row-winner routing: accuracy 0.660"]
Figure : The menu's oracle dividend is , or percentage points. With conditional misroute loss under the stated uniform-error model, . Other confusion patterns and menu changes require recomputing the threshold.
Whiteboard pack
Numbered drawing order
- Write the retrieval and generation contract.
- Draw five boxes: When, Where, What, How, Present.
- Add the closed-book bypass.
- Label the first example's rounded serial allowances .
- Mark presentation's approximately share, then separately check QPS capacity and p95.
- Draw naive, advanced and looped pipelines.
- Add text, projected-vector and separate-adapter entry paths.
- Write the scoped limits: approximately million raw scan vectors, million HNSW payload rows, and million PQ codes; overhead lowers real capacity.
- Finish with the payoff matrix and model-dependent router threshold .
90-100 word script
I start with five decisions: when to retrieve, where to search, what query to issue, how to rank candidates, and what evidence to present. The last decision often owns the latency because generation pays for every presented token. I name the least connected graph that fixes a measured failure, then choose text, embeddings, or parameters based on citation and update needs. Before selecting an index, I ask for chunk count, peak traffic, and latency. Finally, I segment the workload and route only when the measured dividend exceeds the controller’s misroute penalty.
Interview traps
1. “Why not begin with the standard ingest, chunk, embed, index, retrieve, rerank pipeline?”
That walk lists components shared by almost every design, so it does not expose choices. It also has no place for “do not retrieve,” even though retrieval can flip roughly 10 percent of otherwise-correct answers.
2. “Why not call every serious production system modular RAG?”
Modular describes connectivity rather than quality. A loop multiplies control, retrieval, reranking, and intermediate-generation cost by the round count, so use the least connected graph that fixes a measured failure and instrument each added stage.
3. “Would a single vector per document solve prefill latency?”
It can reduce document input slots by the chunk length, 512 times in the example, but it requires a trained projector and removes quotable spans. Default to text and try KV-cache reuse first unless measured prefill dominates and product requirements allow document-level rather than span-level attribution.
4. “The corpus has 200,000 articles. Why not use HNSW immediately?”
Article count is not chunk count. Under the homogeneous fixed-stride scenario, raw vectors use and an idealized scan takes . Against the assumed HNSW search, the difference is , about of the modeled full answer. Exact-neighbor agreement is not perfect evidence recall, and actual latency needs benchmarking.
5. “Is adaptive routing always better than one fixed pipeline?”
No. The original menu's oracle dividend is percentage points. Under equal per-segment route accuracy and uniform selection of wrong branches, mean conditional misroute loss is and break-even route accuracy is approximately . A different confusion matrix changes it. A table-aware branch that improves the bottom segment by adds , or points, to the oracle menu ceiling before routing errors.
Key numbers
Decision skeleton and support budget
| Number | Meaning and committed trade-off |
|---|---|
| 38 minutes | Time available in the opening design prompt. |
| 40 loops | Number of similar loops the staff interviewer has run. |
| 20 minutes, 6 components, 0 decisions | The weak component-first pattern. |
| Roughly 10 percent | Correct closed-book answers flipped wrong by retrieval in the cited measurement. |
| 5 decisions | When, where, what, how, and present. |
| 10 million chunks | Worked support corpus size. |
| 400 tokens | Worked chunk length. |
| 5 queries per second | Sustained traffic. |
| queries per day | Daily traffic at 5 queries per second. |
| 8 billion parameters | Worked generator size. |
| A100 memory capacity. | |
| p95 | Time-to-first-token objective. |
| 312 TFLOP/s | Published dense bf16 arithmetic peak. |
| /s | A100 memory bandwidth used in the examples. |
| and | Assumed MFU and sustained arithmetic throughput. |
| 30 tokens | Gate input length. |
| FLOPs, , rounded to | Gate work and budget. |
| 35 percent and per day | Traffic that needs no store lookup. |
| Not established by the stated counts | Avoided flips require the bypass slice's conditional correctness and harm rates. |
| Under | Marginal source-router cost. |
| , three chunks, | At least one contradictory chunk only under the independent-chunk assumption. |
| 1 billion parameters and 40 output tokens | Conversational rewrite model and output length. |
| , per token, | Rewriter weight size and bandwidth-bound latency. |
| M = 32 and efSearch = 128 | HNSW settings. |
| assumed vector reads | Illustrative search-work budget, not a guarantee from efSearch times the base-layer degree. |
| 768 dimensions and bytes | FP32 vector size. |
| , /s, | Scattered search traffic, effective bandwidth, and latency. |
| 50 candidates | Candidate depth before reranking. |
| 22 million parameters and 430 tokens | Cross-encoder size and pair length. |
| FLOPs and | Reranking work and latency. |
| Search plus reranking. | |
| 5 chunks and tokens | Presentation depth and resulting input length. |
| FLOPs and | Presentation prefill work and latency. |
| and 82 percent | Total time and presentation share. |
| 20 chunks, , | Deeper presentation and resulting prefill and request time. |
| 36 percent | Amount over the target at 20 chunks. |
| Decisions one through four at the deeper presentation setting. | |
| and GPU-hours per day | Prefill use at 5 and 20 chunks. |
| 2 dollars per hour | A100 rental assumption. |
| and per day | Incremental prefill proxy, not the complete serving bill. |
| per day and approximately per year | Difference of unrounded prefill costs, over 365 days. |
| tokens per second | Theoretical prefill ceiling at peak throughput. |
| tokens and | Deep prompt size and hard prefill floor. |
| 60 seconds | Recommended time for the initial five-decision skeleton. |
| About 15 percent | Retrieval share that would falsify the senior latency prediction in the source prompt. |
| Extra prefill caused by raising presentation depth from 5 to 20. | |
| 100-token chunks | Chunk length that allows 20 chunks at the five-by-400-token prefill cost. |
Design maturity
| Number | Meaning and committed trade-off |
|---|---|
| 25 minutes | Point when the maturity challenge arrives in the opening scene. |
| documents and 3 times latency | FAQ example where advanced machinery fixed no measured need. |
| 3 failure classes | Retrieval, generation, and augmentation. |
| Through 2023 and in 2026 | Training horizon and target year in the filing-fee reasoning example. |
| 10 million chunks and 400 tokens | Maturity worked corpus. |
| plus equals | Embedding, ANN search, and retrieval latency. |
| pairs per second | Cross-encoder throughput. |
| , , | Control call, final generation, and intermediate generation. |
| 3 dollars and dollars per million tokens | Generator and control-model prices. |
| 20 chunks, tokens, | Naive prompt and latency. |
| dollars | Naive cost per query. |
| 3 sub-queries, 60 candidates, 5 kept | Advanced retrieval and reranking shape. |
| and | Rerank time and advanced total latency. |
| times | Advanced latency relative to naive. |
| tokens, dollars, dollars | Advanced prompt and component costs. |
| dollars and times cheaper | Advanced total cost and saving relative to naive. |
| 2 rounds, each, total | Modular loop. |
| times | Modular latency relative to naive. |
| chunks, tokens, | Final accumulated retrieved-input component only, not the complete loop bill. |
| 75 percent and | Advanced token reduction and latency tax. |
| Additional latency from advanced to the loop. | |
| , , 192 tokens | Context window, retrieved context, and space left for everything else. |
| tokens and dollars | Tokens removed and per-query saving. |
| Recall@5 and recall@50 | Diagnostic depths for ranking versus candidate failure. |
| target, already missed by final generation | No sequential control call fits without changing the existing budget. |
| A few hundred and roughly 20 percent | Production labels for the multi-hop check and its routing threshold. |
| , , mean | The deterministic mixture still has p95 , not below two seconds. |
| 2 second SLO | Product latency constraint in the staff prompt. |
Injection interfaces
| Number | Meaning and committed trade-off |
|---|---|
| 5 chunks and 512 tokens | Text-interface example. |
| slots versus 5 slots | Text and embedding input sizes. |
| times | Retrieved-document input-slot work ratio, not total latency or fidelity. |
| 7 billion parameters | Generator size. |
| FLOPs and | Raw-text prefill. |
| 768 dimensions and bits | Retrieval-vector capacity. |
| Roughly characters and 1 bit per character | Source’s passage information estimate. |
| times, numerically | Physical float bits divided by a historical passage-entropy estimate; not usable information headroom. |
| 768 by equals | Projector shape and parameter count. |
| million and percent | Projector size and share of the generator. |
| First 2 layers and roughly layer 2 upward | Attention behavior described in the source. |
| 10 million chunks and 1 million queries per day | Worked scale. |
| 2 dollars per hour and dollars per second | GPU price conversion. |
| per query and per day | Document-prefill proxy for one million daily queries. |
| FLOPs, , dollars per day | Embedding prefill work, latency, and cost. |
| by equals | Attention projection size. |
| Rank 8, values, 256 times fewer | Adapter example. |
| 1 in per hour | Change rate that disqualifies parameter storage. |
| per day and approximately per days | Document-prefill gap before other serving and training costs. |
| versus source tokens, a -fold length difference | Inversion experiment length does not establish a recoverable compression or fidelity ratio. |
| Six months, every quarter, 400 customers, 400 runs per hour | Silent-interface-constraint warning, cadence recheck, and adapter update burden. |
Sizing and index selection
| Number | Meaning and committed trade-off |
|---|---|
| 45 minutes, 90 seconds, minute 30, under 2 minutes | Interview duration, premature design point, late sizing reveal, and sizing arithmetic time. |
| articles | Small opening corpus. |
| 3 required numbers | Chunk count, peak query rate, and latency. |
| 1 million tweets and 30 tokens | Small-document example yielding 1 million chunks. |
| 1 million filings, tokens, 400-token chunks, 25 percent overlap | Large-document example. |
| chunks and 167 times | Filing chunk count and growth over tweets. |
| 4 characters per token | English conversion used for text bytes. |
| 768 dimensions, bytes | Flat FP32 vector. |
| M = 32 and bytes | HNSW memory per vector. |
| m = 96, 256 centroids, 96 bytes | Product-quantized vector. |
| 32 times and bytes | PQ compression and total codebook size. |
| /s, , | Exact-scan bandwidth, budget, and scan capacity. |
| Approximately million raw vectors | Idealized scan-only bandwidth limit. |
| and approximately million | Vector-plus-HNSW-base-link payload upper bound, not all-in node capacity. |
| Approximately million PQ codes | Code-only memory upper bound; actual complete index capacity is lower. |
| 34 times source-stated, about times derived, 100 times, seconds to hours | Quantized headroom, changed-corpus follow-up, and rebuild regime shift. |
| 128 dimensions, 400 token vectors, bytes | ColBERT chunk footprint. |
| 67 times and | ColBERT blow-up and size for 3 million chunks. |
| FLOP/s and per token | Prefill throughput and unit latency. |
| , /s, per token | Decode weight size, bandwidth, and latency. |
| 5 chunks, 400 tokens, 200 instruction tokens | Generator input shape. |
| tokens and approximately | Parameter-prefill proxy. |
| output tokens and approximately | Batch-one weight-stream proxy, not measured latency. |
| 32 tokens, 110 million parameters, GFLOP, | Query embedding. |
| 20 pairs, 432 tokens, TFLOP, | Cross-encoder rerank. |
| ANN allowance; stack; full answer | Retrieval is approximately of this idealized full-answer budget. |
| tokens per article and tokens | Worked support corpus content. |
| chunks and | Worked flat index. |
| 3 million per month, average QPS, 5 times, peak QPS | Traffic conversion. |
| , per second, 7 percent | Exact scan latency and duty cycle. |
| and roughly | HNSW footprint and search. |
| 3 hyperparameters | M, efConstruction, and efSearch. |
| and percent | HNSW saving and request share. |
| homogeneous articles | First four-chunk article count above the unrounded scan limit. |
| -token chunks and million vectors | At stride , approaches but does not exceed the stated scan-only threshold. |
| passages | DPR reference size. |
| , , | DPR vector, vector-plus-base-link and PQ-code payload budgets. |
| 26 times | DPR size relative to the support corpus. |
| 65 QPS per million vectors | Approximate full-bandwidth trigger. |
| Approximately | Consistent retrieval-plus-prefill proxy; not a p95 measurement. |
| and | One million vectors flat and quantized. |
| extracted text, tokens, approximately chunks, codes | Conditional on extracted-text size and the stated byte/token and long-document assumptions; not inferable from PDF file size. |
Adaptivity
| Number | Meaning and committed trade-off |
|---|---|
| 512 tokens and top 5 | Shipped fixed pipeline settings. |
| 63 percent | Overall exact match before segmentation. |
| , , , | Segment weights. |
| , , | Parametric-sufficient row. |
| , , | Single-hop row. |
| , , | Multi-hop row. |
| , , | Tabular or numeric row. |
| , , | Fixed-policy column accuracies. |
| and | Oracle accuracy and adaptive dividend. |
| Roughly 10 percent and 100 percent | Retrieval flip rate and traffic share paid by an always-maximal pipeline. |
| queries per day, 1 week, and 1 quarter | Worked traffic, labeling window, and router-versus-menu decision horizon. |
| 7 billion parameters and | Adaptive generator. |
| 200 question tokens, , 60 output tokens, , | No-retrieval path. |
| , , , | One-shot embedding, ANN, reranking, and retrieval subtotal. |
| 5 chunks, 400 tokens, tokens, , | One-shot context and total. |
| 3 rounds, each, 2 reasoning steps, 30 tokens each | Iterative structure. |
| Three-round iterative total. | |
| , , , | Row-wise misroute penalties. |
| and approximately | Conditional misroute loss and break-even under uniform wrong-branch selection and equal route accuracy by segment. |
| and approximately | Oracle mean and reduction before router overhead; not a tail-latency guarantee. |
| 110 million parameters, 32 tokens, 7 GFLOP, roughly | Router size and cost. |
| to , , points | Table-aware branch improvement. |
| points | Perfect-router ceiling with the original menu. |
| times | Three-round iterative to one-shot ratio. |
| 5 rounds, , times | Deeper iterative path. |
| Mean-latency gap from oracle routing to fixed iterative under the displayed branch budgets. |
00-START-HERE · 01-READING-ROUTES · 02_the_competing_answers_to_the_same_problem · 04_what_the_llm_brings_and_what_it_breaks