ai-rag-patterns — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited ai-rag-patterns (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
Production RAG in 2026 is no longer "embed, retrieve top-5, generate." Three measurable shifts changed the playbook: hybrid retrieval beating either BM25 or dense alone, reranking moving from optional to default, and Anthropic's Contextual Retrieval (September 2024) collapsing retrieval-failure rates dramatically. This skill encodes the patterns that actually move the metrics, with cited numbers and the failure modes they address.
Use this skill when designing a new RAG pipeline, diagnosing why an existing one underperforms, or evaluating retrieval quality before generation. Skip it for a small, stable corpus (under ~200K tokens) where putting everything in a cached prompt is the cheaper answer — see §6.
A RAG pipeline is a chain of probabilistic filters: chunking decides what units the system can return, indexing decides what's searchable, retrieval ranks candidates, reranking re-orders them, and generation consumes the result. The output is bounded by the weakest link. The seven failure modes (Barnett et al., arXiv:2401.05856) map cleanly: missing content, top-ranked-missed, not-in-context, not-extracted, wrong format, incorrect specificity, incomplete. Diagnose at the layer that owns the failure; tuning generation when retrieval is the bottleneck is wasted effort.
Two compounding levers move 2026 production RAG most: contextual chunking (adding LLM-generated chunk context before indexing) and hybrid retrieval with reranking. The numbers in §1–§3 below are from Anthropic's Contextual Retrieval write-up and the Elastic / TOIS hybrid-retrieval studies.
| Strategy | When to use | Source |
|---|---|---|
Fixed-size / recursive (LangChain RecursiveCharacterTextSplitter) | Baseline; works for prose with stable structure | Practitioner default; no canonical paper |
Semantic (LlamaIndex SemanticSplitterNodeParser) | Mixed-topic documents where boundaries matter | Practitioner pattern; Greg Kamradt "5 levels of chunking" |
| Late Chunking (Jina AI, Sep 2024) | Long documents with rich context; uses 8192-token embedding model, mean-pools after the transformer at chunk boundaries | arXiv:2409.04701 |
| Anthropic Contextual Retrieval | Production RAG where retrieval quality matters and cost permits ~$1.02 per million doc tokens to pre-process | Anthropic blog, Sep 2024 |
| Parent-document / small-to-big | Index small for precision, return parent for context | LangChain ParentDocumentRetriever, LlamaIndex AutoMergingRetriever |
Anthropic Contextual Retrieval numbers (from a baseline top-20 retrieval-failure rate of 5.7%):
The headline 67% requires reranking on top — it is not the chunking technique alone.
| Method | Strength | Weakness |
|---|---|---|
| BM25 (lexical) | Exact term match, no embedding cost, captures rare terms | Misses paraphrase, synonyms, semantic relationships |
| Dense vector (any modern embedder) | Captures paraphrase and semantic similarity | Weak on rare terms, exact codes, proper nouns |
| Hybrid (BM25 + dense, reciprocal rank fusion) | Combines both signals; outperforms either alone on most production corpora | More moving parts, two indices to maintain |
| ColBERT / late interaction | Token-level matching; strong for queries needing exact-phrase grounding | More expensive than dense |
Hybrid numbers — Elastic Search Labs reports reciprocal rank fusion at +18% NDCG@10 over BM25 alone and +1.4% over ELSER alone on the BEIR benchmark (Elastic — hybrid retrieval). ACM TOIS (Bruch et al., 2023, doi:10.1145/3596512) shows convex combination at α≈0.5 reaches Recall@5 = 0.726 vs RRF k=60 at 0.695 — tuned weighting beats RRF given ~40 labeled query-result pairs to fit α.
Reciprocal Rank Fusion — Cormack, Clarke, Büttcher, SIGIR 2009 (canonical paper). The formula combines ranks across retrievers: RRF_score(d) = Σ 1 / (k + rank_i(d)), default k=60.
ColBERTv2 — Santhanam et al., NAACL 2022. jina-colbert-v2 reports +6.5% nDCG@10 over ColBERTv2; jina-reranker-v3 reports 61.85 nDCG@10 on BEIR, +4.79% over v2 (arXiv:2509.25085).
| Technique | What it does | Source |
|---|---|---|
| HyDE | LLM generates a hypothetical answer document, embeds that for retrieval | arXiv:2212.10496, Gao et al. Dec 2022 |
| Multi-query | LLM rewrites the query into N variations; retrieve for each; merge | LangChain MultiQueryRetriever |
| Decomposition / least-to-most | Break a complex question into sub-questions; retrieve and answer each | arXiv:2205.10625, Zhou et al. May 2022 |
| Query routing | LLM picks which retriever / index / corpus to use | LlamaIndex RouterQueryEngine; agentic-RAG survey arXiv:2501.09136 |
Query rewriting is most impactful when user queries are short or ambiguous (chat agents, voice agents). For well-formed search queries, the lift is marginal.
Reranking is the second filter: take 50–100 candidates from first-stage retrieval, score with a more expensive model, return top 3–10.
| Reranker | Source |
|---|---|
| Cohere Rerank 3.5 / Rerank 4 (Pro, Fast; Apr 2026) | Cohere Rerank docs — billed per search (1 query + up to 100 docs); check current pricing |
Cross-encoders (sentence-transformers/ms-marco-MiniLM-L-6-v2) | Reimers & Gurevych, EMNLP 2019 |
BGE-Reranker (bge-reranker-v2-m3) | Xiao et al., BAAI, arXiv:2309.07597 |
| ColBERT as reranker | Late-interaction over first-stage top-k |
Anthropic's Contextual Retrieval write-up reports reranking adds ~18% relative failure-rate reduction on top of hybrid Contextual Retrieval. No single canonical "typical lift" exists — it depends on first-stage noise level. Vendor blogs cite "20–35% RAG accuracy lift" and "NDCG@5 +18 points" — these are vendor-reported, not peer-reviewed, so treat as ballpark.
Three frameworks dominate; use one as primary, cross-check with another.
| Framework | Metrics | Source |
|---|---|---|
| RAGAS | Faithfulness, answer relevancy, context precision, context recall, context entity recall | Es et al., EACL 2024, arXiv:2309.15217; RAGAS metrics docs |
| TruLens RAG Triad | Context relevance, groundedness, answer relevance | trulens.org RAG Triad |
| DeepEval | G-Eval, HallucinationMetric, ContextualPrecision/Recall/Relevancy | DeepEval LLM evals; G-Eval based on Liu et al., EMNLP 2023, arXiv:2303.16634 |
RAGAS scores — original paper reports human-agreement 95% / 78% / 70% on faithfulness / answer relevance / context relevance. Production threshold: >0.8 on faithfulness and context precision is strong; depends on domain.
Recommended flow (practitioner consensus, not a single citation):
Cross-check with the eval-design skill in the same domain for statistical-significance methodology and judge selection.
2026 frontier models take very long inputs (the Claude 5 family at 1M tokens; Gemini Pro and OpenAI price prompts above 200K and 272K tokens at a higher tier). The question: does long-context generation replace RAG?
Practitioner consensus (no single citation): retrieve a wide shortlist, then let a long-context model reason over it. Pure long-context loses on cost, citation auditability, and freshness for large or changing corpora; pure short-RAG loses on multi-step reasoning across distant passages. Decide by corpus size, refresh rate, citation requirements, and budget.
| Technique | Use case | Source |
|---|---|---|
| ColPali | Document images, PDFs with charts/tables, slides | Faysse et al., arXiv:2407.01449, Jun 2024; introduces ViDoRe benchmark |
| ColQwen2, ColSmol | Smaller / multi-language variants | illuin-tech/colpali |
ColPali beats text-extraction-then-embed pipelines on document-image benchmarks. Use it when the corpus is visually rich (scans, slides, layouts that don't OCR cleanly).
Singh et al., "Agentic Retrieval-Augmented Generation: A Survey" (arXiv:2501.09136, Jan 2025). Patterns: reflection (re-query if confidence low), planning (decompose then retrieve per sub-question), tool use (route between corpora and tools), multi-agent (specialist sub-agents per corpus).
Use agentic RAG when queries are heterogeneous (some need code search, some need docs, some need web), or when single-pass retrieval has known failure modes the agent can detect and recover from. Cost: 2–4× a single-pass RAG; justify with evidence the simpler design failed.
Agentic search is the 2026 variant for code and structured workspaces: give the agent grep/glob/read tools and let it retrieve just in time instead of pre-indexing everything (Anthropic, Effective context engineering for AI agents, Sep 2025). It trades index maintenance for more tool calls; measure both on your eval set.
arXiv:2401.05856, Jan 2024 — canonical failure taxonomy:
Diagnose at the failing layer; map fix to the right intervention (corpus curation, retrieval tuning, reranking, chunk-size, generator prompting).
Within-domain pairings:
Primary sources:
~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.