How to give an LLM knowledge it wasn’t trained on. RAG (Retrieval-Augmented Generation) retrieves relevant chunks from a knowledge base and pastes them into the prompt before the model answers. This page fills the mechanics the vault previously only had an opinion about: Agent Memory says “skip RAG until you need it” and Diarization calls itself “the synthesis pattern RAG was supposed to deliver.” Both are right that RAG is over-reached for. But when your knowledge base genuinely can’t fit in context, you need to know how retrieval actually works. Source: Anthropic’s Contextual Retrieval.

The first question: do you even need it?

The 200k-token rule

If your knowledge base is smaller than ~200,000 tokens (about 500 pages), don’t build RAG. Put the whole thing in the prompt and use prompt caching (latency down >2x, cost down up to 90% on cached tokens). RAG is a scaling solution, not a default.

This is the load-bearing point and it matches the vault’s existing bias. Most “we need RAG” projects are under 500 pages and should just stuff the context window. Reach for retrieval only when the corpus is too big to fit, or grows unboundedly. See Context Engineering for the broader “what goes in the window” discipline.

How standard RAG works

When the corpus is too large, the standard pipeline is:

  1. Chunk the corpus into small pieces, usually a few hundred tokens each.
  2. Embed each chunk with an embedding model -> a vector that encodes meaning.
  3. Store the vectors in a vector database for semantic-similarity search.
  4. At query time, retrieve the chunks most similar to the question and add them to the prompt.

Two retrieval methods, used together. Embeddings capture meaning but miss exact strings. BM25 (a lexical ranking function built on TF-IDF) catches exact matches: error codes, IDs, technical terms. A query for Error code TS-999 is exactly where embeddings fail and BM25 wins. Production RAG runs both and fuses the ranked results. Embeddings + BM25 beats embeddings alone.

The failure mode: chunks lose their context

Splitting documents destroys context. A chunk reading “The company’s revenue grew by 3% over the previous quarter” doesn’t say which company or which quarter, so it retrieves poorly and answers worse. This is the central weakness of naive RAG.

Contextual Retrieval (Anthropic’s fix)

Before embedding and indexing each chunk, prepend a short chunk-specific context that situates it in the whole document:

original_chunk = "The company's revenue grew by 3% over the previous quarter."

contextualized_chunk = "This chunk is from an SEC filing on ACME corp's
performance in Q2 2023; the previous quarter's revenue was $314 million.
The company's revenue grew by 3% over the previous quarter."

You don’t write these by hand. You have a cheap model (they used Claude 3 Haiku) generate the 50–100 token context per chunk, then embed and BM25-index the contextualized version. With prompt caching the whole document loads once, so the one-time cost is about $1.02 per million document tokens.

The stack, ranked by what actually helps

Anthropic tested every combination. The gains stack:

TechniqueRetrieval failure rate (1 − recall@20)
Embeddings only5.7% (baseline)
+ Contextual Embeddings3.7% (−35%)
+ Contextual BM252.9% (−49%)
+ Reranking1.9% (−67%)

Reranking is the last-mile filter: over-retrieve (they pulled top 150), then a reranking model scores each chunk against the query and you keep only the best (top 20). Fewer, better chunks -> better answers, lower cost, slight added latency.

Practical knobs that matter: chunk size / boundary / overlap; embedding model (Gemini and Voyage tested best); top-K (20 beat 10 and 5); and a domain-tuned contextualizer prompt. And always run evals on your own data (Evaluating AI Agents).

How this fits the vault’s view

The vault is right to be RAG-skeptical, and now it can defend the position precisely:

  • Under 500 pages? No RAG. Context window + caching. (Agent Memory, Context Engineering)
  • Diarization vs RAG: Diarization (model reads everything, writes a structured profile) is the better move when a human-readable synthesis is the goal and the subject fits in context. RAG wins only at scale where no synthesis fits.
  • Retrieval as a tool, not an architecture: in an agent, retrieval is one tool the loop can call (Agent Tools - Design Principles), not the whole system.

A RAG index needs a data contract

Making Your Data Ready for Agentic AI adds the production controls missing from retrieval-quality benchmarks. A vector index is a data product, not a passive cache:

  • Freshness SLA: measure time since the last successful rebuild against source systems, not the last document change. This catches both updated-but-unindexed content and a silently failed indexer.
  • Required metadata: every chunk carries source, version, timestamp and access scope. Reject chunks missing any of them.
  • Quality gate: quarantine empty or truncated chunks, OCR/extraction failures, near-duplicates that distort ranking, and malformed or drifting embeddings before they enter the agent-facing store.
  • Certified boundary: agents query only the certified equivalent of a Gold tier. Raw and partially processed documents remain available for human investigation and lineage, not agent answers.

This changes the failure target. Do not ask the model to notice an obsolete policy after retrieval. Make an uncertified index unavailable so the agent has to say it lacks current data.

Security note

RAG ingests untrusted documents into the model’s context. That is one leg of the lethal trifecta: a malicious chunk is an indirect prompt-injection vector. Treat retrieved content as untrusted input. And keep it outside the authorization path: retrieved prose may inform a proposed action, but only reviewed deterministic preconditions may permit it.