Repository navigation
fix(memory): find indexed words across Unicode normalization forms - #150968
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR makes memory keyword queries find indexed words across composed and decomposed Unicode spellings. Example: Search for decomposed München against notes containing München in NFC and NFD forms.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it repairs a concrete memory-search defect still present on current main, with sufficient CLI proof and no actionable findings. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherMemory Core receives queries from the memory CLI and memory_search tool, prepares lexical queries in a read-only retrieval worker, and returns ranked snippets from existing SQLite indexes. flowchart LR
A[Memory CLI or tool] --> B[Memory retrieval manager]
B --> C[Read-only search worker]
C --> D[Canonical query planner]
D --> E[SQLite body and path indexes]
E --> F[Ranked memory snippets]
Technical reviewBest possible solution: Land the canonical query planner while preserving existing indexes, original text, and ranking boundaries. Do we have a high-confidence way to reproduce the issue? Current-main source explains the NFC/NFD misses, and the supplied before/after CLI corpus provides a concrete reproduction; no target code was executed during this read-only review. Is this the best way to solve the issue? Query-side alternatives repair existing indexes without rewriting user text, while keeping strict word conjunctions, short-trigram fallback, and filename ranking in their existing owners. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against afb4f0ff366b. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +118, Tests +433, Docs +1. Total +552 across 6 files. Added test files: 3. View PR surface stats
Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (21 earlier review cycles; latest 8 shown)
Reviewed October 9, 2026, 9:24 PM ET / October 10, 2026, 01:24 UTC (Revision 22). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…penclaw#150968) * fix(memory): preserve Unicode forms in keyword queries * fix(memory): scope canonical query variants * fix(memory): preserve unicode61 canonical recall * fix(memory): preserve MATCH fallback injection * fix(memory): preserve tokenizer ranking * fix(memory): match unicode61 canonical folding * fix(memory): preserve Unicode aliases and query form scoring * test(memory): use canonical agent entries in Unicode proof * fix(memory): consolidate Unicode query planning and regression coverage * fix(memory): match Unicode 6.1 marks when deduplicating queries --------- Co-authored-by: Peter Steinberger <[email protected]>
Related: #38945
What Problem This Solves
Memory keyword search can miss an indexed word when the query and note use visually identical NFC/NFD Unicode spellings, leaving keyword-only recall empty and hybrid recall without its lexical evidence.
User Impact
The memory CLI and
memory_searchfind both stored spellings without rewriting notes, reindexing, or changing configuration. Both SQLite tokenizers are covered. Original chunk text, strict AND matching between words, source filters, ranked limits, and filename precedence are preserved.Why This Change Was Made
keyword-query.tsowns token extraction and canonical query planning. It keeps combining marks attached, builds raw/NFC/NFD alternatives per word, and deduplicates alternatives using SQLite's tokenizer behavior. Short trigram terms retain normalized substring matching; path plans retain their existing independent score aggregation. Identical repeated query terms no longer inflate BM25.Review exposed an additional defect in the incoming implementation: JavaScript's modern Mark category does not match SQLite's fixed Unicode 6.1 categories. The correction uses SQLite's immutable category ranges, preserving Grantha alternatives that SQLite treats as token characters. No dependency, schema, indexing-writer, ranking-formula, or threshold change is introduced.
Production: +166/-48 (net +118). Tests/support: +433/-0, 70 fewer added lines than the incoming PR. Docs: +2/-1. Production growth supplies the canonical alternatives and tokenizer-equivalence rules needed to query existing indexes without duplicate BM25 contributions; consolidating the existing planner and token extraction removes duplicate ownership. The remaining growth keeps those rules at the existing query owner while preserving stored data. Thanks @Leon-SK668 for the Unicode repair; repeated-term handling aligns with @MonkeyLeeT's related ranking work.
Evidence
Baseline:
c75ff3cbf56ea8d00d1f33599482901999098f8d. Candidate:15680ec593d64f0581ad37431238e20a9d780fa0, with main427f926e7c2d763e362f59678c6486b6f2f4aec4merged and contributor history preserved. The query/search/retrieval owners were unchanged between the baseline and merged main.Real
pnpm openclawCLI proof on macOS arm64 / Node 26.10.0 used four isolated indexes:provider: "none"and Ollamanomic-embed-text, each withunicode61andtrigram. Each index contains five synthetic notes: München NFC/NFD, Korean NFC/NFD, and an ASCII control. Candidate searches reuse the original indexes, with no reindex between before and after.All 24 candidate CLI queries pass: the 16 Unicode queries return exactly both corresponding notes with positive keyword scores in both modes/tokenizers; ASCII returns only its control note; absent queries return nothing. Ollama status confirms a complete 768-dimensional vector index and five embedding-cache entries. Hybrid baseline could already recover missing forms semantically; the candidate restores the missing keyword contribution. This exercises real local embedding inference through memory indexing/search, not a chat or Gateway turn.
Hashes of every source note and the ordered persisted chunk path/text rows are identical before and after across all four indexes. The direct SQL regression also queries reopened read-only indexes.
Reproduce the CLI corpus
Use isolated
HOME,OPENCLAW_HOME,OPENCLAW_STATE_DIR, andOPENCLAW_CONFIG_PATH; setagents.defaults.workspaceto a fresh workspace and enablememory-coreplusollama. Setmemory.search.providertononeorollama,memory.search.store.fts.tokenizertounicode61ortrigram, and for Ollama set modelnomic-embed-textand remote base URLhttp://127.0.0.1:11434. This proof reserved port 19227 and used profilememory-keyword; it did not start a Gateway service.Write these five strings, each prefixed with
user:and followed by a newline, tomemory/note-0.mdthroughnote-4.md. Apply Unicode NFD normalization to notes 1 and 3:node scripts/run-vitest.mjs <file> --maxWorkers=1:manager-search.unicode-query.test.ts, 53 tests, 40.25 s wall;manager.unicode-query.test.ts, two tests, 97.20 s wall. Cold compiled-worker preparation dominates wall time. The two integration fixtures protect tool/worker propagation and original-text preservation; the larger form/scoring matrix stays at the cheaper SQLite boundary. No timers, sleeps, or Gateway boots were added.git diff --checkpass. Full SDK lint preparation timed out twice. Canonical Memory Core-scoped preparation succeeded, followed by the same type-aware lint over the touched files (45.44 s, pass).openclaw/ci-gatechecks are green. Hosted step durations: lint 198 s, baseline ratchets 88 s, test types 175 s. This CI run did not select a memory Vitest job; the per-file test timings above are local measurements.Validation tooling corrections: an initial build correctly refused an input snapshot changed during preparation; the final frozen-head build passed. The first tool fixture lacked the current background-lifecycle context and was corrected before its behavioral replay. Gateway-only setup lacked an already-declared QA workspace devDependency needed by broad typechecks; installing it with the frozen lockfile resolved the typecheck prerequisite. One timing-only test invocation was rejected while declaration generation changed its compilation inputs; the subsequent measured run used stable artifacts. No failed tool attempt is counted as a passing check.
Scope is raw/NFC/NFD alternatives per word, including documents that mix forms across words. Arbitrary partial composition within a single stored word and general Unicode compatibility folding are not claimed. Installed-release upgrade and full release-package validation were not run.