Repository navigation
feat(matching): measure how loud a model actually is, and record that the compiler only assumes - #604
Merged
Merged
Conversation
… the compiler only assumes `er-compile` builds a model from a config with no training behind it, so it has to assume how much evidence a field at full agreement contributes: `DEFAULT_FULL_AGREEMENT_BITS = 60.0`. That number is well earned — its doc comment records the derivation, and summing the committed PERSON reference model's exact-level Bayes factors reproduces it to 59.883 bits. Nothing could measure the same quantity on a trained model, so nothing could tell a tenant whether 60 fits their corpus. `TrainedModel::full_agreement_bits` does: per field the strongest non-null level, resolved through the same `level_m_u` path the scorer uses, summed. It also gives the implied bits per field, which is how the model ranks its own evidence — measured, rather than declared through weights. Three corpora, measured with it: person reference model (model_test_v1) 59.883 bits over 6 comparisons fake_1000 trained model (model_final) 31.035 bits over 5 account reference model (acct_model_v1) 21.812 bits over 4 The compiler assumes 60 for all three. `compile_with` never consults `config.entity_type`, and the only production entry point is `compile`, which passes `CompileOptions::default()` — so an account config is compiled roughly 2.7x louder than its own reference model, in the direction the constant's own doc comment calls the more expensive mistake: "louder is not safer. Over-weighting trades missed duplicates for false merges." There was no account coverage anywhere in the compile tests, and no account config fixture. Deliberately a measurement and NOT a re-tuning. The person number earned its value from two independent legs — the reference-model sum and a cluster-count grid search over base_10, where 20 bits found 18 clusters for 10 and 120 bits found 9 — and only the first leg can be run for accounts today: no account config fixture, no account corpus with a known cluster count. Setting the account default to 22 would swap one uncalibrated number for another and move every account tenant's scoring. So the gap is recorded with evidence attached and left as a decision. What ships instead: - `TrainReport.full_agreement_bits` + `bits_per_field`, and `scale_divergence()`, which reports the compiled assumption when the measured scale is more than 2x away either way. The factor is taken from that same grid search rather than invented: inside a factor of two nothing went wrong, and both observed failures were two to three times out. - the three surfaces the convergence report already uses — the train task's counters, `er train`'s summary (always, not only on divergence, so a drift over time is visible), and a stderr warning - a `Compiled.notes` entry naming the scale it assumed, because the assumption is otherwise invisible: the saved model carries m/u values with no trace of the number they came from, and two tenants' models look independent when both inherited one global default - `score_scale_calibration.rs`, which pins the person derivation, the account gap as a bound rather than a point, and — by compiling one config twice with only `entity_type` changed — that the scale is entity-blind The Rust measurement was cross-checked against an independent computation straight off the fixture JSON: 59.883 and 21.812 both ways. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
athvin
added a commit
that referenced
this pull request
Nov 6, 2026
…ibration is now a gate (#623) 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: bmoore813 <[email protected]> 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.
er-compilebuilds a model from a config with no training behind it, so it has to assume how much evidence a field at full agreement contributes:DEFAULT_FULL_AGREEMENT_BITS = 60.0.That number is well earned. Its doc comment records the derivation, and measuring the committed person reference model reproduces it almost exactly — 59.883 bits.
But nothing could take the same measurement on a trained model, so nothing could tell a tenant whether 60 fits their corpus.
TrainedModel::full_agreement_bitsdoes: per field the strongest non-null level, resolved through the samelevel_m_upath the scorer uses, summed. It also yields the implied bits per field — how the model ranks its own evidence, measured rather than declared through weights.Three corpora, one constant
model_test_v1)fake_1000trained (model_final)acct_model_v1)The compiler assumes 60 for all three.
compile_withnever consultsconfig.entity_type, and the only production entry point iscompile, which passesCompileOptions::default()— so an account config is compiled roughly 2.7x louder than its own reference model, in the direction the constant's own doc comment calls the more expensive mistake:There was no account coverage anywhere in the compile tests, and no account config fixture.
Deliberately a measurement, not a re-tuning
The person number earned its value from two independent legs — the reference-model sum and a cluster-count grid search over
base_10, where 20 bits found 18 clusters for 10 and 120 bits found 9. Only the first leg can be run for accounts today: there is no account config fixture and no account corpus with a known cluster count.Setting the account default to 22 would swap one uncalibrated number for another and move every account tenant's scoring. So the gap is recorded with its evidence and left as a decision.
What ships
TrainReport.full_agreement_bits+bits_per_field, andscale_divergence(), which names the compiled assumption when the measured scale is more than 2x away either way. The factor comes from that same grid search rather than being invented: inside a factor of two nothing went wrong, and both observed failures were two to three times out.full_agreement_bits,bits_per_field,assumed_scale_diverges),er train's summary — always, not only on divergence, so a drift over time is visible — and a stderr warning.Compiled.notesentry naming the scale it assumed, because the assumption is otherwise invisible in the artifact: the saved model carries m/u values with no trace of the number they came from, and two tenants' models look independent when both inherited one global default.score_scale_calibration.rs, which pins the person derivation, the account gap as a bound rather than a point (so it needn't be re-tuned when the reference model is retrained), that each field's strongest level is its exact match — which is what makes this the same quantity the constant was calibrated from — and, by compiling one config twice with onlyentity_typechanged, that the scale is entity-blind.Verification
make checkgreen from the repo root — 832 tests, 0 failures; entities current, skills-check ok.The Rust measurement was cross-checked against an independent computation straight off the fixture JSON: 59.883 and 21.812 both ways. The
scale_divergencetest pins both directions and the quiet band, using the two real measurements as its cases (31.0 → quiet, 21.8 → reported), plus the0.0pre-measurement value, so a run that failed before training cannot fire the warning.Builds on #596 (which predicts unmeasurable
exactlevels from the profile) and #598 (which reports which parameters training did not measure).full_agreement_bitsresolves through defaults, sodefaulted_levelsis how you tell which of the total is measurement and which is assumption.🤖 Generated with Claude Code