La interfaz está localizada; las descripciones y documentos de las Skills se traducen automáticamente con IA a su idioma. El código, los comandos, rutas y términos técnicos se mantienen en el original, y prevalece el documento del autor.
Explorar Skills
Diseño y creatividad · SKILL.md

rag-evaluator

rag-evaluator

Use when designing, building, or operating RAG evaluation — golden sets, retrieval metrics (Recall@K, NDCG, MRR), answer metrics (faithfulness, citation accuracy), LLM-as-judge setup, CI gates for RAG, eval at scale, drift detection. Triggers on phrases like "evaluate RAG", "golden set", "RAG metrics", "RAGAS", "faithfulness evaluation", "regression test RA…

Independent GitHub snapshot · Automated classification · Original documentation governs

Documentación de la Skill

GitHub

name: rag-evaluator description: Use when designing, building, or operating RAG evaluation — golden sets, retrieval metrics (Recall@K, NDCG, MRR), answer metrics (faithfulness, citation accuracy), LLM-as-judge setup, CI gates for RAG, eval at scale, drift detection. Triggers on phrases like "evaluate RAG", "golden set", "RAG metrics", "RAGAS", "faithfulness evaluation", "regression test RAG", "RAG CI".

RAG Evaluation

Evaluation is what separates a RAG demo from a RAG product. Build evaluation before tuning the system, not after.

Three levels of evaluation

LevelWhat it measures
RetrievalDid we fetch the right evidence?
AnswerDid the model generate a correct, grounded response?
OperationalLatency, cost, abstention rate, drift

You need all three. Skipping retrieval evaluation is the most common mistake — teams measure answers and miss that retrieval was the actual problem.

v1 vs v2 evaluation maturity

PhaseApproach
v1 (launch)50–200 hand-labeled golden queries; retrieval metrics (Recall@K, NDCG); human spot checks; simple faithfulness rubric
v2 (scale)LLM-as-judge calibrated against human labels; production-trace eval; synthetic eval generation; drift detection

Critical: do not start with LLM-as-judge. Build the hand-labeled foundation first; an uncalibrated judge gives confident garbage.

Retrieval metrics

MetricMeasuresUse when
Recall@KFraction of relevant docs in top-KHigh-stakes / compliance
Precision@KFraction of top-K that are relevantReducing noise
Context PrecisionAre relevant chunks ranked near the top of retrieved set?As soon as you add a reranker
MRR1 / rank of first relevantQ&A where first hit matters
NDCG@KRanking quality with graded relevanceSearch-style ordering
Hit@KAny relevant doc in top-K?Coarse baseline

Context Precision vs Precision@K: Precision@K asks "how many of the top-K are relevant?" — binary. Context Precision asks "are the relevant chunks ranked near position 1 or buried at position K?" A reranker can leave Precision@K unchanged while dramatically improving Context Precision. Add this metric as soon as you introduce a reranker — it's the clearest signal of whether the reranker is earning its keep.

Formula: Context Precision@K = Σ (Precision@i × relevance_i) / total_relevant where i ranges over positions 1..K and relevance_i is 1 if chunk at position i is relevant, 0 otherwise.

Eval Breakdown by Dimension

When Recall@K or another metric regresses — especially after a corpus growth event — never treat the aggregate metric as the diagnosis. Break it down first. The aggregate may hide a regression in one segment while other segments stay healthy.

Dimensions to slice by before touching the pipeline:

DimensionHow to sliceWhat a drop isolates
Document typepolicy vs. ticket vs. manual vs. tableChunking or parsing problem specific to one format
Recencyfresh docs (< 30 days) vs. stale docs (> 90 days)Freshness/version filtering issue; stale docs flooding top-K
Query stylekeyword-heavy vs. semantic / conceptualEmbedding model weakness on one query style; BM25 not covering the other
Query lengthshort (≤ 5 tokens) vs. long (≥ 15 tokens)Short queries may need expansion; long queries may need decomposition
Corpus segmentdepartment, product line, access tierIndex crowding in one segment; wrong routing; missing sub-index
Near-duplicate ratequeries where top-3 results are near-identicalCorpus has duplicate/stale documents polluting top-K

Rule: if one dimension shows a sharp drop while others are flat, the root cause is in that segment — fix that segment before changing the global pipeline. See rag-operations-guide.md §9 for corpus hygiene fixes when duplicates or stale docs are the culprit.

Answer metrics

MetricMeasures
FaithfulnessEvery claim supported by retrieved context?
Answer relevanceDoes the answer address the question?
Context relevanceWas retrieved context actually useful?
Citation accuracyDo citations support the claims?
Citation quality (≠ presence)Does the cited chunk contain the specific assertion?
Hallucination rateFrequency of unsupported assertions
Abstention qualityRefusals when refusal was correct
False Abstention RateHow often the system refused when retrieved context actually supported an answer
False Answer RateHow often the system answered when it should have abstained (the dangerous failure)

Citation quality is not citation presence

A common failure: 100% of answers have citations, but 30% of citations don't actually support the specific claim. Build evaluation that checks per-claim support:

- query: "What approval is required for external contractors?"
  claim: "External contractors need written approval and a valid certificate"
  citation_must_support:
    - contractor_type: external
    - requirement_type: written_approval
    - requirement_type: certificate
  failing_citations:
    - Generic contractor discussion without approval specificity
    - Discussion of approval without certificate requirement

Golden set design

Build the golden set BEFORE building the system. Minimum viable golden set:

- question: What approval is required for external contractors?
  expected_documents:
    - contractor-policy.pdf#page=12
  expected_sections:
    - Approval Requirements
  expected_answer_contains:
    - written approval
    - certificate of compliance
  must_not_contain:
    - unsupported cost estimate
  expected_classification: policy_question
  expected_abstention: false

Coverage targets:

  • ~60% happy path (typical queries with clear answers)
  • ~20% edge cases (rare terms, multi-hop, comparisons)
  • ~20% known unanswerable (verify abstention works)

Even 50 labeled queries is dramatically better than zero. Don't wait for perfection.

LLM-as-judge: dangers and mitigations

When you move to LLM-as-judge at scale (RAGAS, TruLens, custom), know the biases:

BiasMitigation
Position biasRandomize position
Verbosity biasCap or normalize answer length
Self-preference biasUse different model family for judge vs generator
Style biasScore against rubric, not impression

Calibration is mandatory. Sample 10% of judge-graded responses, have humans grade them, track judge–human agreement. If agreement drops below 80%, the judge is drifting; re-prompt or re-train.

Eval at scale

ApproachWhen
Hand-labeled golden setAlways, from day one
Synthetic eval generationExpand coverage; verify 10% by hand
Production-trace evalAfter 1+ month live; sample real queries, label, feed back
Drift detectionMonitor distribution shifts in queries, scores, abstention rate
Counterfactual evalTest abstention works — remove answer doc, verify refusal

CI gate pattern

# Eval CI gate (pseudocode)
def rag_ci_gate(pull_request):
    results = run_eval(golden_set, pull_request.code)
    if results.recall_at_10 < baseline.recall_at_10 - 0.02:
        fail("Recall@10 regression")
    if results.faithfulness < baseline.faithfulness - 0.02:
        fail("Faithfulness regression")
    if results.citation_quality < baseline.citation_quality - 0.05:
        fail("Citation quality regression")
    return pass

Run this on every PR that touches the RAG pipeline.

Python + FastAPI eval scaffolding

When the user wants to set up evaluation in a Python/FastAPI project:

evals/
  golden_set.yaml          # Hand-labeled queries
  run_eval.py              # Eval runner
  metrics.py               # Retrieval + answer metrics
  judges.py                # LLM-as-judge (v2)
  baselines.json           # Baseline scores for CI comparison
  reports/                 # Per-run reports

Suggested libraries: ragas (with calibration), deepeval, or custom — depends on stack. The framework matters less than having the golden set and running it on every change.

Diagnostic Matrix

When a metric regresses, use this table to triage the root cause before touching any code. Fix the upstream layer first — don't patch generation when retrieval is broken.

Bad MetricLikely Root CauseWhere to Look First
Low Recall@KBad chunking (chunks too large/small), weak embedding model, indexing gap, metadata filter too strictCheck chunking strategy, embedding model selection, pre-filter logic
Low Precision@KToo many irrelevant chunks retrieved, reranker missing or weak, k too highReduce k, add/tune reranker, tighten hybrid retrieval
Low Context PrecisionReranker missing or underperforming — relevant chunks exist but are buriedReranker not deployed, or ef_search/nprobe index params too loose; tune or add cross-encoder
Low Context RelevanceSemantic drift between query and document vocabulary, poor chunking, wrong retrieval strategyCheck query expansion, embedding model mismatch, chunking granularity
Low Answer RelevancePrompt issue, generation model too weak, instructions unclear or conflictingAudit system prompt, check for prompt injection, try stronger model
Low FaithfulnessHallucination, citation enforcement absent in prompt, grounding prompt too weakAdd atomic-claim citation check, tighten grounding instructions, check context packing for noise

Key principle: trace backward from the bad metric to the pipeline layer that owns it. Low Faithfulness is almost always a generation-layer or context-packing problem, not a retrieval problem. Low Recall@K is almost always a retrieval or chunking problem — fixing the prompt won't help.

How to apply

When asked about RAG evaluation:

  1. Find out their phase. v1 (no eval yet) needs golden set first. v2 (has eval) needs scale and calibration.
  2. Push back on "we'll evaluate later." No golden set = flying blind. Even 50 queries beats nothing.
  3. Start with retrieval metrics, not just answer metrics. Recall@K catches retrieval failures that look like generation failures.
  4. Warn against uncalibrated LLM-as-judge. It's the most common eval mistake.
  5. Recommend per-claim citation checking — citation presence is a weak signal.

Reference: full playbook §33–37 (evaluation), §35.2 (citation quality), §37.1 (eval at scale).

Skills guardadas