Repository navigation
Memory search's key-match arm splits a key at whitespace before stemming it - #475
Merged
Merged
Conversation
…ing it ClickHouse stem() refuses a word that holds ASCII whitespace, so one key such as `communication style` failed the key-match pre-check, the wide pass and the component pass for every query in its namespace. Keys are now split at `_` and at the six ASCII whitespace characters (`translate` then `splitByChar`); a key without whitespace splits as before, and the Python mirror of the predicate splits the same way. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…curate docstrings Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ace key qualifies in the gate Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… whitespace Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
force-pushed
the
fix/key-match-tokenize-keys
branch
from
November 10, 2026 11:12
fff6dd1 to
4624655
Compare
This was referenced Nov 10, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
Memory search's key-match arm works in a namespace that holds a memory key with whitespace in it (
communication style). Before, every key-match read in that namespace failed and the arm added nothing.Why
The key-match arm splits each
memory_keyat_and stems the parts with ClickHousestem(t, 'en').stem()refuses a word that holds ASCII whitespace (Code: 36. Function stem requires each input to be a single word without whitespace). All three statements stem every key in the namespace: the keys-only pre-check, the wide pass with its document frequencies, and the component-only pass. So one key such ascommunication stylefails each of them, for every query in that namespace. The arm fails open, so search still answered, without the arm. A deployment logskey-match pre-check failed ... Code: 36and thenkey-match arm failedon each such search.The fix splits keys before they are stemmed: at
_and at the six ASCII whitespace charactersstem()checks for (KEY_PARTSinserver/memory/app/search/sql.py).translatemaps each whitespace byte to_before the split. A key without whitespace yields exactly the parts it did before. The Python mirror of the predicate (key_match_key_qualifies, which the gate uses) splits the same way throughkey_parts.The query side already tokenizes in Python (
lemma_tokens) and never reachesstem().Decisions:
/,-or.too would letpref/editor_themematch onpref. But it would also change the part count and the per-stem document frequencies of keys that work today, and with them the ranking. Whitespace is the one inputstem()refuses, and no key that works today holds any.translate, notsplitByRegexp.translatemaps bytes one for one, so the split reads nothing more. On clickhouse-local over two million generated keys (SELECT sum(length(arrayMap(t -> stem(t, 'en'), <split>))) FROM (SELECT concat('user_task_', toString(number % 1000), '_worktree_path') AS k FROM numbers(2000000))),splitByRegexp('[_[:space:]]', lower(k))took 1.45 s against 0.73 s forsplitByChar('_', lower(k)), andtranslateplussplitByChartook 0.77 s.Scope and risk
communication stylematches a query about "communication style"._split alone (see above).Compatibility, rollout and rollback
Tests
tests/unit/test_key_match_sql.py(clickhouse-local, the production table):communication styleanduser_communication_style: the wide statement and the component statement each find both keys, and the pre-check answers, also on a namespace whose only key iscommunication style. Onmaineach fails with the deployment'sCode: 36(the arm logs a failed pre-check and falls through to the wide statement).key_partsin Python returns the statements'KEY_PARTSfor ASCII keys with__, a leading_, a space, a tab, a newline, a vertical tab, a form feed, a carriage return and//-. The last one also holds the lettersv,fandr, so each escape in the literal is pinned as whitespace, not as its letter.__, a leading_, mixed case,/,-): for three queries, each statement's rows and order equal those of the same statement with the_-only split put back._-joined key-like string intests/andbench/, plus edge cases (a__b,_lead_x,trail_x_, mixed case, non-ASCII).KEY_PARTSreplaced bysplitByChar('_', lower(memory_key)).tests/unit/test_key_match_arm.py: the PREWHERE assertion namesKEY_PARTS.tests/analyzer/shapes.txt: the nine key-match shapes are replaced (the pre-check, four of the wide statement and four of the component statement), regenerated withpython -m tests.analyzer.corpus --write, which on this branch reproduces the file exactly.make format lint typecheck; the key-match, read-scope, tag-filter, run-scope, handler-gate and public-copy unit tests;tests/analyzer.AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code. The failing statement was reproduced on clickhouse-local, and the comparison above was run.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass; the integration suite passes if server behaviour changed. (Format, lint, typecheck and the affected unit tests were run; CI runs the rest.)--write; see Tests.)main; no merged migration is edited. (No migration.)frontend/changed. (Unchanged.)docs/describe the system as it now is, and this description names any operator steps and wire changes.git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code