Best for
- Use when the user asks about: choosing retrieval mode (file search / tools / SQL / vector RAG); designing a RAG or retrieval system; diagnosing retrieval quality; late interaction, reranking, or hybrid search; PDF, tabl…
vasilyu1983/AI-Agents-public/frameworks/shared-skills/skills/ai-rag/SKILL.md
Designs retrieval-augmented generation and search systems. Use when choosing retrieval, chunking, hybrid search, grounding, or RAG evaluation patterns.
Decision brief
Build retrieval systems that are grounded, observable, and explicit about tradeoffs.
Compatibility matrix
| Platform | Status | Evidence | What to check |
|---|---|---|---|
| Codex | Declared | Source record | Install path and trigger |
| Claude Code | Declared | Source record | Install path and trigger |
| Cursor | Not declared | No explicit evidence | Portability before use |
| Gemini CLI | Not declared | No explicit evidence | Portability before use |
Installation
The source command is displayed only when detected. A safe inspection prompt is always available so your agent can explain every action before execution.
npx skills add https://github.com/vasilyu1983/AI-Agents-public --skill "frameworks/shared-skills/skills/ai-rag"Inspect the Agent Skill "ai-rag" from https://github.com/vasilyu1983/AI-Agents-public/blob/53f6cb73ea53a2646e3e7d4665062ad66f3683ac/frameworks/shared-skills/skills/ai-rag/SKILL.md at commit 53f6cb73ea53a2646e3e7d4665062ad66f3683ac. List every install step, command, network request, credential, file read/write, external action, and rollback step. Explain whether it fits my task. Do not install or execute anything until I approve.
Workflow
1. Pin the authority source and freshness budget first. Before touching a chunker or embedder, decide whether truth lives in documents, live tools, or a structured store, and how stale an answer is allowed to be. This decision, not chunk size, determines the architecture. 2. Run…
Review the “ASCII Flow” section in the pinned source before continuing.
Review the “Quick Reference” section in the pinned source before continuing.
Review the “Retrieval Choice Framework” section in the pinned source before continuing.
Authority source: define whether truth comes from retrieved documents, live tools, structured databases, or a hybrid of them.
Permission review
The documentation includes network, browsing, or remote request actions.
**Managed retrieval is a real option:** Anthropic's `web_search_20260209` (and `web_search_20250305`) server tools and OpenAI's file-search are API-native retrieval surfaces — evaluate them before building a self-hosted RAG stack. See [refeThe documentation includes network, browsing, or remote request actions.
| Provider-managed retrieval | Anthropic web search tool (`web_search_20260209`) or hosted file search | Fresh web data with citations, fast start, no infra to operate | You need residency controls, custom ranking internals, or corpus isolaEvidence record
| Signal | Value | Evidence type | Meaning |
|---|---|---|---|
| Quality score | 95/100 | Computed | Documentation, specificity, maintenance, and trust rules |
| Repository stars | 82 | Source | Repository attention, not individual Skill quality |
| Compatibility | 2 platforms | Source | Declared in the catalog source record |
| Usage guide | automated source guide | Editorial | Generated or reviewed according to the visible evidence level |
Pinned source
Build retrieval systems that are grounded, observable, and explicit about tradeoffs.
This skill covers:
July 2026 posture
web_search_20260209 (and web_search_20250305) server tools and OpenAI's file-search are API-native retrieval surfaces — evaluate them before building a self-hosted RAG stack. See references/managed-retrieval-vs-self-hosted.md.../ai-context-layer/references/retrieve-vs-preload-vs-finetune.md before building a RAG pipeline.Scope note: For generation-prompt structure and output contracts after retrieval, use ai-prompt-engineering.
Implementation note: This skill owns retrieval theory and evaluation concepts. For vector-brain builds with paste-ready SQL, pgvector assets, manifests, ingest scripts, and agent retrieval tool contracts, use ai-vector-brain.
knowledge need
|
v
retrieval mode decision
long context | hosted retrieval | tool/API | SQL/graph | hybrid search
|
v
corpus contract
source truth + parsing + metadata + ACL + freshness + deletion path
|
v
retrieval quality loop
baseline -> sparse/dense/hybrid -> rerank/filter/query rewrite -> eval
|
v
answer quality loop
context pack + citation checks + refusal behavior + faithfulness eval
scripts/exact_search_baseline.py, scripts/retrieval_eval.py). Measure recall@k, MRR, nDCG before adding embeddings, hybrid fusion, or a reranker — an expert never tunes a component the eval hasn't proven necessary.| Need | Recommended path | Use when | Avoid when |
|---|---|---|---|
| Small corpus fits in context | Long-context prompt or lightweight search | Low update rate, low audit burden | Corpus is large, fast-changing, or citation-critical |
| Provider-managed retrieval | Anthropic web search tool (web_search_20260209) or hosted file search | Fresh web data with citations, fast start, no infra to operate | You need residency controls, custom ranking internals, or corpus isolation beyond provider defaults |
| Provider-managed file/doc retrieval | OpenAI file-search (Responses API) | Standard docs/Q&A, limited infra appetite | You need custom ranking, strict residency controls, or deep retrieval tuning |
| Provider-managed doc retrieval on AWS | AWS Bedrock Knowledge Bases | AWS-native, want managed ingestion + embedding + retrieval with IAM/residency controls | You need cross-cloud portability or custom ranking internals → references/aws-bedrock-knowledge-bases.md |
| Source of truth is tools/APIs | Tool-first or MCP retrieval | Data lives in SQL, CRM, ticketing, SaaS APIs, or internal tools | You actually need semantic retrieval over large prose corpora |
| Website or research ingestion | Crawl/extract first, then index | The source starts as websites, reports, or broad web research | You only need one-off browsing instead of a maintained retrieval system |
| Exact joins or aggregations | SQL/graph retrieval | Questions need filters, joins, counts, or relationship traversal | Natural-language corpus lookup is the main problem |
| Standard knowledge retrieval | Hybrid search + rerank | Mixed lexical + semantic queries, high recall, controllable latency | A simpler hosted or tool-first option already solves the problem |
| Generated repo/context hub corpus | Graph-bounded hybrid (graph scopes, vector recalls, rerank) | A compiled multi-repo/context hub with an existing knowledge/code graph | The corpus has no graph, or simple semantic lookup already passes eval |
| High-precision retrieval | Late interaction / multivector retrieval | Near-duplicate docs, subtle wording differences, PDF pages, multilingual precision | Latency budget is tight and BM25+dense+rering is already sufficient |
| PDFs, tables, diagrams | Multimodal document retrieval | OCR loses structure or layout meaning matters | Plain text extraction is already high quality |
| Production readiness proof | Golden eval + exact baseline + traces | You need to prove quality, not just describe architecture | One-off exploratory research with no durable corpus |
Need external knowledge?
├─ No -> Use direct prompting / standard prompt engineering
└─ Yes
├─ Data already lives behind tools, APIs, SQL, or SaaS?
│ └─ Start with tool-first or MCP retrieval
│
├─ Corpus fits comfortably in model context and changes slowly?
│ └─ Try long-context or hosted file search before custom indexing
│
├─ Need joins, counts, or relationship traversal?
│ └─ Use SQL, graph, or graph+vector hybrid retrieval
│ (paradigm choice: see ../software-database-design/SKILL.md#storage-paradigm-matrix-relational-vs-graph-vs-vector)
│
├─ Need fresh web data or provider-managed file search without self-hosting?
│ └─ Evaluate managed retrieval first: Anthropic web_search_20260209 / web_search_20250305,
│ OpenAI file-search, or other provider-native tools before building a custom stack
│ (see references/managed-retrieval-vs-self-hosted.md for decision criteria)
│
├─ Need retrieval over prose or mixed documents?
│ └─ Use sparse+dense hybrid as the default baseline
│
├─ Retrieval misses subtle matches or page-level structure?
│ └─ Add late interaction, multivector, or multimodal retrieval
│
├─ Precision still poor?
│ └─ Add reranking, filters, query rewriting, and stronger evals
│
└─ Same queries keep re-running synthesis? Need a reviewable knowledge asset?
└─ Switch from retrieval to knowledge compilation (P7 in ai-context-layer)
Route to ai-context-layer/references/knowledge-compilation-and-wiki-pattern.md
Blocks A15 (RAG re-run per turn instead of compiled knowledge)
| Need | Route to |
|---|---|
Small personal knowledge base (≲100 articles / ≲400K words) where an LLM-maintained INDEX.md is sufficient and vector infra would be premature | ../docs-notes-retrieval/SKILL.md (Karpathy scale heuristic) |
| Paste-ready SQL, DDL, pgvector indexes, or backend loader scripts | ../ai-vector-brain/SKILL.md |
| Building a repo/docs/compliance vector brain end to end | ../ai-vector-brain/SKILL.md |
| App context architecture, memory lifecycle, and grounding boundaries | ai-context-layer |
| Agent topology and tool orchestration | ../ai-agents/SKILL.md |
| Bot UX, conversation flows, and escalation | ai-bot-builder |
On-device iOS retrieval-stitch composer (Apple Foundation Models, @Generable, retrieval over local chunks with no-cloud guarantee) | ../software-ios-ai-engine/SKILL.md |
End-to-end natural conversational iOS surface composed with this skill + ai-context-layer + ai-vector-brain, Path A (Foundation Models) and Path B (vector-DB-only) | ../software-ios-ai-engine/references/composition-with-rag-context-vector.md |
| Cross-platform natural conversation (iOS / Android / web / Telegram-Discord-WhatsApp-Slack bots / voice / backend) with or without on-device models | ../ai-context-layer/references/conversational-surfaces-cross-platform.md |
Do
Avoid
See references/quick-start-guide.md for detailed root-cause analysis of each anti-pattern below.
../ai-context-layer/references/anti-patterns-catalog.md)../ai-context-layer/references/knowledge-compilation-and-wiki-pattern.md)When users ask for "best" tools, models, or frameworks:
add_as_web_search: true.See references/research-and-ingestion-patterns.md for crawl/extract (Firecrawl-style), research loops (GPT Researcher-style), recurring data pipelines (dlt-style), and CLI evaluation workflows (simonw/llm-style). Core rule: separate crawl/extract from rank/retrieve, keep raw capture and chunks as distinct artifacts.
check_sources.py — validate sources.json · retrieval_eval.py — recall@k/MRR/nDCG · check_citation_support.py — evidence-ID verification · generate_synthetic_rag_testset.py — testset scaffolds · late_interaction_eval.py — ColBERT/ColPali offline eval (no inference runner) · exact_search_baseline.py — exact cosine/dot baseline · hybrid_rrf_demo.py — BM25-lite + vector + RRF smoke test
Use when the user asks about: choosing retrieval mode (file search / tools / SQL / vector RAG); designing a RAG or retrieval system; diagnosing retrieval quality; late interaction, reranking, or hybrid search; PDF, table, or diagram retrieval; grounding, citation, or faithfulness evaluation; or debugging freshness, ACL, or prompt-injection in retrieval.
Architecture & choice: retrieval-choice-framework.md · managed-retrieval-vs-self-hosted.md · pipeline-architecture.md · aws-bedrock-knowledge-bases.md
Corpus & chunking: chunking-strategies.md · chunking-patterns.md · index-selection-guide.md · embedding-model-guide.md · research-and-ingestion-patterns.md · pdf-heavy-retrieval-playbook.md
Retrieval patterns: retrieval-patterns.md · vector-search-patterns.md · hybrid-fusion-patterns.md · bm25-tuning.md · graph-rag-patterns.md · contextual-retrieval-guide.md · advanced-rag-patterns.md · agentic-rag-patterns.md
Ranking & query: ranking-pipeline-guide.md · query-rewriting-patterns.md · backend-comparison-fixtures.md
Grounding & eval: grounding-checklists.md · confidence-scoring.md · abstention-recipe.md · rag-evaluation-guide.md · search-evaluation-guide.md
Ops & debugging: observability-tracing-contract.md · retrieval-debugging-runbook.md · rag-troubleshooting.md · search-debugging.md · rag-caching-patterns.md · distributed-search-slos.md · user-feedback-learning.md · multilingual-domain-patterns.md · security-red-team-cases.md
Onboarding: quick-start-guide.md - workflow, full template index, detailed anti-patterns · wiki-grounded-retrieval.md
../ai-context-layer/references/anti-patterns-catalog.md - A2, A10, A13, A15 anti-patterns referenced throughout this skill../ai-context-layer/references/retrieve-vs-preload-vs-finetune.md - Decision rubric: RAG vs long-context vs fine-tune../ai-context-layer/references/knowledge-compilation-and-wiki-pattern.md - P7 pattern for compiled knowledge (A15 fix)../ai-vector-brain/references/dev-context-hub-vector-recipe.md - Graph-bounded build path for generated-context corpora../software-ios-ai-engine/references/composition-with-rag-context-vector.md - iOS conversational RAG compositionGate before invoking: each foundation has a When to Apply / When to Skip section.
Verify bugs, framework footguns, and version-specific guidance against current primary web sources. Use web search for current vendor capabilities, prices, benchmarks, and release status. Mark unverified claims explicitly if live browsing is unavailable.
Before applying this skill on a non-trivial task, read learnings.consolidated.md in this directory (and learnings.md if present). After applying it, append one dated bullet to learnings.md via agents-skills-feedback-loop/scripts/append_learning.py. Do not modify SKILL.md itself.
Frequently asked questions
Build retrieval systems that are grounded, observable, and explicit about tradeoffs.
The source record exposes this install command: npx skills add https://github.com/vasilyu1983/AI-Agents-public --skill "frameworks/shared-skills/skills/ai-rag". Inspect the command and pinned source before running it.
The pinned source record declares support for: codex, claude code.
Static rules flagged network in the source; the page lists the matching lines and excerpts.
Alternatives
vasilyu1983/AI-Agents-public
Configures Claude Code hooks and Codex hooks.json/notify callbacks. Use when adding guardrails, preflight, audit trails, worktree automation, or budget enforcement.
vasilyu1983/AI-Agents-public
Guides iOS testing with XCTest, XCUITest, Swift Testing, simctl, and xcresult. Use when choosing destinations, controlling flakes, or parsing test artifacts for native apps.
vasilyu1983/AI-Agents-public
Guides multi-GPU pre-training: DDP, FSDP2, ZeRO, tensor/pipeline/expert parallelism, fp8/Muon. Use when scaling a run, training MoE, or reproducing GPT-2 on rented GPUs.
vasilyu1983/AI-Agents-public
Scans public GitHub repos for agent skills, dev practices, and code patterns. Use when enriching skills, setting team policy, or researching a build domain.