Skip to content

perf(recall): split identifiers in the matcher tokenizer (#409) - #417

Merged
abogartz merged 5 commits into
mainfrom
perf/409-identifier-tokenizer
Nov 17, 2026
Merged

abogartz merged 5 commits into
mainfrom
perf/409-identifier-tokenizer

Conversation

@abogartz

@abogartz abogartz commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

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. So getUserAccount, get_user_account and get-user-account finally share get/user/account, while an exact query for db_id still 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") and words("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.
  • Authored keywords are stored lower-cased and fused by 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:

  • Control arms frozen. naive, bm25Rank and 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.
  • Cost. The tokenizer is a single linear pass with no backtracking; a test bounds 20 calls on 4,000-character adversarial rows under 40 ms.
  • Unreproducible numbers removed. The first version's body quoted "no-gold wrong rows 0.60 → 0.44"; that figure exists in no committed artifact and cannot be reproduced. It is gone.

Measurements — shipped configuration

bun bench/runners/recall-quality.ts (fixture 52 gold / 105 queries, kw indexed, k=3), this branch vs origin/main:

arm lexical R@1 top-1 noise
prod (no kw — not what ships) 98% → 100% 6% → 5%
prod+kw (shipped) 98% → 98% 6% → 6%

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.md is 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:

  • Trailing punctuation: the whole-identifier form is edge-trimmed, so Join on db_id. carries db_id and stays reachable for a db_id query. Interior separators unchanged.
  • Fused keyword alias: admission now counts concepts, not tokens — an identifier plus its segments is one concept, identifiers sharing a token merge, long queries require two distinct concepts, and a concept contributes at most its best token's idf (granularity can no longer inflate admission or rank). Both reviewer cases pinned by tests.
  • Cost bound calibrated: the linear scan costs ~34 ms per 20 calls on a 4,000-char adversarial row vs ~200 ms for the regex chain it replaces; bound set to 150 ms (a 40 ms budget tripped at 42 ms on the CI runner).
  • Bench re-run after the fix: every arm's R@1/R@3 and top-1 noise identical at all three store sizes (lexical 98%, noise 6%/6%/7%), one extra lexical recovery at store 200 and 500 (all-miss 43 → 42). The merge-or-close positioning is unchanged.
  • Merge interaction: this PR and feat(recall): two-concept admission for memory_recall behind a flag #418 both edit 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.

…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.
@abogartz

Copy link
Copy Markdown
Owner Author

Composition note. Independent of the window changes in #415, #416 and #418 — this changes what the tokenizer produces, so it changes ranking inputs rather than admission or size. Live top-5 churn 7.7%, no-gold rows per call 0.60 → 0.44 at unchanged recall.

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.
@abogartz

Copy link
Copy Markdown
Owner Author

Rework pushed (8c2df14); the body now carries the current numbers — everything quoted here before this comment is void.

The review's two blocking regressions are fixed and pinned by tests: words("db_id") returned empty (exact-identifier queries abstained), and split queries could never match fused stored keywords (breaking the #40 vocabulary bridge). Each identifier now emits both the whole lower-cased form and its camel/separator segments. Bench control arms (naive, bm25, the class classifier) carry a frozen copy of the legacy tokenizer so this PR can no longer redefine its own baselines. The claimed 0.60→0.44 no-gold improvement is not reproducible from any committed artifact and has been removed.

Honest re-measurement on the shipped arm (prod+kw): lexical R@1 98%→98%, top-1 noise 6%→6%. The fixture has no identifier-mismatch queries, so this is now positioned as a correctness fix the fixture cannot price — merge-as-correctness or close-for-lack-of-evidence, maintainer's call.

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 WhollyMindless left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/recall/score.ts
.split(/[^a-z0-9_]+/)
.filter((t) => t.length > 2);
const out: string[] = [];
const ids = text.match(/[A-Za-z0-9_.\-/]+/g);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/recall/score.ts
const flush = () => {
if (cur.length > 2) {
const seg = cur.toLowerCase();
if (seg !== whole) out.push(seg); // single words emit once, as before

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 WhollyMindless left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@abogartz
abogartz merged commit 9236d68 into main Nov 17, 2026
4 checks passed
abogartz-opencode-self-improvement Bot pushed a commit that referenced this pull request Nov 17, 2026
## [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))
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.26.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@WhollyMindless

Copy link
Copy Markdown
Contributor

Post-merge follow-up: [P2] Identifier splitting lets scope metadata bypass dedup's non-Latin content floor.

Reproduced on v0.26.1 (6cdc206) through the real memory_recall handler in an isolated store: append two settled learning rows in scope auth_token_refresh_policy, with these unrelated contents:

  • 登录令牌在刷新后必须轮换并且旧令牌立即失效
  • 数据库连接池的最大连接数应该根据并发量调整

Recall with query: "auth_token_refresh_policy" and the default limit. Flag unset returns both; OPENCODE_MEMORY_DEDUP=0.8 returns only the newer row. The identical probe passes with the flag enabled at 8e86df4 (after #415/#416, immediately before #417).

contentTokens() in src/recall/dedupe.ts:128–132 tokenizes haystack(m) and removes only the whole scope/type tokens. The new tokenizer leaves auth, token, refresh, policy behind. Both rows therefore clear MIN_CONTENT=4 and have Jaccard 1 despite having no comparable prose. Before #417 their content-token sets were empty, so the floor preserved both.

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.

@abogartz

Copy link
Copy Markdown
Owner Author

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: contentTokens() no longer touches haystack().

abogartz-opencode-self-improvement Bot pushed a commit that referenced this pull request Nov 17, 2026
## [0.28.1](v0.28.0...v0.28.1) (2026-11-17)

### Bug Fixes

* **dedupe:** build the comparison vocabulary from content/keywords only ([#421](#421)) ([ce5c586](ce5c586)), closes [#417](#417) [#417](#417)
abogartz added a commit that referenced this pull request Nov 18, 2026
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.
abogartz added a commit that referenced this pull request Nov 18, 2026
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).
abogartz-opencode-self-improvement Bot pushed a commit that referenced this pull request Nov 18, 2026
# [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))
@abogartz
abogartz deleted the perf/409-identifier-tokenizer branch November 19, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants