Evaluate RAG
Purpose
Help agents evaluate retrieval-augmented generation systems by separating retrieval quality from generation quality. This skill covers retrieval eval datasets, Recall@k, reranking metrics, chunking experiments, faithfulness, relevance, and training-data leakage checks.
Quick Start
- Do trace-level error analysis before selecting metrics.
- Build query-to-relevant-chunk datasets for retrieval.
- Optimize first-pass retrieval for recall.
- Evaluate generation separately for faithfulness and relevance.
- Grid-search chunking before tuning generation when retrieval is weak.
Operating Constraints
- Do not rely on one end-to-end score.
- Do not tune generation before checking whether the needed context was retrieved.
- Use Recall@k for first-pass retrieval and precision, MRR, or NDCG for reranking as appropriate.
- Treat synthetic questions as useful but not sufficient without realism filtering.
- Check train/eval leakage when RAG traces become training data.
Inputs This Skill Expects
- RAG traces showing query, retrieved chunks, context, and answer.
- Corpus chunks, chunking strategy, retriever, reranker, and prompt.
- Retrieval eval dataset or source documents from which to build one.
- Generation eval criteria such as grounding, relevance, citation support, and omissions.
Output Contract
- State whether failures come from retrieval, generation, or both.
- Provide retrieval metrics and generation findings separately.
- Recommend chunking, embedding, reranking, prompt, or generation changes based on the diagnosed failure.
- Include leakage and source-alignment checks if traces become training rows.
Procedure
- Inspect failed traces and classify retrieval versus generation failures.
- Build or review query-to-relevant-chunk labels.
- Measure first-pass retrieval and reranking separately.
- Test chunk size, overlap, and content-aware chunking when retrieval is weak.
- Evaluate generated answers for faithfulness, relevance, omissions, and hallucinations.
- If converting traces to training rows, audit final serialized rows for leakage, citation/source alignment, prompt residue, and malformed text.
Pitfalls And Gotchas
- Using similarity metrics as primary answer-quality measures.
- Overfitting to synthetic retrieval questions.
- Ignoring multi-hop queries that need multiple chunks.
- Treating reranker precision as a fix when first-pass recall is too low.
- Training on RAG traces without checking final assistant text quality.
Progressive Disclosure
Start with trace inspection and retrieval/generation separation. Expand into synthetic QA, adversarial retrieval, chunking grid search, reranking, multi-hop metrics, or training-data audits only when the problem requires it.
Verification Pattern
- Confirm traces were inspected before metrics were chosen.
- Confirm retrieval and generation are measured separately.
- Confirm first-pass retrieval recall is adequate before generation tuning.
- Confirm chunking changes are evaluated against a labeled retrieval set.
- Confirm RAG-derived training rows are checked for leakage and source alignment.
1---2name: evaluate-rag3description: Guardrail for evaluating RAG retrieval and generation quality, including retrieval datasets, Recall@k, chunking experiments, grounding, and leakage checks.4---56# Evaluate RAG78## Purpose9Help agents evaluate retrieval-augmented generation systems by separating retrieval quality from generation quality. This skill covers retrieval eval datasets, Recall@k, reranking metrics, chunking experiments, faithfulness, relevance, and training-data leakage checks.1011## Quick Start121. Do trace-level error analysis before selecting metrics.132. Build query-to-relevant-chunk datasets for retrieval.143. Optimize first-pass retrieval for recall.154. Evaluate generation separately for faithfulness and relevance.165. Grid-search chunking before tuning generation when retrieval is weak.1718## Operating Constraints19- Do not rely on one end-to-end score.20- Do not tune generation before checking whether the needed context was retrieved.21- Use Recall@k for first-pass retrieval and precision, MRR, or NDCG for reranking as appropriate.22- Treat synthetic questions as useful but not sufficient without realism filtering.23- Check train/eval leakage when RAG traces become training data.2425## Inputs This Skill Expects26- RAG traces showing query, retrieved chunks, context, and answer.27- Corpus chunks, chunking strategy, retriever, reranker, and prompt.28- Retrieval eval dataset or source documents from which to build one.29- Generation eval criteria such as grounding, relevance, citation support, and omissions.3031## Output Contract32- State whether failures come from retrieval, generation, or both.33- Provide retrieval metrics and generation findings separately.34- Recommend chunking, embedding, reranking, prompt, or generation changes based on the diagnosed failure.35- Include leakage and source-alignment checks if traces become training rows.3637## Procedure381. Inspect failed traces and classify retrieval versus generation failures.392. Build or review query-to-relevant-chunk labels.403. Measure first-pass retrieval and reranking separately.414. Test chunk size, overlap, and content-aware chunking when retrieval is weak.425. Evaluate generated answers for faithfulness, relevance, omissions, and hallucinations.436. If converting traces to training rows, audit final serialized rows for leakage, citation/source alignment, prompt residue, and malformed text.4445## Pitfalls And Gotchas46- Using similarity metrics as primary answer-quality measures.47- Overfitting to synthetic retrieval questions.48- Ignoring multi-hop queries that need multiple chunks.49- Treating reranker precision as a fix when first-pass recall is too low.50- Training on RAG traces without checking final assistant text quality.5152## Progressive Disclosure53Start with trace inspection and retrieval/generation separation. Expand into synthetic QA, adversarial retrieval, chunking grid search, reranking, multi-hop metrics, or training-data audits only when the problem requires it.5455## Verification Pattern56- Confirm traces were inspected before metrics were chosen.57- Confirm retrieval and generation are measured separately.58- Confirm first-pass retrieval recall is adequate before generation tuning.59- Confirm chunking changes are evaluated against a labeled retrieval set.60- Confirm RAG-derived training rows are checked for leakage and source alignment.