RAG pipeline cheat sheet

The eight stages, what each is for, and the debug checklist that maps a bad answer to one failing stage.

The pipeline

INGEST -> CHUNK -> EMBED -> INDEX          (offline, per document change)
QUERY  -> RETRIEVE -> RERANK -> GENERATE   (online, per question)
StageJobSkipped or broken, you see
IngestPull sources into clean text + metadata; track updates and deletesMissing or stale content: correct answers are impossible for the generator
ChunkSplit into retrievable fact-bundles with context keptFragments that match but cannot answer; answers cut mid-fact
EmbedTurn each chunk into a vector; same model for queriesParaphrased questions retrieve nothing relevant at any k
IndexStore vectors + keywords + metadata for fast filtered searchSlow queries, or filters silently dropping valid rows
QueryRewrite, expand or route the raw question; extract filtersExact constraints ("under 400k") treated as vague similarity
RetrieveTop-k candidates via dense, sparse or hybrid + filtersGold chunk absent from top k: recall@k is the ceiling
RerankRescore candidates reading query + chunk together; keep top nRight chunk retrieved at rank 18, ignored by the generator
GenerateAnswer only from provided chunks, with citations, or say "not found"Fluent inventions; correct chunks present but contradicted

Debug checklist

Run top to bottom; stop at the first "no". Adapted from the seven failure points of Barnett et al.[1]

  1. Is the fact in the corpus at all? No: ingest gap (missing content). Fix ingestion, not prompts.
  2. Is it in one chunk, with enough context to stand alone? No: chunking. Re-chunk or add chunk context.
  3. Do the filters you extracted actually match the row's metadata? No: query/index. Fix filter extraction or metadata.
  4. Is the gold chunk in the retrieved top k? No: retrieval. Try hybrid, raise k, rewrite the query (HyDE).
  5. Is it in the top n after reranking, near the start or end of the prompt? No: rerank/ordering ("lost in the middle").
  6. Does the answer use it, faithfully, with a citation? No: generation. Tighten the grounding instructions; require "not found" over guessing.
  7. Is the answer complete and correctly formatted? No: generation instructions or context precision (too much noise retrieved).
Rule of thumb: measure retrieval before touching prompts. If recall@k is low, no prompt can save the answer.

Stage budgets that usually work

KnobSane startMove when
Chunk size200-500 tokens, plus chunk context lineRecall low and chunks look fragmentary
Retrieve k20-150 candidatesReranker present: raise; no reranker: keep small
Rerank keep n5-20 chunksFaithfulness drops as n grows (noise)
RRF constant k60Rarely; it is deliberately insensitive

Sources: Lewis et al. 2020, Anthropic contextual retrieval, Barnett et al. 2024, Liu et al. 2023. Full list in RESOURCES.md.