Pattern library
Fourteen practical RAG patterns and when to use them
Filter by where the pattern acts. Each card explains the failure it addresses, the main trade-off, and the evidence you should collect before adopting it.
Long-context baseline
BaselineProvide the relevant corpus directly when it fits the model context and latency/cost remain acceptable.
- Best when
- Small or bounded knowledge sets, high need for simplicity, few permission boundaries.
- Watch for
- Distracting context, repeated token cost, stale snapshots and weak corpus-level access controls.
What to measure
Task success, citation quality, latency and cost versus a retrieval baseline. Do not assume a bigger context window makes retrieval unnecessary.
Flat vector RAG
BaselineChunk documents, embed them, retrieve top-k nearest neighbors, then generate from the selected evidence.
- Best when
- Semantic Q&A over a moderately sized corpus with straightforward questions.
- Watch for
- Exact identifiers, chunk ambiguity, weak filters and noisy top-k context.
What to measure
Recall@k of answer-bearing chunks, context precision, answer groundedness, latency and cost.
Metadata filtering & routing
RetrievalConstrain search by tenant, source, product, date, document type, geography or permissions before/alongside semantic retrieval.
- Best when
- The corpus is heterogeneous or access boundaries matter.
- Watch for
- Incorrect metadata extraction, over-filtering and inherited permissions.
What to measure
Filter accuracy, empty-result rate, recall within the filtered corpus and permission violations.
Hybrid retrieval
RetrievalFuse lexical retrieval such as BM25 with dense semantic retrieval so exact terms and conceptual similarity can both contribute.
- Best when
- Queries include names, IDs, acronyms, citations, SKUs or technical terms as well as natural-language concepts.
- Watch for
- Fusion weights and duplicate candidates; tune on real queries.
Current note
Hybrid lexical + semantic retrieval is now a mainstream production pattern. Anthropic’s contextual retrieval recipe explicitly combines BM25 and embeddings before reranking.
Query transformation
RetrievalRewrite, expand, decompose or generate multiple search queries before retrieval.
- Best when
- User language is ambiguous, conversational, multi-part or poorly aligned with corpus terminology.
- Watch for
- Query drift and extra model calls; preserve the user’s original intent.
Variants
Multi-query, decomposition, step-back questions and hypothetical-document-style query expansion are useful variants, but should be evaluated per query class.
Reranking
RetrievalRetrieve a broader candidate set quickly, then use a stronger relevance model to reorder and trim evidence before generation.
- Best when
- First-stage recall is good but too many weak candidates pollute context.
- Watch for
- Added latency and cost, especially with many or long candidates.
Current note
Modern rerankers can score lexical, semantic and semi-structured candidates; keep first-stage retrieval broad enough that the reranker has the right document to promote.
Contextual retrieval
IndexingPrepend chunk-specific context: such as document identity, section, time period or surrounding meaning: before building dense and lexical indexes.
- Best when
- Individual chunks are ambiguous once separated from the document.
- Watch for
- Additional indexing work and the risk of generated context introducing noise.
Evidence
Anthropic reported substantially fewer retrieval failures from contextual embeddings + contextual BM25, with further gains from reranking. Treat those results as vendor experiments and reproduce on your corpus.
Parent-child retrieval
IndexingIndex small child chunks for precise matching, then return a larger parent section or document window for generation.
- Best when
- Small chunks retrieve well but omit definitions, tables, qualifiers or surrounding narrative.
- Watch for
- Overly large parents can reintroduce context noise and token cost.
What to measure
Retrieval recall using children, answer quality using parent context, and context utilization rather than just token volume.
Hierarchical / RAPTOR-style retrieval
IndexingBuild multi-level representations: chunks, clusters and summaries: so retrieval can operate at different levels of abstraction.
- Best when
- Long documents or collections require both detail retrieval and higher-level synthesis.
- Watch for
- Index build cost, update complexity and summary drift in frequently changing corpora.
Research basis
RAPTOR recursively clusters and summarizes chunks into a tree. More recent work continues to explore lower-cost and more update-friendly hierarchical variants.
Multi-vector / late-interaction retrieval
RetrievalRepresent a document with multiple token- or region-level vectors rather than compressing all meaning into one vector.
- Best when
- Fine-grained matching matters and single-vector embeddings miss local evidence.
- Watch for
- Larger indexes and more specialized retrieval infrastructure.
Research basis
ColBERT-style late interaction separates efficient document encoding from fine-grained query-document matching; multimodal descendants apply similar ideas to visually rich documents.
GraphRAG
StructuredExtract entities, relationships and communities, then query graph structure plus source text for local or corpus-level reasoning.
- Best when
- Questions depend on relationships, multi-hop paths, communities, themes or “what connects these things?”
- Watch for
- Expensive indexing, entity/relationship extraction errors and graph maintenance.
Current Microsoft GraphRAG modes
The current project distinguishes Basic search, Local search for entity-centric questions, Global search over community reports, and DRIFT search that combines local exploration with broader community context.
Corrective RAG (CRAG)
AdaptiveEvaluate retrieved evidence and trigger corrective actions: such as alternate search, evidence refinement or fallback: when retrieval is weak.
- Best when
- Retrieval quality varies materially and the system can access alternate knowledge sources.
- Watch for
- Evaluator errors, extra latency and uncontrolled external retrieval.
Research basis
The CRAG paper uses a retrieval evaluator to determine whether corrective retrieval actions should be triggered instead of blindly trusting top-k results.
Self-reflective RAG
AdaptiveMake retrieval conditional and critique evidence or generated output rather than retrieving a fixed number of passages for every question.
- Best when
- Some queries need retrieval, others do not, and evidence relevance varies.
- Watch for
- Reflection can add latency and may itself be wrong; it needs evaluation like any other component.
Research basis
Self-RAG formalized adaptive retrieval and self-reflection rather than indiscriminately adding a fixed top-k context to every generation.
Agentic & multimodal retrieval
AdaptiveLet a policy or agent choose among vector search, SQL, graph, web, document/image retrieval or tools, then iterate when evidence is insufficient.
- Best when
- Queries span heterogeneous systems or need different retrieval strategies and modalities.
- Watch for
- Tool permissions, loops, cost, observability, reproducibility and prompt-injection exposure.
Design rule
Agentic retrieval should be bounded by approved tools, budgets, maximum steps, evidence requirements and fallback behavior. “Agentic” is orchestration, not a substitute for good indexes.