Repository navigation
feat(catalog): acceptable alternative skills per query, and catalog routing-compare for two saved runs - #915
Conversation
…compare for two saved runs (intel#710) catalog routing scored a query against its one gold skill only, and two saved all-vs-all runs could not be compared without rescoring by hand. A request in the --queries-by-skill file may now be an object {"query", "acceptable"} beside plain strings. A file of strings reads and saves exactly as before. When the file names an alternative, each arm adds acceptable_rate per gold skill next to own_rate (same scored denominator; (none), (tie) and a failed call never count), the summary prints it, and the rows of such a query keep acceptable. confusion and attractors still follow the gold alone. A malformed object, an unknown key or an acceptable name outside the field is refused naming the file, the skill and the query. catalog routing-compare BASE.json OTHER.json [--arm lexical|model] [--out FILE] pairs the per-query rows of two saved runs by (gold, query), makes no model call, and reports each run's number right, the discordant counts, the exact two-sided sign test over them and the queries whose pick changed. Queries in one run only and unscored rows are counted and left out; alternatives are used only when both runs name the same ones. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
CLI interface change detectedThis PR changes dokimi's user-facing CLI surface (commands and/or options): + added command `dokimi catalog routing-compare`
+ argument `base`
+ argument `other`
+ option `--arm`
+ option `--help/-h`
+ option `--out`Updated on every push; the |
|
✅ OpenCodeReview: Found no critical or high issues in this commit. CI at Review limit reached. This PR has had 6 reviews, so it will only be reviewed again when you ask. Lower-severity findings not shown (1)1 medium Review details
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #915 +/- ##
==========================================
+ Coverage 95.83% 95.86% +0.02%
==========================================
Files 442 444 +2
Lines 58788 59101 +313
Branches 10146 10198 +52
==========================================
+ Hits 56342 56655 +313
Misses 1521 1521
Partials 925 925
🚀 New features to boost your workflow:
|
…t and refuses a malformed row, exact acceptable counts in the summary Settles the three open review threads of intel#915. The summary line of `catalog routing` took its pooled gold and gold-or-acceptable counts from the four-decimal rates, so 1 hit in 30000 scored queries printed as 0. It now sums `confusion` for the gold picks and a new exact per-gold `acceptable_picks` for the acceptable ones. `routing-compare` ran its sign test over every pair, so a request listed six times, right in BASE and wrong in OTHER, gave p = 0.03125. The test now counts each distinct `(gold, query)` once (right in BASE only when more of its pairs are right there); `discordant` keeps the pair counts and `discordant_queries` holds the counts the test uses. `load_run` now checks every row: `query` and `gold` strings, `acceptable` a list of strings, and for the model arm `picks` a list of strings, and refuses with the file and row number. A model section of the wrong type no longer raises for the lexical arm, it only leaves the model name out. Tests also cover the unreachable-before lines codecov named: a too deeply nested file, an unwritable `--out`, the left-out and changed-pick lines of the summary, and a field with no scored query. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
…ting-compare checks the lexical rank and pick Settles the two open review threads and the Python 3.14 wheel failure of intel#915. all_vs_all now drops the gold from a query's acceptable names in kept_alternatives, not only in the file loader, and omits a query left with none, so a direct call no longer counts a gold pick as both the gold and an acceptable hit in either arm. load_run refuses a lexical row whose rank is missing or is neither null nor a positive integer, and a row with a rank whose picked is not a string, naming the file and row; null ranks and the picks (none) and (tie) are kept. The deep-nesting test no longer relies on an unterminated run of brackets, which Python 3.14 reports as a JSON error rather than a RecursionError: it makes json.loads hit the depth limit, as the sibling tests of the queries file do. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
|
Review points answered at Declined, with the evidence in the replies:
|
vchamarthi
left a comment
There was a problem hiding this comment.
🟡 Not approved yet · reviewed 6362b4c
Next: @antonwolfy: settle 1 open question (below). 3 nits optional.
Blocking
- Open question for @antonwolfy:
catalog routing-compare --out FILEcreates a missing parent directory (dokimi/dokimi/commands/routing_compare.py:52), so a mistyped directory is created rather than refused, the waycatalog routing --outdoes. State indocs/skill-novelty.mdthat--outcreates its parent directory, or drop themkdirand refuse a missing directory.
Verified on 6362b4c: ✅ changed tests: 63 passed, fail on main · ✅ full suite with main merged in: 23613 passed · ✅ merges onto main ·
16 checks behind it, each with its evidence
| Area | What holds | How |
|---|---|---|
| Queries file objects | A request given as {query, acceptable} loads with its alternatives, and a file of strings gives an empty alternatives map and no acceptable key in the result |
tests on the head |
| Gold as own alternative | The gold named in its own acceptable is dropped in both arms of a direct all_vs_all call, so a gold pick is counted once |
tests on the head |
| Acceptable rate | acceptable_rate shares the scored denominator with own_rate, and the pooled gold and gold-or-acceptable counts are exact at 30000 scored queries |
tests on the head |
| Sign test | The exact two-sided sign test gives the known p over the discordant pairs, and a request listed twice counts once | tests on the head |
| Compare refusals | --arm model is refused for a run made without --model, and two runs with no pair in common are refused as an input error |
tests on the head |
| File shapes | {}, [], truncated JSON and an empty file are refused naming the file, and the refusal does not reach a traceback |
ran it, edge input (structured) |
| Text input | Bytes that are not UTF-8 are refused naming the file, and a byte order mark with CRLF line endings loads | ran it, edge input (text) |
| Command exit | catalog routing-compare with a missing file exits 2 and prints an Error: line on stderr |
ran it, edge input (cli) |
| Paths | A directory and a missing file given as BASE are refused naming the path and the cause | ran it, edge input (paths) |
| Numbers | A lexical rank of 0, -1, true, 1.0 or NaN is refused naming the row |
ran it, edge input (numbers) |
| Collections | Six copies of one request that is right in BASE and wrong in OTHER count as one discordant query with p 1.0, and two empty runs give p 1.0 with no pair | ran it, edge input (collections) |
| Nulls | A null acceptable and a null unscored rank and picked are read as no alternative, and a null gold is refused naming the row |
ran it, edge input (none) |
| Gold filter mutant | Negating the check that drops a query's alternatives when the query is outside the field makes the changed tests fail | broke the code, tests caught it |
| Load mode check mutant | Negating the mode and result check in load_run makes the changed tests fail |
broke the code, tests caught it, edge input (structured) |
| Merge | The PR merges onto current main with no conflict | merge onto main |
| Local ci | The whole local CI passes with main merged in, including the CLI snapshot, mypy and the coverage of changed lines | full suite, main merged in |
…docs name the acceptable key and the --out parent directory A run whose `result` is null or absent was refused as "not an all-vs-all routing result (mode 'all_vs_all')", naming a mode the file has: it now says the `result` object is missing. docs/skill-novelty.md says a request object has no key besides `query` and `acceptable`, and that `catalog routing-compare --out` creates a missing parent directory, as `catalog routing --out` does. A test reads the `gold only` line of the summary: printed for a comparison with alternatives, absent for one without. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@vchamarthi (#915 (review)): On the open question: kept the |
|
Ready for another look at Declined, with the evidence in the reply:
|
vchamarthi
left a comment
There was a problem hiding this comment.
🟢 Approved · re-reviewed 7995f58
Next: nothing required from @antonwolfy. 1 nit optional.
Verified on 7995f58: ✅ changed tests: 66 passed, fail on main · ✅ full suite with main merged in: 23677 passed · ✅ merges onto main · ✅ 12 broken variants of the changed code: 12 caught by the tests · 1 mutation tried · 8 edge inputs tried
10 checks behind it, each with its evidence
| Area | What holds | How |
|---|---|---|
| Changed tests | The changed test files pass on the head: 66 tests in tests/test_catalog_routing_compare.py and tests/test_novelty_routing_acceptable.py |
tests on the head |
| Changed tests on main | The same two test files fail on main at collection, since dokimi.novelty.routing_compare and check_acceptable do not exist there |
same tests on main |
| Null result | "result": null as BASE is refused naming the file and the result object is missing, as the check at dokimi/dokimi/novelty/routing_compare.py:49-50 does |
ran it, edge input (none) |
| Malformed run files | {}, [], a truncated object, an empty file and a result of {} are each refused naming the file and the cause |
ran it, edge input (structured) |
| Encoding | A run file with bytes that are not UTF-8 is refused naming the file, and a file with a byte order mark and CRLF line endings loads | ran it, edge input (text) |
| Empty collection | A result holding an empty lexical object is refused naming the missing lexical.per_query rows |
ran it, edge input (collections) |
| --out and missing paths | --out into a directory that does not exist writes the comparison, and a missing BASE is refused naming the path |
ran it, edge input (paths) |
| Exit code | catalog routing-compare with a missing BASE exits 2 and prints missing.json: cannot read on stderr |
ran it, edge input (cli) |
| Query object keys | A query object with query and acceptable loads with its alternatives, and an extra key is refused naming the key, as docs/skill-novelty.md now says |
ran it, edge input (structured) |
| Gold only line | Negating if scoring == "gold_or_acceptable": at dokimi/dokimi/commands/routing_compare.py:80 fails the changed tests, so the new test pins the line |
broke the code, tests caught it |
…t an object Settles the review nit on routing_compare.py:50: `"result": []` was reported as a missing `result` object although the key is present. The message now reads "the `result` object is missing or not an object", and the refusal test gains the `[]` case. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@vchamarthi (#915 (review)): Approval with one optional nit; it is the thread above (4621804247), settled in 5ccbed7. |
… limit and a model row with no picks list A saved run holding an integer past Python's digit limit made json.loads raise a plain ValueError that neither handler caught, so the command ended in a traceback. The reader now turns it into a RoutingInputError naming the file, and the JSON read moves into its own helper to keep load_run under the complexity cap. A model row whose `picks` is missing or null was read as an unanswered call and silently dropped from the counts. Only a list of strings is accepted now; an empty list stays an unanswered call. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
Summary
#710 asks for two optional parts of the all-vs-all routing measurement, left out of the #678 fix because they are features. On
main(the command iscatalog routingnow; #595 is merged andnovelty routing --all-vs-allis retired):maintoday--queries-by-skilltakes a list of strings per skill, so the second skill's pick counts as a miss and an attractor:{"a": [{"query": "tune b things", "acceptable": ["b"]}]}is refused withthe queries for 'a' must be a list of stringslexical.per_queryandmodel.noise.per_queryhold the rows (#711), but comparing them query by query is left to a scriptOption taken for the queries file: extend it backward-compatibly, since a request may be a plain string or an object
{"query": "...", "acceptable": ["<other skill>", ...]}; a file of strings reads and saves as before (no new key is written). The comparison is a new leaf,catalog routing-compare BASE.json OTHER.json, besidecatalog routing, because the two parts share one saved shape.Closes #710
Changes
dokimi/novelty/all_vs_all.py:load_queries_with_acceptablereturns thedict[str, list[str]]of queries together with an acceptable map;load_queries_by_skillkeeps itsdict[str, list[str]]return. An object without a stringquery, anacceptablethat is not a list of strings or an unknown key is refused naming the file, the skill and the query; the gold named as its own alternative is dropped by the loader when it reads the file, andkept_alternatives, whichall_vs_allandcheck_acceptablecall, leaves the gold out of the names it keeps, so a directall_vs_all(..., acceptable=)call never counts a gold pick as an acceptable hit as well; a blankqueryis dropped with its object.check_acceptablerefuses an acceptable name that is not in the field (skill, query and name named); the alternatives of a skill the field leaves out are moot, since its queries are dropped.all_vs_all(..., acceptable=)addsacceptable_rateper gold skill besideown_ratein both arms, only when the file names an alternative (same scored denominator;(none),(tie)and a failed call never count; the model arm counts per call).confusionandattractorsstill follow the gold alone. Rows of a query with alternatives keepacceptable(lexical.per_query,model.noise.per_query); other rows do not get the key.commands/novelty.py,commands/novelty_routing_report.py: the command loads the map, checks it before--estimate-onlytoo, and the summary prints the pooled gold and gold-or-acceptable counts per arm, fromconfusionand a new exact per-goldacceptable_picks, not from the rounded rates (1 hit in 30000 scored queries prints as 1, not 0).dokimi/novelty/routing_compare.py,dokimi/commands/routing_compare.py:catalog routing-compare BASE OTHER [--arm lexical|model] [--out FILE]pairs rows by(gold, query), makes no model call, and reports each run's number right, the discordant counts, the exact two-sided sign test (exact_binomial_two_sided, 1.0 with no discordant pair) and the queries whose pick changed. The sign test counts distinct(gold, query)queries, not pairs: a request listed twice is one query (discordant_queriesin the JSON;discordantkeeps the pair counts), so six copies of one request, right in BASE and wrong in OTHER, give p = 1.0, not 0.03125. Every row is checked on load:queryandgoldstrings,acceptablea list of strings, for the lexical armrankpresent and null or a positive integer andpickeda string whenrankis set (a null rank and the picks(none)and(tie)are kept), and for--arm modelpicksa list of strings; a row of another type is refused naming the file and the row number, and amodelsection of the wrong type no longer stops a lexical comparison. A query in one run only is counted and shown by example; a row with no content word, a model query with no answered call or with no unique modal pick (--reps) is left out and counted. When both runs name the sameacceptablefor a pair, right means gold or acceptable; otherwise that pair is scored on the gold alone and a note says so. A file that is not JSON, notmode: all_vs_all, or without per-query rows (saved before feat(novelty): all-vs-all routing keeps a row per query for the lexical arm #711) is refused naming the file and the cause, as is--arm modelfor a run without a model arm and two runs with no pair in common (exit 2).commands/catalog.pyandcli_routes.py(a free leaf);docs/reference/cli-interface.jsonregenerated withmake cli-snapshot;docs/skill-novelty.mddocuments the file shape,acceptable_rateand the compare command.Risk
None for existing files: a queries file of strings gives the same loader result and the same saved result (pinned by a test comparing the two). A queries file that was refused before (an object in a list) is read now. The comparison
--outis plain JSON with no schema, likecatalog routing --out.--armis the existing canonical spelling of the flag registry; here it names a routing arm, not a subject variant. Open PRs that add catalog leaves or flags (#838, #840, #841, #846, #849) also editcli_routes.py,commands/catalog.pyanddocs/reference/cli-interface.json, so a merge meets textual conflicts in those one-line additions; the snapshot is regenerated withmake cli-snapshotafter either merges. No open PR changesnovelty/all_vs_all.py.Testing
On a Linux review host, at
0fc5618(onmaind4023b9):make ci-local: 36 passed, 0 failed, 14 skipped (docker and network smoke, other Python legs, conda-forge, fuzz, semgrep, jobs that do not run on a PR). 23610 tests passed, 19 skipped.tests/test_novelty_routing_acceptable.py(21) andtests/test_catalog_routing_compare.py(45), including the sign-test counterexamples (5 against 0 of 10 pairs gives p = 0.0625, 6 against 0 gives 0.03125) and an end-to-end run from two files the realall_vs_allwrote with a stub selector. Onmain's code (with the new loader names stubbed as the old loader and a no-op check) the first file gives 17 failed, 1 passed (the one that passes pins that a file of strings gives noacceptablekey). For the second,main's copy gets stubrouting_comparemodules with the real names and signatures that answer wrongly (a comparison of 0 paired queries, no discordant pairs, p 1.0, no changed picks; a command that exits 0 and prints nothing): 24 failed, each on a value or a refusal that did not happen, the first beingassert 0 == 10onn_pairedof the 5-against-0 case.ownandeithercounts (30000 scored queries, one gold hit, one acceptable hit), the sign test over pairs instead of distinct queries, the net sign of a repeated request, theacceptableandpicksrow checks, the model-section guard, the cap on listed changes, the unwritable--out, the too-deeply-nested file and the no-scored-query line.kept_alternatives(both arms double-count it), thepickedcheck and the missing-rankcheck of a lexical row, and theRecursionErrorhandler ofload_run. The too-deeply-nested test makesjson.loadsraiseRecursionError, because an unterminated run of[raises a JSON error on Python 3.14 instead.resultis null or missing is refused with "theresultobject is missing" rather than as a wrong mode ({"mode": "all_vs_all", "result": null}and a file with noresult), and thegold only: BASE n, OTHER mline of the summary is printed for a comparison with alternatives and absent for one without.docs/skill-novelty.mdnow says a request object has no key besidesqueryandacceptable, and thatrouting-compare --outcreates a missing parent directory, ascatalog routing --outdoes (the end-to-end test writes--outinto a directory that does not exist).resultis present but not an object ({"mode": "all_vs_all", "result": []}) is refused with "theresultobject is missing or not an object"; restoring the old "is missing" wording fails the threeresultrefusal cases.json.loadsraise a plainValueError) is refused with "not JSON this reader accepts" naming the file instead of a traceback, and a model row whosepicksis null or missing is refused as "picksis not a list of strings" while an empty list stays an unanswered call. Dropping theValueErrorhandler fails the first, and accepting a nullpicksfails the two model cases.semgrep.Open questions
None.
Revert
A plain revert restores the old loader and removes
catalog routing-compare. Nothing is stored: a saved run that hasacceptable_rateoracceptablekeys keeps them, and is still read by every reader that ignores unknown keys.Checklist
pytestpassesruff,mypy, and schema checks passAGENTS.mdraise/exit and test names the doc, contract or issue it traces to.github/.licenserc.yaml)