| name | ai-rag |
| description | Complete RAG and search engineering skill. Covers chunking strategies, hybrid retrieval (BM25 + vector), cross-encoder reranking, query rewriting, ranking pipelines, nDCG/MRR evaluation, and production search systems. Modern patterns for retrieval-augmented generation and semantic search. |
RAG & Search Engineering โ Complete Reference
Build production-grade retrieval systems with hybrid search, grounded generation, and measurable quality.
This skill covers:
- RAG: Chunking, contextual retrieval, grounding, adaptive/self-correcting systems
- Search: BM25, vector search, hybrid fusion, ranking pipelines
- Evaluation: recall@k, nDCG, MRR, groundedness metrics
Modern Best Practices (December 2025):
Default posture: deterministic pipeline, bounded context, explicit failure handling, and telemetry for every stage.
Scope note: For prompt structure and output contracts used in the generation phase, see ai-prompt-engineering.
Quick Reference
| Task | Tool/Framework | Command/Pattern | When to Use |
|---|
| Decide RAG vs alternatives | Decision framework | RAG if: freshness + citations + corpus size; else: fine-tune/caching | Avoid unnecessary retrieval latency/complexity |
| Chunking & parsing | Chunker + parser | Start simple; add structure-aware chunking per doc type | Ingestion for docs, code, tables, PDFs |
| Retrieval | Sparse + dense (hybrid) | Fusion (e.g., RRF) + metadata filters + top-k tuning | Mixed query styles; high recall requirements |
| Precision boost | Reranker | Cross-encoder/LLM rerank of top-k candidates | When top-k contains near-misses/noise |
| Grounding | Output contract + citations | Quote/ID citations; answerability gate; refuse on missing evidence | Compliance, trust, and auditability |
| Evaluation | Offline + online eval | Retrieval metrics + answer metrics + regression tests | Prevent silent regressions and staleness failures |
Decision Tree: RAG Architecture Selection
Building RAG system: [Architecture Path]
โโ Document type?
โ โโ Page/section-structured? โ Structure-aware chunking (pages/sections + metadata)
โ โโ Technical docs/code? โ Structure-aware + code-aware chunking (symbols, headers)
โ โโ Simple content? โ Fixed-size token chunking with overlap (baseline)
โ
โโ Retrieval accuracy low?
โ โโ Query ambiguity? โ Query rewriting + multi-query expansion + filters
โ โโ Noisy results? โ Add reranker + better metadata filters
โ โโ Mixed queries? โ Hybrid retrieval (sparse + dense) + reranking
โ
โโ Dataset size?
โ โโ <100k chunks? โ Flat index (exact search)
โ โโ 100k-10M? โ HNSW (low latency)
โ โโ >10M? โ IVF/ScaNN/DiskANN (scalable)
โ
โโ Production quality?
โโ Add: ACLs, freshness/invalidation, eval gates, and telemetry (end-to-end)
Core Concepts (Vendor-Agnostic)
- Pipeline stages: ingest โ chunk โ embed โ index โ retrieve โ rerank โ pack context โ generate โ verify.
- Two evaluation planes: retrieval relevance (did we fetch the right evidence?) vs generation fidelity (did we use it correctly?).
- Freshness model: staleness budget, invalidation triggers, and rebuild strategy (incremental vs full).
- Trust boundaries: retrieved content is untrusted; apply the same rigor as user input (OWASP LLM Top 10: https://owasp.org/www-project-top-10-for-large-language-model-applications/).
Implementation Practices (Tooling Examples)
- Use a retrieval API contract: query, filters, top_k, trace_id, and returned evidence IDs.
- Instrument each stage with tracing/metrics (OpenTelemetry GenAI semantic conventions: https://opentelemetry.io/docs/specs/semconv/gen-ai/).
- Add caches deliberately: embeddings cache, retrieval cache (query+filters), and response cache (with invalidation).
Do / Avoid
Do
- Do keep retrieval deterministic: fixed top_k, stable ranking, explicit filters.
- Do enforce document-level ACLs at retrieval time (not only at generation time).
- Do include citations with stable IDs and verify citation coverage in tests.
Avoid
- Avoid shipping RAG without a test set and regression gate.
- Avoid โstuff everythingโ context packing; it increases cost and can reduce accuracy.
- Avoid mixing corpora without metadata and tenant isolation.
When to Use This Skill
Claude should invoke this skill when the user asks:
- "Help me design a RAG pipeline."
- "How should I chunk this document?"
- "Optimize retrieval for my use case."
- "My RAG system is hallucinating โ fix it."
- "Choose the right vector database / index type."
- "Create a RAG evaluation framework."
- "Debug why retrieval gives irrelevant results."
Related Skills
For adjacent topics, reference these skills:
- ai-llm - Prompting, fine-tuning, instruction datasets
- ai-agents - Agentic RAG workflows and tool routing
- ai-llm-inference - Serving performance, quantization, batching
- ai-mlops - Deployment, monitoring, security, privacy, and governance
- ai-prompt-engineering - Prompt patterns for RAG generation phase
Detailed Guides
Core RAG Architecture
Advanced Retrieval Techniques
- Retrieval Patterns - Dense retrieval, hybrid search, query preprocessing, reranking workflow, metadata filtering
- Contextual Retrieval Guide - Chunk context augmentation technique; validate impact on your corpus
- Grounding Checklists - Context compression, hallucination control, citation patterns, answerability validation
Production & Evaluation
- RAG Evaluation Guide - Recall@K, nDCG, groundedness, RAGAS/TruLens, A/B testing, sliced evaluation
- Advanced RAG Patterns - Graph/multimodal RAG, online evaluation, telemetry, shadow/canary testing, adaptive retrieval
- RAG Troubleshooting - Failure mode triage, debugging irrelevant results, hallucination fixes
Existing Detailed Patterns
Templates
System Design (Start Here)
Chunking & Ingestion
Embedding & Indexing
Retrieval & Reranking
Context Packaging & Grounding
Evaluation
Navigation
Resources
Templates
Data
External Resources
See data/sources.json for:
- Embedding models (OpenAI, Cohere, Sentence Transformers, Voyage AI, Jina)
- Vector DBs (FAISS, Pinecone, Qdrant, Weaviate, Milvus, Chroma, pgvector, LanceDB)
- Hybrid search libraries (Elasticsearch, OpenSearch, Typesense, Meilisearch)
- Reranking models (Cohere Rerank, Jina Reranker, RankGPT, Flashrank)
- Evaluation frameworks (RAGAS, TruLens, DeepEval, BEIR)
- RAG frameworks (LlamaIndex, LangChain, Haystack, txtai)
- Advanced techniques (RAG Fusion, CRAG, Self-RAG, Contextual Retrieval)
- Production platforms (Vectara, AWS Kendra)
Use this skill whenever the user needs retrieval-augmented system design or debugging, not prompt work or deployment.