Skip to content

fix(matching): tf: true with no exact level published fine and failed every run - #616

Merged
athvin merged 1 commit into
mainfrom
bm/tf-exact-level-gate
Nov 5, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/tf-exact-level-gate

Conversation

@athvin

@athvin athvin commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Term-frequency adjustment scales against the exact-match level's u probability. er-compile attaches the adjustment to a comparison's first declared level whenever tf: true, without requiring that level to be an exact match — and at scoring time scoring::u_probability_for_tf_base searches for a sibling level that is an exact match on exactly the TF column, and errors when there is none.

Nothing checked for one: not er-config, not config_check, not the compiler.

Proven before fixing

Against the committed fixture with given_name's exact level removed and its tf: true left in place:

config_reference_problems  ->  []            (publish allowed)
er_compile::compile        ->  Ok            (compiles cleanly)
match_weight_parts_sql     ->  Err("comparison 'given_name': tf adjustment on level
                               'jaro_winkler_similarity(...) >= 0.9' requires an
                               exact-match level on column 'given_name'")

So a tenant could publish a config that failed the scoring stage on every subsequent run. It is the same shape as the constraint-column hole directly above the new check, whose own comment is the better description: the run failed "loudly, but minutes later and inside the tenant's pipeline rather than at the publish that introduced it."

Why only exact qualifies

Every other comparator either is not an equality (variant_match, jaro_winkler:, levenshtein:) or compares a derived expression rather than the bare columns (username_exact, domain_exact, first_n:, dob_same_year_month), and exact_match_columns detects only an equality of two bare columns. The engine's escape hatch, disable_tf_exact_match_detection, is not reachable from a tenant config.

All eight committed configs that set tf: true already declare exact first, so the refusal rejects nothing that exists.

The regression test keeps the proof in two parts: one asserts the publish refusal, and a second compiles the bad config and asserts the engine's own error. The second is the positive control for why the gate exists — if u_probability_for_tf_base ever grows a fallback, the refusal becomes over-strict and that test says so.

The advisory this started out as

profile_advisories now recommends tf: true where it would change scores materially. The spread is taken from the scoring SQL rather than from the idea of TF:

weight * ( log2(u_exact) - log2(greatest(tf_l, tf_r, minimum_u_value)) )

so a value of relative frequency p is adjusted by weight * log2(u_exact / p), and comparing the commonest value against a typical one gives weight * log2(n_max / n_avg). u_exact cancels, which is what makes it answerable from a profile alone — no estimate of the collision probability needed, only two counts the profile already has.

It is a skew, not a span — and two existing tests are why

The first draft compared the mode against a hypothetical one-off, giving log2(n_max). That grows with the corpus: it fired on a column whose commonest value covered 2% of a 100,000-row table, and would have fired on nearly every column in any large corpus. Measuring against the average frequency instead is scale-free, and it asks the question that actually decides the matter — on a uniform column TF shifts every value by the same amount and discriminates nothing. A regression test uses the numbers that exposed it.

Two refusal wrappers corrected

The publish path said "config references columns the standardized schema does not have". That already misdescribed the ensemble and survivorship checks and would have misdescribed this one — a reader goes hunting for a typo that is not there. Both wrappers now say what they actually reject and let each problem speak for itself. Nothing asserted the old wording.

Verification

make check green from the repo root — 838 tests, 0 failures; entities current, skills-check ok. config_check is at 35 tests, up from 29. Re-verified after rebasing onto a main that had moved 8 commits: entity verify clean, config_check 35/35, er-compile 17/17.

🤖 Generated with Claude Code

…ed every run

Term-frequency adjustment scales against the exact-match level's u probability.
`er-compile` attaches the adjustment to a comparison's FIRST declared level
whenever `tf: true`, without requiring that level to be an exact match, and at
scoring time `scoring::u_probability_for_tf_base` searches for a sibling level
that is an exact match on exactly the TF column and errors when there is none.

Nothing checked for one — not `er-config`, not `config_check`, not the
compiler. Proven end to end before fixing, against the committed fixture with
`given_name`'s exact level removed and its `tf: true` left in place:

  config_reference_problems  ->  []                      (publish allowed)
  er_compile::compile        ->  Ok                      (compiles cleanly)
  match_weight_parts_sql     ->  Err("comparison 'given_name': tf adjustment
                                 on level 'jaro_winkler_similarity(...) >= 0.9'
                                 requires an exact-match level on column
                                 'given_name'")

So a tenant could publish a config that failed the scoring stage on every
subsequent run. The same shape as the constraint-column hole directly above the
new check, whose comment is the better description: the run failed "loudly, but
minutes later and inside the tenant's pipeline rather than at the publish that
introduced it".

Only the `exact` token qualifies as the base. Every other comparator either is
not an equality (`variant_match`, `jaro_winkler:`, `levenshtein:`) or compares
a derived expression rather than the bare columns (`username_exact`,
`domain_exact`, `first_n:`, `dob_same_year_month`), and `exact_match_columns`
detects only an equality of two bare columns. The engine's escape hatch,
`disable_tf_exact_match_detection`, is not reachable from a tenant config. All
eight committed configs that set `tf: true` already declare `exact` first, so
the refusal rejects nothing that exists.

The regression test keeps the proof: one case asserts the publish refusal, and
a second compiles the bad config and asserts the engine's own error, which is
the positive control for why the gate exists — if `u_probability_for_tf_base`
ever grows a fallback, the refusal becomes over-strict and that test says so.

Alongside it, the advisory this started out as: `profile_advisories` now
recommends `tf: true` where it would change scores materially. The spread comes
from the scoring SQL rather than from the idea of TF —

    weight * ( log2(u_exact) - log2(greatest(tf_l, tf_r, minimum_u_value)) )

so a value of relative frequency p is adjusted by weight * log2(u_exact / p),
and comparing the commonest value against a typical one gives
weight * log2(n_max / n_avg). `u_exact` cancels, which is what makes it
answerable from a profile alone.

It is a SKEW and not a span, and two existing tests are why. The first draft
compared the mode against a hypothetical one-off, giving log2(n_max), which
grows with the corpus: it fired on a column whose commonest value covered 2% of
a 100,000-row table and would have fired on nearly every column in any large
corpus. Measuring against the average frequency is scale-free and asks the
question that decides the matter — on a uniform column TF shifts every value by
the same amount and discriminates nothing. A regression test uses the numbers
that exposed it.

Also corrects the two refusal wrappers. The publish path said "config
references columns the standardized schema does not have", which already
misdescribed the ensemble and survivorship checks and would have misdescribed
this one; a reader goes looking for a typo that is not there. Both now say what
they actually reject and let each problem speak for itself.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@athvin
athvin merged commit 2aaa19f into main Nov 5, 2026
39 checks passed
@athvin
athvin deleted the bm/tf-exact-level-gate branch November 5, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants