Skip to content

feat(matching): a config can declare its own score scale, and the calibration is now a gate - #623

Merged
athvin merged 1 commit into
mainfrom
bm/configurable-score-scale
Nov 6, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/configurable-score-scale

Conversation

@athvin

@athvin athvin commented Nov 5, 2026

Copy link
Copy Markdown
Owner

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", 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 (59.9 bits) including account tenants whose own reference model measures 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 and reported it; this is where that measurement can be used.

Beside thresholds rather than in a new block, 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 leaves CONFIG_BLOCKS untouched.

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_if is load-bearing for the reason entity_type, approval and models each 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 existing 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; 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.notes now 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 compile reads the config, the grid is three ordinary resolves. 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 known truth: acct_base has 7 records and 4 entities but no truth.csv and no traps.csv, where base_10 has 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, under er-standardize.

3. The last two design items, recorded as declines

Neither is built, and both now say why where an implementer would look:

  • A fourth m estimator (from training.deterministic_rules) — dedupe-core/src/training/mod.rs. Three paths to m already cover the ground, prior already consumes those same rules, and the diagnostic it was wanted for arrived as full_agreement_bits + defaulted_levels. Worth revisiting only as a test if EM's m is ever shown wrong on a real corpus.
  • The cluster-size distribution — er-cli/src/profile.rs. It belongs beside metric_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 check green on the rebased state — 854 tests, 0 failures. The grid-search test run separately with DEDUPE_E2E_DUCKLAKE=1 (it self-skips otherwise): passes in ~60s. cargo doc -D warnings clean.

🤖 Generated with Claude Code

…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-bus eligible for the merge bus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants