Skip to content

feat(match): rarity-weighted, fuzzy, combination-aware term scorer (A4/A10)#25

Merged
officialCodeWork merged 1 commit into
developmentfrom
build/phase-4/step-4.1-term-matching
Jul 14, 2026
Merged

feat(match): rarity-weighted, fuzzy, combination-aware term scorer (A4/A10)#25
officialCodeWork merged 1 commit into
developmentfrom
build/phase-4/step-4.1-term-matching

Conversation

@officialCodeWork

Copy link
Copy Markdown
Owner

Step 4.1 — Term matching v2 (opens Phase 4)

Failure modes A4 / A7 / A10. matchComponentsByText is now a real scorer over rendered text instead of raw overlap.

  • Rarity weighting (IDF) — a term's weight is its inverse document frequency across the graph. A lone "Save" (in every form) ties → honest ambiguous; one distinctive term ("Card number") dominates → ok.
  • Fuzzy tokens — long tokens match within a small, length-scaled edit distance, so OCR slips ("Acount Reconcilliation") still land the right component. Short common tokens stay exact (save ≠ safe), so noise can't collide unrelated matches.
  • Combination bonus — several distinct terms co-occurring in one component outrank the same terms scattered across many.
  • Order-sensitive phrases"Order deleted" ≠ "Delete order" (a bag-of-tokens bug the a9 fixture caught). Match evidence keeps its i18n-key / branch provenance.

New primitives

editDistance (bounded Levenshtein), fuzzyTokenMatch, tokenize in core text utils. Eval harness gains GoldenQuery.topK — the honest top-3 bar for OCR-noisy input.

Eval

Fixture a10-ocr-noise: four components with distinctive long words; misspelled OCR queries resolve to the right component (top-1, well within top-3). a4 (generic "Save") stays green.

Verification

  • 36 core + 92 parser tests pass (7 new matcher/text tests).
  • pnpm eval: green, precision/recall 1.000, match accuracy 1.000.

🤖 Generated with Claude Code

…4/A10)

Replace matchComponentsByText with a real scorer (TRACKER step 4.1):

- Rarity weighting: each term's weight is its inverse document frequency across
  the graph, so a lone "Save" (everywhere) ties → honest `ambiguous`, while one
  distinctive term ("Card number") breaks the tie → `ok`.
- Fuzzy tokens: long tokens match within a small, length-scaled edit distance,
  so OCR slips ("Acount Reconcilliation") still land the right component; short
  common tokens stay exact so noise can't collide unrelated matches.
- Combination bonus: several distinct terms co-occurring in one component
  outrank the same terms scattered across many.
- Order-sensitive phrase matching: "Order deleted" no longer equals
  "Delete order" (a bag-of-tokens bug caught by the a9 fixture). Match evidence
  keeps its i18n-key / branch provenance.

New text utils: editDistance (bounded Levenshtein), fuzzyTokenMatch, tokenize.
Eval harness gains GoldenQuery.topK (the honest top-3 bar for OCR). Fixture
a10-ocr-noise (misspelled distinctive text → correct top-1). 36 core + 92 parser
tests pass; eval green (precision/recall 1.000, match accuracy 1.000).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@officialCodeWork
officialCodeWork merged commit 5d5bb58 into development Jul 14, 2026
1 check passed
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