agent-instructions
Use when writing project instructions for a coding agent (CLAUDE.md, AGENTS.md, or equivalent). Covers what belongs in them, what…
Use when building retrieval-augmented generation. Covers chunking, embedding and hybrid search, reranking, grounding and citation, and diagnosing whether a bad answer is a retrieval failure or a generation failure. Trigger on "our rag keeps hallucinating", "chat with our docs",
Claude Code
$ npx -y skills add nimadorostkar/Claude-Skills-collection --skill rag --agent claude-code
Codex
$ npx skills add nimadorostkar/Claude-Skills-collection --skill rag -a codex -y
Cursor
$ npx skills add nimadorostkar/Claude-Skills-collection --skill rag -a cursor -y
Gemini CLI
$ npx skills add nimadorostkar/Claude-Skills-collection --skill rag -a gemini-cli -y
GitHub Copilot
$ npx skills add nimadorostkar/Claude-Skills-collection --skill rag -a github-copilot -y
OpenCode
$ npx skills add nimadorostkar/Claude-Skills-collection --skill rag -a opencode -y
Windsurf
$ npx skills add nimadorostkar/Claude-Skills-collection --skill rag -a windsurf -y
name: rag description: Use when building retrieval-augmented generation. Covers chunking, embedding and hybrid search, reranking, grounding and citation, and diagnosing whether a bad answer is a retrieval failure or a generation failure. Trigger on "our rag keeps hallucinating", "chat with our docs", "retrieval returns the wrong documents". Do not use for managing context in a long conversation — see the context-engineering skill; for teaching a style or format, see the fine-tuning skill. metadata: category: ai version: 1.0.0 tags: [rag, retrieval, embeddings, vector-search, grounding]
Build a RAG system whose answers are grounded in retrieved evidence, and be able to tell — when an answer is wrong — whether the retriever failed to find the right document or the generator failed to use it.
1. **Evaluate retrieval separately** — Before touching the prompt. If the correct passage is not in the top-k, no amount of prompt engineering will produce a correct answer. Measure recall@k first. 2. **Chunk on semantic boundaries** — Sections, paragraphs, or logical units. Fixed-size chunking splits a table in half and produces two useless chunks. Add overlap so a fact spanning a boundary is not lost. 3. **Retrieve hybrid** — Dense embeddings find semantic matches; BM25 finds exact terms, product codes, and names. Neither alone is sufficient; the combination materially outperforms both. 4. **Rerank the candidates** — Retrieve 50, rerank with a cross-encoder, pass the top 5. Reranking is the single highest-value addition to a naive RAG pipeline. 5. **Ground the generation** — Instruct the model to answer *only* from the provided context, to cite the passage for each claim, and to say it does not know when the context does not contain the answer. 6. **Diagnose failures by component** — For each wrong answer: was the right passage retrieved? If no, it is a retrieval problem. If yes, it is a generation problem. These have completely different fixes.
**Hybrid retrieval with reranking:**
async def retrieve(query: str, tenant_id: str, k: int = 5) -> list[Chunk]:
# 1. Rewrite the query: user questions are often poor search queries.
search_query = await rewrite_for_retrieval(query)
# 2. Dense and sparse, in parallel. They fail in different ways.
dense, sparse = await asyncio.gather(
vector_store.search(
embed(search_query),
k=50,
filter={"tenant_id": tenant_id}, # a filter, not a post-hoc check
),
bm25.search(search_query, k=50, filter={"tenant_id": tenant_id}),
)
# 3. Fuse the two rankings.
candidates = reciprocal_rank_fusion(dense, sparse)[:50]
# 4. Rerank with a cross-encoder: it sees the query and the passage together,
# which a bi-encoder embedding cannot. This is the biggest single win.
scored = await reranker.score(query, candidates)
return [c for c, score in scored if score > 0.35][:k]**Grounded generation that is allowed to refuse:**
GROUNDED_PROMPT = """\
Answer the question using only the passages provided below.
- Cite the passage number for every factual claim, like this: [2]
- If the passages do not contain the answer, respond exactly:
"The provided documents do not answer this question."
- Do not use knowledge from outside the passages, even if you are confident.
Passages:
{passages}
Question: {question}"""**Diagnosing failures by component — the step that most teams skip:**
for case in eval_set:
retrieved = await retrieve(case.question, case.tenant_id)
retrieved_ids = {c.id for c in retrieved}
if not (case.gold_chunk_ids & retrieved_ids):
record("RETRIEVAL_FAILURE", case) # the answer was never in the context
else:
answer = await generate(case.question, retrieved)
if not matches(answer, case.gold_answer):
record("GENERATION_FAILURE", case) # it was there and the model missed it
# Typical first result on a naive pipelinA curated library of 137 production-grade skills for Claude and other AI coding agents. Every skill follows one structure, speaks with one voice, and earns its place by changing what the agent does.
Use when writing project instructions for a coding agent (CLAUDE.md, AGENTS.md, or equivalent). Covers what belongs in them, what…
Use when an agent needs state that survives a session or a context compaction. Covers what to persist, file-based memory,…
Use when automating agent behavior with lifecycle hooks. Covers hook events, deterministic enforcement of rules the model should…
Use when packaging skills, commands, hooks, and MCP servers into a distributable plugin. Covers manifest structure, bundling,…
Use when writing a new skill for an AI agent. Covers scoping, description writing for reliable triggering, progressive…
Use when reviewing or improving an existing agent skill. Covers triggering accuracy, content quality, redundancy with the base…
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…
Ask which skill or flow fits your situation. A router over the skills in this repo.