eval-rag
Evaluate RAG pipeline retrieval and generation quality separately. Measure Recall@k, Precision@k, MRR, NDCG@k for retrieval. Assess faithfulness and relevance for generation. Use when the AI feature uses retrieval (search, knowledge base, document QA). Do NOT use for non-RAG AI features.
What this skill does
# Eval RAG
Evaluate RAG pipelines by separating retrieval quality from generation quality. Fix retrieval first.
## Entry Point
When this skill is invoked, start with:
```
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
EVAL RAG
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Retrieval and generation fail differently. Measure them separately.
What RAG feature are we evaluating?
What does it retrieve from? (knowledge base, docs, database)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```
## Prerequisites
Complete error analysis (`/upgrade-evals`) on RAG pipeline traces before selecting metrics. Inspect what was retrieved vs. what the model needed. Determine whether the problem is retrieval, generation, or both. Fix retrieval first — the LLM can ignore irrelevant context but cannot generate from missing context.
## Core Process
### Step 1: Separate Retrieval from Generation
Ask the PM: "When the AI gives a wrong answer, is it because it found the wrong documents, or because it had the right documents but said the wrong thing?"
This determines where to focus:
| Symptom | Likely Cause | Fix |
|---------|-------------|-----|
| AI says "I don't know" or gives generic answer | Retrieval: relevant docs not found | Improve chunking, embeddings, or query |
| AI confidently states something not in any doc | Generation: hallucination | Improve prompt, add grounding |
| AI answers a different question than asked | Could be either | Check retrieved docs first |
### Step 2: Build a Retrieval Evaluation Dataset
Queries paired with ground-truth relevant document chunks.
**Manual curation (highest quality, PM-driven):**
Ask the PM: "For each of these test queries, which document(s) actually contain the answer?"
The PM maps queries to chunks. This is domain knowledge work — the PM knows the content better than any automated system.
**Synthetic QA generation (scalable):**
Claude Code executes: For each document chunk, extract a fact and generate a question answerable only from that fact.
```
Given a chunk of text, extract a specific, self-contained fact from it.
Then write a question that is directly and unambiguously answered
by that fact alone.
Return output in JSON format:
{ "fact": "...", "question": "..." }
Chunk: "{text_chunk}"
```
**Adversarial questions (stress-testing):**
Claude Code executes: Create queries that resemble content in multiple chunks but are only answered by one. Find similar chunks via embedding search, then generate a question that only the target chunk answers.
### Step 3: Measure Retrieval Quality
Claude Code executes all metric computations. The PM interprets results.
**Recall@k** — Did we find the right documents?
```
Recall@k = (relevant docs in top k) / (total relevant docs for query)
```
Prioritize for first-pass retrieval. High recall = the right docs are in the candidate set.
**Precision@k** — How much noise in the results?
```
Precision@k = (relevant docs in top k) / k
```
Prioritize for reranking evaluation.
**MRR (Mean Reciprocal Rank)** — How quickly do we find the first right document?
```
MRR = (1/N) * sum(1/rank_of_first_relevant_doc)
```
Best for single-fact lookups.
**NDCG@k** — Are the most relevant results ranked highest?
```
DCG@k = sum over i=1..k of: rel_i / log2(i+1)
IDCG@k = DCG@k with documents sorted by decreasing relevance
NDCG@k = DCG@k / IDCG@k
```
Use when documents have varying utility.
**Which metric to use:**
| Your Query Type | Primary Metric | Why |
|----------------|---------------|-----|
| Single-fact lookups ("What's our refund policy?") | MRR | One key chunk needed, want it ranked first |
| Broad coverage ("Summarize market trends") | Recall@k | Need all relevant docs, even at cost of noise |
| Ranked results matter | NDCG@k or Precision@k | Quality of ranking matters for the answer |
**Choosing k:** Factual lookup uses k=1-2. Synthesis query uses k=5-10. Ask the PM: "How many documents does your pipeline pass to the LLM?"
### Step 4: Optimize Chunking (if retrieval is the bottleneck)
Treat chunking as a tunable hyperparameter. Claude Code executes a grid search.
Claude Code executes:
```
Test combinations of chunk size and overlap.
Re-index the corpus for each configuration.
Measure retrieval metrics on the evaluation dataset.
```
Example results:
| Chunk Size | Overlap | Recall@5 | NDCG@5 |
|-----------|---------|----------|--------|
| 128 tokens | 0 | 0.82 | 0.69 |
| 128 tokens | 64 | 0.88 | 0.75 |
| 256 tokens | 0 | 0.86 | 0.74 |
| 256 tokens | 128 | 0.89 | 0.77 |
| 512 tokens | 0 | 0.80 | 0.72 |
Present to PM: "256 tokens with 128 overlap gives the best recall. Want to go with that?"
**Content-aware chunking:** When fixed-size chunks split related information, use natural document boundaries (sections, paragraphs). Augment chunks with context: prepend document title and section headings before embedding.
### Step 5: Evaluate Generation Quality
After confirming retrieval works, evaluate what the LLM does with the retrieved context.
**Answer faithfulness** — Does the output accurately reflect the retrieved context?
- **Hallucinations:** Information absent from source documents. In RAG, even correct facts from the LLM's own knowledge count as hallucinations.
- **Omissions:** Relevant information from the context ignored in the output.
- **Misinterpretations:** Context information represented inaccurately.
**Answer relevance** — Does the output address the original query? An answer can be faithful to the context but fail to answer what the user asked.
Use `/upgrade-evals` to discover specific manifestations in your pipeline. Use `/build-judge` for failure modes that require subjective evaluation.
### Step 6: Diagnose with the Metric Pattern Table
Present this to the PM for root cause identification:
```
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
RAG DIAGNOSTIC TABLE
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
| Context Quality | Faithfulness | Relevance | Diagnosis |
|-----------------|-------------|-----------|-----------|
| Good | Good | Bad | Generator attended to wrong section |
| Good | Bad | -- | Hallucination or misinterpretation |
| Bad | -- | -- | Retrieval problem. Fix first. |
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```
**What to tell your engineer:**
- "Context quality is low" → Fix chunking, embeddings, or query preprocessing.
- "Faithful but not relevant" → Generator needs better instruction to address the actual question.
- "Not faithful" → Add grounding instructions, reduce temperature, or use citation enforcement.
## Multi-Hop Retrieval
For queries requiring information from multiple chunks:
**Two-hop Recall@k:** Fraction of 2-hop queries where both ground-truth chunks appear in top k results.
```
TwoHopRecall@k = (1/N) * sum(1 if {Chunk1, Chunk2} ⊆ top_k_results)
```
Diagnose: classify failures as hop 1 miss, hop 2 miss, or rank-out-of-top-k.
## Output
```
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
RAG EVALUATION RESULTS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Feature: [name]
Eval dataset: [N] queries with ground-truth mappings
RETRIEVAL:
| Metric | Score | Interpretation |
|--------|-------|---------------|
| Recall@5 | [X] | [good/needs work] |
| Precision@5 | [X] | [good/needs work] |
| MRR | [X] | [good/needs work] |
GENERATION:
| Dimension | Pass Rate | Top Failure Mode |
|-----------|-----------|-----------------|
| Faithfulness | [%] | [description] |
| Relevance | [%] | [description] |
DIAGNOSIS: [Retrieval problem / Generation problem / Both]
RECOMMENDED ACTIONS:
1. [highest-impact fix]
2. [second fix]
3. [third fix]
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```
## Anti-Patterns
- Using a single end-to-end correctness metric without separating retrieval and gRelated in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.