Repository navigation
feat(matching): a config can declare its own score scale, and the calibration is now a gate - #623
Merged
Merged
Conversation
…ibration is now a gate Two halves of the same gap, both about the constant every compiled model's m/u values derive from. **1. The scale was global in practice, however corpus-dependent it said it was.** `CompileOptions`' own doc comment says the two knobs "are options rather than constants because the right scale depends on how dirty the corpus is", and `compile_with` exists so a caller can supply them. Nothing in production ever called it: `compile` passed `CompileOptions::default()` unconditionally, so every tenant inherited a number calibrated on the committed PERSON reference model — which measures 59.9 bits, against the committed ACCOUNT model's 21.8. `thresholds.full_agreement_bits` and `thresholds.disagreement_ratio` are now optional config fields, and `compile` reads them. This is the third step of measure -> report -> act: #604 measured what a corpus supports (`TrainReport::full_agreement_bits`) and reported it; this is where that measurement can be used. Beside `thresholds` rather than in a block of its own, because a threshold is meaningless without the scale it is measured on — `auto_merge: 20` means "most of the evidence" at a 22-bit scale and "a third of it" at 60. It also keeps `CONFIG_BLOCKS` untouched. Absent means today's default, and `skip_serializing_if` is load-bearing for the reason `entity_type`, `approval` and `models` each carry it: the canonical document feeds `config_hash`, so an absent value serialises to nothing and every existing tenant's hash — and every committed golden — stays byte-identical. Asserted directly, both ways: absent does not appear in the canonical document, declared does move the hash, and each half moves it independently. A declared scale is bounds-checked and refused rather than clamped, as `CompileError::ScaleOutOfRange`, next to the `WeightOutOfRange` precedent and surfacing through the publish handler that already compiles. Both failure modes are silent in the OUTPUT, which is why refusal is right: at zero bits no pair accumulates enough evidence and the run reports "no duplicates" rather than a miscalibration, and at a negative value agreement becomes evidence AGAINST a match so the model works backwards while still producing scores that look like scores. The boundary values that are extreme but meaningful still compile. `Compiled.notes` now says whether the scale was declared or inherited, because a reader of a compiled model otherwise cannot tell a deliberate scale from a default, and those warrant different amounts of trust. **2. The calibration was prose. Now it is a gate.** `DEFAULT_FULL_AGREEMENT_BITS`' comment records the experiment behind it: "at 20 bits the compiled model finds 18 clusters where there are 10 ... and at 120 bits it finds 9 ... 55-60 bits reproduces the committed membership exactly." No committed test reproduced any of it. The experiment was run once by hand and written into prose, so the number every compiled model depends on was protected by nothing — changing it to 120 "to be safe" would have passed every gate while silently merging distinct people, the failure the comment itself calls the more expensive one. Now that `compile` reads the config, the grid is three ordinary resolves, and it reproduces the comment EXACTLY: truth = 10 default(60) = 10 quiet(20) = 18 loud(120) = 9 The exact counts are pinned rather than the direction, because those are the numbers the comment states and this test exists to be their gate; a failure means the calibrating evidence moved and the comment needs the new measurement, not that the assertion needs loosening. ~60s in the DuckLake tier, which is the right price for the only evidence behind the scale. This is also the harness the account question needs. Answering it still needs an account corpus with a known entity count — `acct_base` has 7 records and 4 entities but no `truth.csv` and no traps, where `base_10` has both — so the account scale stays recorded rather than re-tuned. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Two halves of the same gap, both about the constant every compiled model's m/u values derive from. Plus the two remaining design items, recorded as declines with reasons.
1. The scale was global in practice, however corpus-dependent it said it was
CompileOptions' own doc comment says the knobs "are options rather than constants because the right scale depends on how dirty the corpus is", andcompile_withexists so a caller can supply them. Nothing in production ever called it —compilepassedCompileOptions::default()unconditionally, so every tenant inherited a number calibrated on the committed person reference model (59.9 bits) including account tenants whose own reference model measures 21.8.thresholds.full_agreement_bitsandthresholds.disagreement_ratioare now optional config fields andcompilereads them. This is the third step of measure → report → act: #604 measured what a corpus supports and reported it; this is where that measurement can be used.Beside
thresholdsrather than in a new block, because a threshold is meaningless without the scale it is measured on —auto_merge: 20means "most of the evidence" at a 22-bit scale and "a third of it" at 60. It also leavesCONFIG_BLOCKSuntouched.Hash stability is the safety claim, and it is asserted directly rather than assumed: absent values do not appear in the canonical document, a declared value does move
config_hash, and each half moves it independently.skip_serializing_ifis load-bearing for the reasonentity_type,approvalandmodelseach carry it — so every existing tenant's hash, and every committed golden, stays byte-identical.A declared scale is refused rather than clamped, as
CompileError::ScaleOutOfRange, beside the existingWeightOutOfRangeprecedent and surfacing through the publish handler that already compiles. Both failure modes are silent in the output, which is why refusal is right: at zero bits no pair accumulates enough evidence and the run reports "no duplicates" rather than a miscalibration; at a negative value agreement becomes evidence against a match, so the model works backwards while still producing scores that look like scores. Boundary values that are extreme but meaningful still compile.Compiled.notesnow says whether the scale was declared or inherited — a reader of a compiled model otherwise cannot tell a deliberate scale from a default, and those warrant different trust.2. The calibration was prose. Now it is a gate.
DEFAULT_FULL_AGREEMENT_BITS' comment records the experiment behind it: "at 20 bits the compiled model finds 18 clusters where there are 10 … and at 120 bits it finds 9 … 55–60 bits reproduces the committed membership exactly."No committed test reproduced any of it. The experiment was run once by hand and written into prose, so the number every compiled model depends on was protected by nothing — changing it to 120 "to be safe" would have passed every gate while silently merging distinct people, the failure the comment itself calls the more expensive one.
Now that
compilereads the config, the grid is three ordinary resolves. It reproduces the comment exactly:The exact counts are pinned rather than the direction, because those are the numbers the comment states and this test exists to be their gate. A failure means the calibrating evidence moved and the comment needs the new measurement — not that the assertion needs loosening. ~60s in the DuckLake tier, which is the right price for the only evidence behind the scale.
This is also the harness the account question needs. Answering it still needs an account corpus with known truth:
acct_basehas 7 records and 4 entities but notruth.csvand notraps.csv, wherebase_10has both. Seven trap-free records would look like evidence while being weak, so the account scale stays recorded rather than re-tuned. I also corrected the module comment that claimed no account fixture exists — one does, underer-standardize.3. The last two design items, recorded as declines
Neither is built, and both now say why where an implementer would look:
training.deterministic_rules) —dedupe-core/src/training/mod.rs. Three paths tomalready cover the ground,prioralready consumes those same rules, and the diagnostic it was wanted for arrived asfull_agreement_bits+defaulted_levels. Worth revisiting only as a test if EM'smis ever shown wrong on a real corpus.er-cli/src/profile.rs. It belongs besidemetric_snapshot.largest_group, which is already the headline of that distribution. A profile is one row per column plus run-level scalars; a histogram is neither, and putting it here would split one concept across two tables written by different stages.Verification
make checkgreen on the rebased state — 854 tests, 0 failures. The grid-search test run separately withDEDUPE_E2E_DUCKLAKE=1(it self-skips otherwise): passes in ~60s.cargo doc -D warningsclean.🤖 Generated with Claude Code