AI Engineering Playbook
RAG

RAG

The most-built system in applied AI — and the one most often described too shallowly.

Prerequisites

Why this section exists

An LLM's weights froze at a training cutoff and never contained your private data. You need it to answer from documents it has never seen, and to show its work. You have two options: change the weights (slow, expensive, bad at facts, no per-user access control) or change the prompt. RAG is the second option, done seriously.

Everyone can say "retrieve documents, put them in the prompt." Everything that actually matters sits one level below that, on a single insight:

The sentence to have ready

Almost every RAG failure is a retrieval failure. If the right chunk never reaches the prompt, no model, no prompt wording, and no amount of temperature tuning can save the answer. So the engineering effort — and the evaluation effort — goes into retrieval quality, not prompt polish.

Everything in this section follows from taking that sentence seriously.

What's in here

PageThe question it answers
The RAG PipelineThe end-to-end picture — this is the "explain RAG" answer
Ingestion & ChunkingParsing real documents, chunking strategies, the size tradeoff, metadata design
Retrieval PatternsQuery rewriting, HyDE, multi-query, parent-child, contextual retrieval
Advanced RAGAgentic RAG and graph RAG — when the extra machinery pays for itself
RAG EvaluationFaithfulness, context precision/recall, golden datasets, LLM-as-judge and its biases
Production RAGFreshness, document lifecycle, per-user ACLs, cost, latency, graceful degradation

Read in that order. Evaluation before production is deliberate: you cannot productionize what you cannot measure, and "we shipped it and it felt better" is not a result.

Where this connects

  • Agents — hand retrieval to the model as a tool and RAG becomes agentic RAG; the loop replaces the fixed pipeline.
  • Security — retrieved content is untrusted input, which makes RAG a prompt-injection surface and a data-leakage surface at once.
  • Design: Enterprise RAG — all of this, assembled into one system with explicit numbers.
Advanced RAG

On this page