RAGIFY
/Docs
developer mode
Audience: developerRead Time: 7 minStatus: built

Evaluation and Doctor

Evaluation and Doctor

Last verified against: commit 6f2f20b (v1.0)
Estimated Read Time: 7 min
Status: built

Locus provides an evaluation suite and an automated diagnostic engine (Doctor) to measure and improve retrieval quality across prompt, chunking, and ranking variants.


1. Retrieval Metrics & Statistics

Evaluations quantify retrieval and generation performance against labeled golden test sets:

MetricInterpretationTarget Direction
recall@kFraction of ground-truth chunks retrieved in top-k resultsHigher is better
precision@kFraction of retrieved top-k chunks that are relevantHigher is better
context_precision_tokens@kSignal-to-noise ratio of tokens injected into LLM promptHigher is better
ndcg@kNormalized Discounted Cumulative Gain accounting for rank positionsHigher is better
mrrMean Reciprocal Rank of first relevant documentHigher is better
hit@5Probability that at least one relevant chunk appears in top 5Higher is better
false_refusalRate at which the assistant refuses an answerable questionLower is better
unsafe_answerRate at which the assistant answers an unanswerable questionLower is better

95% Paired Bootstrap Confidence Intervals

When comparing baseline and candidate variants, Locus computes paired bootstrap confidence intervals (1,000 resamples) and permutation p-values. A variant difference is designated meaningful only when zero falls outside the 95% confidence interval ($\alpha = 0.05$).


2. Doctor Rules (D1 – D9)

The Doctor diagnostics engine runs 9 automated rules across evaluation runs:

  1. D1: Route Slice Weakness
    Detects if specific semantic query categories underperform compared to the overall run average.
  2. D2: Depth Gap
    Evaluates whether increasing candidate depth (candidates_n) from 5 to 20 captures relevant chunks missed at top 5.
  3. D3: Broad Chunks
    Detects chunks with excessive token counts that dilute prompt context precision.
  4. D4: False Refusals
    Identifies instances where sufficient evidence exists in retrieved context, but the assistant refused to answer.
  5. D5: Unsafe Answers
    Detects hallucinations where the assistant answered an unanswerable question without supporting citations.
  6. D6: Citation Problems
    Flags citations pointing to missing chunks or invalid document offsets.
  7. D7: Temporal Stale Citations
    Detects conflicts between multiple conflicting document versions where an older version was cited.
  8. D8: Router Errors
    Flags routing mismatches where structured queries fell back unnecessarily to semantic retrieval.
  9. D9: Rerank No Gain
    Identifies scenarios where cross-encoder reranking produced no statistically significant gain over hybrid search alone.

3. Evidence Levels

Every finding emitted by Doctor is classified into one of four evidence tiers:

  • observed: Direct measurement from current run results (e.g. observed false refusal count).
  • counterfactual: What-if simulation evaluating alternative parameter thresholds on historical traces.
  • measured_effect: Statistical comparison with paired bootstrap confidence intervals between two runs.
  • hypothesis: Algorithmic suggestion requiring an experimental run to confirm.

When a recommended configuration change is deployed and an evaluation subsequently confirms improvement, the finding transitions to status verified_improved.


4. Running an Evaluation via API

To trigger an evaluation run programmatically:

# Run in terminal
curl -X POST http://127.0.0.1:8000/evaluation/runs \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer locus_session_REPLACE_ME" \
  -d '{
    "dataset_id": 1,
    "variant": {
      "strategy": "hybrid_rerank",
      "top_k": 5,
      "min_score": 0.35
    }
  }'
Checked against build git-rev-evaluation-doctor
Truth Audit Specification Validated