eval: record why each answer source ranks where it does, opt-in on canary dispatch

Merged
BI
1mo ago
+138-4

User description

Summary

  • Before: the answer-quality canary reports which files an answer used, but not why they landed in that order. After PR #3572 went live, assessment-documentation still lists Assessment Documentation (AKG) 4th behind Admissions, Radiotherapy and Pressure Injury. An offline reproduction keeps AKG first, so a step after selection on the live path is reordering, and nothing recorded shows which.
  • After: the bounded per-source diagnostics also carry ranking (hybrid, rank, release-rank and final scores, final rank, and pipeline match reasons such as retrieval_signal:document_title_phrase or second_stage_rerank). A new dump_rag_cases dispatch payload passes the existing --dump-rag-cases flag, so the file lands in the canary artifact.
  • How: buildBoundedRagSourceDiagnostics in scripts/eval-answer-quality.ts gains the ranking block. Reasons are bounded to 48 and passed through displaySafeDiagnosticText. eval-canary.yml adds DUMP_RAG_CASES to the answer step, which is empty for the weekly schedule. The dump is written before any --fail-on-threshold exit.

Areas touched: Answer engine
RAG impact: no retrieval behaviour change — eval diagnostics and an opt-in canary artifact only

Verification

  • Checks run:
    • npx vitest run tests/eval-answer-quality.test.ts: Tests 23 passed (23), including the new ranking-diagnostics test.
    • npm run lint (changed files): recorded a pass for "lint:internal"
    • npm run typecheck: recorded a pass for "typecheck:internal"
    • npm run test: Tests 31524 passed | 8 skipped (31532)

Risk and rollout

  • Risk: low. This is eval tooling only, and the workflow switch is off unless a dispatch sets dump_rag_cases: "true".
  • Rollback: revert this commit.
  • Provider or production effects: none from merging. A dispatched canary run with the switch on is paid (about US$1 to 2) and needs the owner's named yes.

Notes

  • Kept as a draft until the owner says go.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VkKjYakMrMXofU8foQCgbq


Generated by Claude Code


Summary by cubic

Records each answer source's ranking scores and pipeline match reasons in the eval canary diagnostics, so a live source misorder (the AKG guideline still ranked 4th after PR #3572) can be diagnosed offline.

Diagnostics

  • buildBoundedRagSourceDiagnostics now emits a ranking block: answer-evidence score, hybrid, rank, release-rank, and final scores, final rank, and match reasons (capped at 48 and sanitized).
  • The answer-evidence score re-scores the emitted sources with the answer-stage ranking that set their order, since rankAnswerEvidence can reorder sources after retrieval selection; it explains that reorder, not later context-selection moves.
  • eval-canary.yml adds a DUMP_RAG_CASES env var that passes --dump-rag-cases only when a dispatch sets dump_rag_cases: "true"; the weekly schedule stays off.
  • Eval tooling only — no retrieval or answer behavior change.

CodeAnt-AI Description

Add opt-in source-ranking details to answer-quality canary dumps

What Changed

  • Each answer source’s diagnostic details now show its ranking scores, final position, and reasons for matching.
  • Dispatch runs can optionally save per-case answers and ranking details as a canary artifact; scheduled runs remain unchanged.

Impact

✅ Easier diagnosis of misordered answer sources
✅ Offline review of canary ranking decisions
✅ No extra answer generation for diagnostics

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.