Skip to content

fix(memory): find indexed words across Unicode normalization forms - #150968

Merged
steipete merged 20 commits into
openclaw:mainfrom
Leon-SK668:leon/fix-memory-unicode-query-20260917
Oct 10, 2026
Merged

steipete merged 20 commits into
openclaw:mainfrom
Leon-SK668:leon/fix-memory-unicode-query-20260917

Conversation

@Leon-SK668

@Leon-SK668 Leon-SK668 commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

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_search find 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.ts owns 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 main 427f926e7c2d763e362f59678c6486b6f2f4aec4 merged and contributor history preserved. The query/search/retrieval owners were unchanged between the baseline and merged main.

Real pnpm openclaw CLI proof on macOS arm64 / Node 26.10.0 used four isolated indexes: provider: "none" and Ollama nomic-embed-text, each with unicode61 and trigram. 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.

Keyword-only query Main: unicode61 Main: trigram Candidate: both tokenizers
München NFC Both notes NFC note only Both notes, ranks 1–2
München NFD No results No results Both notes, ranks 1–2
Korean NFC NFC note only NFC note only Both notes, ranks 1–2
Korean NFD NFD note only NFD note only Both notes, ranks 1–2

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, and OPENCLAW_CONFIG_PATH; set agents.defaults.workspace to a fresh workspace and enable memory-core plus ollama. Set memory.search.provider to none or ollama, memory.search.store.fts.tokenizer to unicode61 or trigram, and for Ollama set model nomic-embed-text and remote base URL http://127.0.0.1:11434. This proof reserved port 19227 and used profile memory-keyword; it did not start a Gateway service.

Write these five strings, each prefixed with user: and followed by a newline, to memory/note-0.md through note-4.md. Apply Unicode NFD normalization to notes 1 and 3:

München liegt in Bayern.
München liegt in Bayern.
한국어 문서를 보관합니다.
한국어 문서를 보관합니다.
Quartz compass calibration coefficient 17.
pnpm openclaw --profile memory-keyword memory index --force
pnpm openclaw --profile memory-keyword memory search 'München' --json
pnpm openclaw --profile memory-keyword memory search "$(python3 -c 'import unicodedata; print(unicodedata.normalize("NFD", "München"))')" --json
pnpm openclaw --profile memory-keyword memory search '한국어' --json
pnpm openclaw --profile memory-keyword memory search "$(python3 -c 'import unicodedata; print(unicodedata.normalize("NFD", "한국어"))')" --json
pnpm openclaw --profile memory-keyword memory search quartz --json
pnpm openclaw --profile memory-keyword memory search unrecordedword --json
pnpm openclaw --profile memory-keyword memory status --json
  • Regressions: original-main SQL cases fail on missing canonical words, false separator matches, and duplicate scores. The corrected tool fixtures fail on original main with empty results for both tokenizers (189.38 s wall). The new Grantha case fails on the earlier PR implementation in both unicode61 directions; trigram passes (122.06 s wall).
  • Candidate tests: 111 tests / five files pass, 283.45 s wrapper wall. Standalone 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.
  • Tokenizer contract: an independent SQLite 3.53.4 FTS vocabulary probe agrees for all 2,564 current/legacy mark characters: 1,645 separators, 919 token characters, zero discrepancies.
  • Checks: runtime build passes; production and test extension typechecks pass; all eight requested ratchets/config/inventory checks pass; formatting and git diff --check pass. 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).
  • Review and CI: fresh independent Codex autoreview is clean at P0–P2 after fixing its Unicode-version finding. ClawSweeper reviewed this exact head: 5/6, no findings and no before-merge items. CI run 38010534818 and security-review run 38010529466 completed successfully, and both openclaw/ci-gate checks 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.

@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 17, 2026
@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

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

  • Before: Keyword search returns no matching notes.
  • After: Both notes appear with positive keyword scores without reindexing.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, useful repair with shipped-entry-point proof, meaningful regressions, preserved existing-state compatibility, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The current-head receipt exercises the real memory CLI on macOS arm64 with both tokenizers and keyword-only/Ollama hybrid modes, showing NFC/NFD recall against reused indexes and successful ASCII and absent-query controls.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Visually identical query and note spellings can produce empty keyword recall or omit lexical evidence from hybrid recall.
Reason: The repair addresses demonstrated owned behavior without introducing configuration, schema, dependency, or public API changes.

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
Reviewed head: 15680ec593d64f0581ad37431238e20a9d780fa0

Before merge

None.

Findings

None.

Agent review details

How this fits together

Memory 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]
Loading

Technical review

Best 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

  • Tokenizer-aware query planning and short-term fallback keeps the original intent (3ce48af: Provide configurable Unicode/CJK tokenizers and substring fallback for terms too short for trigram MATCH.)
  • Separate filename retrieval keeps the original intent (e9b7a9a: Find notes by filenames and paths without polluting body relevance or replacing exact-path precedence.)
  • Worker-owned lexical retrieval keeps the original intent (e14b3dd: Keep large memory searches responsive by moving retrieval into bounded workers.)
  • Repeated query terms and canonical spelling equivalence changes intended behavior with a stated reason (unknown: The base joins every extracted term directly; the PR explains removing duplicate BM25 contributions and preserving whole Unicode words, while unavailable early blobs prevent establishing the original rationale.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit e14b3dd adds extensions/memory-core/src/memory/keyword-query.ts:12 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e14b3ddac2e5; files: extensions/memory-core/src/memory/keyword-query.ts)
  • Tak Hoffman: Raw commit 3ce48af adds extensions/memory-core/src/memory/manager-search.ts:195 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 3ce48aff660a; files: extensions/memory-core/src/memory/manager-search.ts)

PR surface

Source +118, Tests +433, Docs +1. Total +552 across 6 files. Added test files: 3.

View PR surface stats
Area Files Added Removed Net
Source 2 166 48 +118
Tests 3 433 0 +433
Docs 1 2 1 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 601 49 +552

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +166/-48; tests and support +433/-0 Production growth implements canonical alternatives and SQLite tokenizer equivalence at one query owner; coverage protects recall, scoring, existing indexes, and tool-to-worker propagation.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Unicode spelling differences cause missed lexical recall with a limited memory-search blast radius.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (21 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-26T11:28:31.822Z sha 4fb7f79 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-06T06:02:24.062Z sha 4fb7f79 :: blocked before merge. :: none
  • reviewed 2026-10-08T07:16:49.429Z sha 39a18c4 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-08T07:30:27.291Z sha 7d4af78 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-08T07:38:50.443Z sha 7d4af78 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-08T10:17:28.811Z sha 7d4af78 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T00:56:40.845Z sha 15680ec :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T01:03:48.172Z sha 15680ec :: needs maintainer review before merge. :: none

Reviewed October 9, 2026, 9:24 PM ET / October 10, 2026, 01:24 UTC (Revision 22).

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 17, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 22, 2026
@clawsweeper clawsweeper Bot added the rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. label Oct 8, 2026
@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 8, 2026
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Oct 10, 2026
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Oct 10, 2026
@steipete steipete self-assigned this Oct 10, 2026
@steipete
steipete merged commit 17a1d10 into openclaw:main Oct 10, 2026
128 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: memory-core Extension: memory-core P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants