-
Notifications
You must be signed in to change notification settings - Fork 0
docs+tooling(eval): ADDENDUM 4 close-out — Phase C record, boundary-case policy, artifact trend tool (Phase D) #1006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // Render a run-over-run metric trend from downloaded eval-canary artifacts. | ||
| // | ||
| // Every canary run uploads `eval-canary-output` (golden-retrieval.json, 30-day | ||
| // retention). Download the artifacts you want to compare, then: | ||
| // | ||
| // npm run eval:trend -- runA/golden-retrieval.json runB/golden-retrieval.json | ||
| // npm run eval:trend -- --case lithium-therapy-monitoring runA.json runB.json | ||
| // | ||
| // Files are ordered as given (pass oldest first). Offline and read-only: no | ||
| // providers, no repo state — the durable trend record without new infrastructure | ||
| // (docs/observability-slos.md §3.1). | ||
| import { readFileSync } from "node:fs"; | ||
|
|
||
| /** One trend row per artifact payload; exported for tests. */ | ||
| export function buildTrendRows(payloads) { | ||
| return payloads.map(({ label, payload }) => { | ||
| const summary = payload?.summary ?? {}; | ||
| const results = Array.isArray(payload?.results) ? payload.results : []; | ||
| return { | ||
| label, | ||
| cases: results.length, | ||
| failed: Array.isArray(summary.failed_cases) ? summary.failed_cases.length : (summary.failed_cases ?? 0), | ||
| doc_recall_at_5: summary.document_recall_at_5 ?? null, | ||
| content_recall_at_5: summary.content_recall_at_5 ?? null, | ||
| mrr_at_10: summary.mrr_at_10 ?? null, | ||
| content_mrr_at_10: summary.content_mrr_at_10 ?? null, | ||
| irrelevant_at_10: summary.irrelevant_source_rate_at_10 ?? null, | ||
| p50_ms: summary.median_latency_ms ?? null, | ||
| p90_ms: summary.p90_latency_ms ?? null, | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
| /** Per-case reciprocal-rank trend across payloads; exported for tests. */ | ||
| export function buildCaseTrend(payloads, caseId) { | ||
| return payloads.map(({ label, payload }) => { | ||
| const match = (Array.isArray(payload?.results) ? payload.results : []).find((result) => result.id === caseId); | ||
| return { | ||
| label, | ||
| found: Boolean(match), | ||
| rr_at_10: match?.reciprocalRankAt10 ?? null, | ||
| content_rr_at_10: match?.contentReciprocalRankAt10 ?? null, | ||
| passed: match ? match.failures?.length === 0 || match.failures === undefined : null, | ||
| strategy: match?.retrievalStrategy ?? null, | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
| function formatTable(rows) { | ||
| if (!rows.length) return "(no rows)"; | ||
| const keys = Object.keys(rows[0]); | ||
| const cell = (value) => (typeof value === "number" ? Number(value.toFixed(4)).toString() : String(value ?? "-")); | ||
| const widths = keys.map((key) => Math.max(key.length, ...rows.map((row) => cell(row[key]).length))); | ||
| const line = (values) => values.map((value, i) => value.padEnd(widths[i])).join(" "); | ||
| return [ | ||
| line(keys), | ||
| line(widths.map((w) => "-".repeat(w))), | ||
| ...rows.map((row) => line(keys.map((k) => cell(row[k])))), | ||
| ].join("\n"); | ||
| } | ||
|
|
||
| function main() { | ||
| const argv = process.argv.slice(2); | ||
| const caseFlag = argv.indexOf("--case"); | ||
| const caseId = caseFlag >= 0 ? argv[caseFlag + 1] : undefined; | ||
| const files = argv.filter((arg, index) => arg !== "--case" && index !== caseFlag + 1); | ||
| if (!files.length) { | ||
| console.error("Usage: eval-trend [--case <golden-case-id>] <golden-retrieval.json...> (oldest first)"); | ||
| process.exit(2); | ||
| } | ||
| const payloads = files.map((file) => ({ label: file, payload: JSON.parse(readFileSync(file, "utf8")) })); | ||
| console.log(formatTable(buildTrendRows(payloads))); | ||
| if (caseId) { | ||
| console.log(`\nCase trend: ${caseId}`); | ||
| console.log(formatTable(buildCaseTrend(payloads, caseId))); | ||
| } | ||
| } | ||
|
|
||
| if (process.argv[1] && process.argv[1].endsWith("eval-trend.mjs")) main(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { buildCaseTrend, buildTrendRows } from "../scripts/eval-trend.mjs"; | ||
|
|
||
| const payload = (overrides: Record<string, unknown> = {}) => ({ | ||
| label: "run-a.json", | ||
| payload: { | ||
| summary: { | ||
| document_recall_at_5: 1, | ||
| content_recall_at_5: 1, | ||
| mrr_at_10: 0.8921, | ||
| content_mrr_at_10: 0.9228, | ||
| irrelevant_source_rate_at_10: 0.1083, | ||
| median_latency_ms: 11895, | ||
| p90_latency_ms: 34045, | ||
| failed_cases: [], | ||
| }, | ||
| results: [ | ||
| { | ||
| id: "lithium-therapy-monitoring", | ||
| reciprocalRankAt10: 1, | ||
| contentReciprocalRankAt10: 0.75, | ||
| failures: [], | ||
| retrievalStrategy: "text_fast_path", | ||
| }, | ||
| { | ||
| id: "flowchart-next-step", | ||
| reciprocalRankAt10: 0.2, | ||
| contentReciprocalRankAt10: 0.78, | ||
| failures: [], | ||
| retrievalStrategy: "text_fast_path", | ||
| }, | ||
| ], | ||
| ...overrides, | ||
| }, | ||
| }); | ||
|
|
||
| describe("eval-trend aggregation", () => { | ||
| it("builds one summary row per artifact in input order", () => { | ||
| const failing = payload({ | ||
| summary: { | ||
| document_recall_at_5: 0.9167, | ||
| content_recall_at_5: 0.9653, | ||
| mrr_at_10: 0.8138, | ||
| failed_cases: ["a", "b", "c"], | ||
| }, | ||
| }); | ||
| failing.label = "run-b.json"; | ||
| const rows = buildTrendRows([payload(), failing]); | ||
| expect(rows.map((row: { label: string }) => row.label)).toEqual(["run-a.json", "run-b.json"]); | ||
| expect(rows[0]).toMatchObject({ cases: 2, failed: 0, mrr_at_10: 0.8921, doc_recall_at_5: 1 }); | ||
| expect(rows[1]).toMatchObject({ failed: 3, mrr_at_10: 0.8138, doc_recall_at_5: 0.9167 }); | ||
| }); | ||
|
|
||
| it("tracks a single case's reciprocal rank across runs and flags absences", () => { | ||
| const trend = buildCaseTrend([payload()], "flowchart-next-step"); | ||
| expect(trend[0]).toMatchObject({ found: true, rr_at_10: 0.2, strategy: "text_fast_path", passed: true }); | ||
| const missing = buildCaseTrend([payload()], "not-a-case"); | ||
| expect(missing[0]).toMatchObject({ found: false, rr_at_10: null, passed: null }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Do not drop the first artifact when
--caseis absent.With no
--case,caseFlagis-1, soindex !== caseFlag + 1becomesindex !== 0. The documented two-file invocation therefore reports only the second run, while a single-file invocation exits with “no files”.Proposed fix
const caseFlag = argv.indexOf("--case"); const caseId = caseFlag >= 0 ? argv[caseFlag + 1] : undefined; - const files = argv.filter((arg, index) => arg !== "--case" && index !== caseFlag + 1); + const files = + caseFlag >= 0 + ? argv.filter((_, index) => index !== caseFlag && index !== caseFlag + 1) + : argv;📝 Committable suggestion
🤖 Prompt for AI Agents