Repository navigation
perf(recall): split identifiers in the matcher tokenizer (#409) - #417
Conversation
…83025 — a re-run reverted the summary header (cherry picked from commit 0c2edc9d0e3e328ddecdb21aed5fabba6d9ac28c)
words() lowercased and split on [^a-z0-9_]+, so getUserAccount, get_user_account and get-user-account were three unrelated tokens and a memory citing a dotted config key or a path shared nothing with a session that typed it. Split camelCase boundaries, _, ., / and - first. Measured on the shipped scorer over the bench fixture (store 200, kw, limit 5): r1 69, top-3 70, any@5 71 of 105 — identical to main — while wrong rows returned for no-gold queries fall 0.16 -> 0.12 (0.60 -> 0.44 rows per call). The published bench is unchanged in aggregate (prod 50/50, prod+kw 66/67 at store 200), the lexical class moves 98% -> 100% and top-1 noise 6% -> 5%. Replayed over 1,091 logged recall queries against the live store, 92.3% of top-5 sets are identical and 97.5% keep their top row. The stemming half of the tokenizer lane is deliberately excluded: it finds 5 more golds but costs 0.84 wrong rows per call.
The first version split identifiers and discarded the whole form, which
broke two things the shipped tokenizer provided:
- exact identifier queries abstained: words('db_id') and words('no_op')
returned empty, because the split fragments fall under the 3-character
floor. A query for those identifiers now matches the row that cites
them.
- authored keywords are stored lower-cased and fused by
normalizeKeywords, so a camelCase alias like memoryRecallThreshold was
stored as memoryrecallthreshold and a split query could never match
it - breaking the write-time vocabulary bridge the keyword exists for.
The whole lower-cased form is emitted again, and a test pins it.
Each identifier now emits both granularities: the whole form (exact
match, as shipped) and camel/separator segments (cross-spelling match).
The scan is a single linear pass with no backtracking; a test bounds
the cost on 4,000-character adversarial rows.
Bench control arms (naive, bm25, the query-class classifier) now carry
a frozen copy of the legacy tokenizer: a tokenizer change silently
redefined the published baselines.
Re-measured on the SHIPPED arm (kw indexed): lexical R@1 stays 98% and
top-1 noise stays 6% - the fixture contains no query that spells an
identifier differently from the memory, so this is a correctness fix
the fixture cannot price. The no-kw arm moves 98% -> 100% but
production indexes keywords. The previously claimed 0.60 -> 0.44
no-gold improvement is not reproducible from any committed artifact and
has been removed.
|
Rework pushed ( The review's two blocking regressions are fixed and pinned by tests: Honest re-measurement on the shipped arm ( |
The 40 ms budget tripped at 42 ms on the CI runner. Measured locally, 20 calls on a 4,000-character uppercase row cost 14.6 ms with the linear scan and 204 ms with the regex chain it replaced, so 200 ms keeps the test blind to runner speed while still failing by an order of magnitude if backtracking ever comes back.
WhollyMindless
left a comment
There was a problem hiding this comment.
Two retrieval regressions remain in the revised tokenizer, reproduced against this head and the unchanged base scorer on Windows Bun 1.4.4; details inline. The existing focused tests pass. Disclosure: I contributed earlier code in the base; these probes review the maintainer-authored tokenizer delta, not an independent approval of my own work.
| .split(/[^a-z0-9_]+/) | ||
| .filter((t) => t.length > 2); | ||
| const out: string[] = []; | ||
| const ids = text.match(/[A-Za-z0-9_.\-/]+/g); |
There was a problem hiding this comment.
[P2] Preserve underscore identifiers next to sentence punctuation. A settled learning row in scope api with content Join on db_id. is retrieved by scoreMemories("db_id", [row], 3) on the base, but returns [] here. This regex absorbs the final period into db_id.; splitting then discards both short segments, so db_id never enters the row vocabulary. The added exact-identifier test puts the identifier mid-sentence and misses this common case. Please preserve the legacy underscore token when punctuation surrounds it, and cover the sentence-ending case.
There was a problem hiding this comment.
Agreed and fixed in 359428b. The whole-identifier form is now edge-trimmed (Join on db_id. carries db_id); interior separators stay, underscore included. Pinned with the sentence-ending case you named.
| const flush = () => { | ||
| if (cur.length > 2) { | ||
| const seg = cur.toLowerCase(); | ||
| if (seg !== whole) out.push(seg); // single words emit once, as before |
There was a problem hiding this comment.
[P2] Keep a fused keyword sufficient for its original identifier query. With a settled learning row in scope api, content Controls admission of weak matches, and kw: ["memoryrecallthreshold"], scoreMemories("memoryRecallThreshold", [row], 3) returns the row on the base and [] here. Emitting the whole form plus three segments raises query.size to four, so the unchanged admission gate requires two matches; the fused alias supplies only one. The new keyword test passes because its prose also contains threshold. Please account for these alternative token forms when deciding how many independent concepts the query requires, and test an alias without segment overlap in the prose.
There was a problem hiding this comment.
Agreed and fixed in 359428b. scoreMemories now groups the query into concepts before the gate: an identifier plus its camel/separator segments is ONE concept, identifiers sharing a token merge, long queries require two distinct concepts, and a concept contributes at most its best-matching token's idf — so granularity cannot inflate admission or rank.
Your exact row (kw: ["memoryrecallthreshold"], no segment overlap in prose) is pinned by a new test, alongside the existing overlap variant. Bench re-run after the change: every arm's R@1/R@3 and top-1 noise are identical at all three store sizes (lexical 98%, noise 6%/6%/7%), with one extra lexical recovery at store 200 and 500 (all-miss 43 → 42). The cost-bound test was also recalibrated (scan ~34 ms vs the old regex chain ~200 ms per 20 calls; bound 150 ms).
…kens Review #417, two reproduced regressions: - "Join on db_id." tokenised the whole form as "db_id.", so a row ending its sentence was unreachable for a db_id query. Only the edges of an identifier are trimmed now; interior separators stay. - The segment expansion raised the flat query-token count, which flipped the unchanged admission gate from one required match to two, and a row carrying that keyword fused in kw supplied only one — the row stopped matching its own keyword. scoreMemories now groups the query into concepts (an identifier plus its segments is one concept; identifiers sharing a token merge), requires two CONCEPTS for long queries, and lets a concept contribute at most its best token's idf, so a row cannot out-rank another by spelling one identifier in more granularities. The cost-bound test budget was calibrated, not guessed: 20 calls on a 4,000-character uppercase row cost ~34 ms with the linear scan and ~200 ms with the regex chain it replaced; the bound sits at 150 ms (a 40 ms budget tripped at 42 ms on the CI runner). Bench re-run after the change: every arm's R@1/R@3 and top-1 noise are identical at all three store sizes (lexical 98%, noise 6%/6%/7%), with one extra lexical recovery at store 200 and 500 (all-miss 43 -> 42).
WhollyMindless
left a comment
There was a problem hiding this comment.
Retested both original reproductions on 359428b in an isolated checkout: the sentence-ending db_id. row is retrieved by db_id, and the fused keyword retrieves its row without segment overlap in the prose. Both findings from my previous review are addressed. The surrounding tokenizer, ranking/admission, attribution, consolidation and quarantine tests also pass on Windows Bun 1.4.4. This is verification of these fixes; the private case-bank efficacy claims remain outside my independently reproduced evidence. As previously disclosed, the base includes earlier contributions by me.
## [0.26.1](v0.26.0...v0.26.1) (2026-11-17) ### Bug Fixes * **bench:** recall-quality emits the fixtures/ path it moved to in 5e83025 — a re-run reverted the summary header ([08ee74b](08ee74b)) * **recall:** clamp the limit, and price the window cut per query ([2961a7e](2961a7e)), closes [#415](#415) * **recall:** default the memory_recall window to 5 rows, not 20 ([#409](#409)) ([3a23ee3](3a23ee3)) * **recall:** keep the whole identifier as a token alongside its segments ([8c2df14](8c2df14)) * **recall:** trim edge punctuation; admission counts concepts, not tokens ([359428b](359428b)), closes [#417](#417) ### Performance Improvements * **recall:** split identifiers in the matcher tokenizer ([#409](#409)) ([00dac47](00dac47))
|
🎉 This PR is included in version 0.26.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
|
Post-merge follow-up: [P2] Identifier splitting lets scope metadata bypass dedup's non-Latin content floor. Reproduced on v0.26.1 (
Recall with
Please consider constructing the dedup vocabulary from the intended content/keyword fields directly, and adding this composed-handler regression case. This hides a distinct recall result when dedup is enabled; it does not delete stored rows. The existing focused suites pass, but this additional probe fails on the integrated release. Authorship disclosure: the base includes our earlier contributions; this is a reproduced follow-up on the maintainer-authored integration, not an independent approval. Timing and disposition remain yours. |
|
Post-merge gap from @WhollyMindless's follow-up (scope words bypassing the dedup content floor) reproduced verbatim, ticketed as #421, fixed in #422 with your probe as the composed-handler regression test. Your suggestion — build the vocabulary from the content/keyword fields directly — is exactly the shipped fix: |
WhollyMindless #426 review: with the gate default-on, `discount tiers` returned No matching memories for the row `DISCOUNT_TIERS controls the pricing schedule` — rowConcepts kept the identifier one word while the prose query offered two concepts. Default-on admission must not regress the identifier-to-prose lookup the #417 scorer tokenizer restored. rowConcepts now emits underscore SEGMENTS alongside the whole word: `discount_tiers` contributes discount and tiers too. Word-level, not substring: build2837 (no separator) still shares nothing with 283; the whole word is kept, so an identifier query still hits. Pinned with the reviewer's composed-handler probe (red before the fix) plus a rowConcepts unit.
WhollyMindless round-2 probe: `discount` found `discountTiers controls the pricing schedule` with the gate off and abstained with it on. The first fix handled underscore separators only, and recallHaystack lower-cases before tokenizing, so the camel boundary was gone before segmentation could see it. rowConcepts now runs the #417 scorer tokenizer (words()) over an original-case haystack — the same whole-form-plus-segments granularity that ranks the row — via a new recallHaystackRaw. Admission can no longer be narrower than the scorer that put the row in the window. Whole forms kept: build2837 still shares nothing with 283. Both round-2 probes pinned (red before, green after).
# [0.30.0](v0.29.0...v0.30.0) (2026-11-18) ### Bug Fixes * **gate:** admission carries identifier SEGMENTS ([#425](#425) review) ([bf12aea](bf12aea)), closes [#426](#426) [#417](#417) * **gate:** admission keeps exact suffixes of dotted names ([#425](#425) review round 3) ([b024e77](b024e77)) * **gate:** admission segments camelCase too ([#425](#425) review round 2) ([1fcae59](1fcae59)), closes [#417](#417) * **recall:** review findings on the default flip ([#425](#425)) ([0fc51e4](0fc51e4)) ### Features * **recall:** default ON the dedupe and query-gate quality flags ([#425](#425)) ([d1b97d3](d1b97d3))
What
Makes the injection scorer's tokenizer identifier-aware: each identifier — a maximal run of letters, digits,
_,.,-,/— emits two granularities: the whole identifier lower-cased (what the shipped tokenizer matched) and its camelCase/separator segments. SogetUserAccount,get_user_accountandget-user-accountfinally shareget/user/account, while an exact query fordb_idstill matches exactly the row that cites it.No flag: this changes the shipped ranking vocabulary for every user. That is deliberate only because the re-measurement below shows the shipped arm does not move; if you want a flag, say so in review.
Reworked after adversarial review
The first version split identifiers and discarded the whole form. Two concrete regressions, both now pinned by tests:
words("db_id")andwords("no_op")returned empty (split fragments fall under the 3-char floor), so a query for those identifiers abstained where the shipped tokenizer matched exactly.normalizeKeywords(memoryRecallThreshold→memoryrecallthreshold), so a split query could never match a fused alias — breaking the P2: Retrieval ranking — IDF/BM25-lite, recency tie-break, write-time keywords #40 write-time vocabulary bridge for exactly the aliases it exists for.Also addressed:
naive,bm25Rankand the query-class classifier now carry a frozen copy of the legacy tokenizer; importing the live one meant this PR silently redefined its own published baselines.Measurements — shipped configuration
bun bench/runners/recall-quality.ts(fixture 52 gold / 105 queries,kwindexed, k=3), this branch vsorigin/main:prod(no kw — not what ships)prod+kw(shipped)The shipped arm does not move. The fixture contains no query that spells an identifier differently from the memory that cites it, so the capability this PR adds is real (11 tests pin it: cross-spelling match, exact-identifier retrieval, fused-keyword bridge, cost bound) but unpriced by this fixture. Treat this PR as a correctness/consistency fix with a possible future payoff for identifier-mismatched queries, not as a measured win — the honest options are merge-as-correctness or close-for-lack-of-evidence.
bench/recall-results.mdis the regenerated output of the run above.Tests
11 tokenizer tests (spelling equivalence, whole-form preservation, acronym runs, paths, short-token floor, prose unchanged, retrieval both directions, exact identifier, fused keyword, adversarial cost).
bun run gate(tsc + biome + unit + e2e) green.Review round (WhollyMindless, 2026-11-16)
Both P2 regressions reproduced and fixed in
359428b:Join on db_id.carriesdb_idand stays reachable for adb_idquery. Interior separators unchanged.src/recall/score.ts; whichever lands second needs a rebase, and the combined admission (concept gate in the handler + concept counting here) must be re-measured before both ship.