Skip to content
ML to LLMs
Cheat sheets

RAG pipeline

Every stage of retrieval-augmented generation, its knobs, and its failure modes.

StageKnobsFailure modeCheck
Ingestparsers, cleaning, metadata, permissionsgarbled tables and PDFs, missing textspot-check extracted text
Chunksize, overlap, structure-aware splittinganswer split across chunks; diluted chunksrecall@k by chunk setting
Embed and indexembedding model, sparse index, versioningwrong model, stale index, version mismatchindex freshness, model version in traces
Retrievek, hybrid weighting, metadata filterslow recall, vocabulary mismatch, permission leaksrecall@k, MRR on a labeled set
Rerankcross-encoder, candidate countadded latency; can't fix missing candidatesnDCG@k, latency
Construct contextordering, source labels, token budgettoo much or irrelevant contextcontext relevance
Generate"answer only from sources, cite, say I don't know"ignoring context, unsupported claimsgroundedness, citation correctness
Evaluatetest set, judges, human reviewjudging fluency onlylayer-by-layer metrics

Chunk count: ⌈(N−O)/(S−O)⌉\lceil (N - O)/(S - O)\rceil for NN words, size SS, overlap OO.

Hybrid search: sparse (exact terms, IDs) + dense (paraphrases), fused by weighted scores or reciprocal rank fusion.

Security: filter by permissions at retrieval time; treat retrieved text as untrusted (prompt injection).

Debug order: is the evidence retrieved? → is it in the final context? → is the answer grounded in it?

Lessons: The RAG pipeline · Evaluating LLM systems · Securing AI systems