Repository navigation
perf(memory): score fallback vector rows without decoding to number[] - #164773
Conversation
The JS fallback scan in searchChunksByEmbedding decoded every stored binary64 blob into a fresh number[] and recomputed the query norm per row. Score the blob in place through a DataView and compute the query norm once. Ranking and scores are bit-identical.
|
🦞👀 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 scores stored memory vectors directly from binary64 bytes and computes query-prefix norms once per search. Example: Search a 6,600-chunk, 1,024-dimension memory index with sqlite-vec disabled.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR: it provides a measured fallback-search optimization absent from current main, preserves numerical and storage contracts, and has no actionable patch findings. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherMemory Core sends query embeddings to a read-only retrieval worker, which scans SQLite embedding BLOBs and returns ranked chunks and snippets. flowchart LR
A[Memory CLI or tool] --> B[Search orchestration]
B --> C[Read only retrieval worker]
D[SQLite embedding BLOBs] --> C
C --> E[Direct byte scorer]
E --> F[Ranked chunks and snippets]
Technical reviewBest possible solution: Land the focused private scorer while preserving the existing worker, storage, cancellation, and ranking contracts. Do we have a high-confidence way to reproduce the issue? Current-main source shows per-row array allocation and repeated query normalization, and supplied paired CLI measurements demonstrate their cost; this review executed no target code. Is this the best way to solve the issue? Direct scoring at the existing fallback owner removes measured work without adding persistent state, configuration, or another public API. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 06cf159ba182. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +15, Tests +65, Docs +1. Total +81 across 6 files. Added test files: 0. 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 (4 earlier review cycles)
Reviewed October 10, 2026, 3:15 AM ET / 07:15 UTC (Revision 5). |
Merge current main while preserving the contributor implementation. Cache query-prefix norms, retain exact binary64 ranking and malformed-vector behavior, and retire the unused private generic cosine path.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
|
Thank you @steipete! |
…openclaw#164773) The JS fallback scan in searchChunksByEmbedding decoded every stored binary64 blob into a fresh number[] and recomputed the query norm per row. Score the blob in place through a DataView and compute the query norm once. Ranking and scores are bit-identical.
What Problem This Solves
Memory search without sqlite-vec decodes every stored embedding into a new numeric array and repeatedly normalizes the same query. Large indexes spend avoidable CPU and allocation work on each fallback scan.
User Impact
Fallback search uses less scoring work while preserving ranked results and exact scores. No configuration, schema, stored-format, migration, or operator action changes. Embedding-provider latency and the timeout reports in #128140 and #114913 remain outside this change.
Why This Change Was Made
Memory Core scores little-endian binary64 BLOBs directly and computes query-prefix norms once. It retains the existing bounded scan, bigint row cursor, cancellation, tie ordering, and contender payload snapshot. The former generic cosine implementation and its private-local export had no remaining production caller and were removed; the published legacy JSON parser and embedding codec remain intact.
Thanks @etzelm for the original optimization and numerical parity coverage. The contributor commits remain in the branch, with current main merged rather than rebased. Against main
f18b305771d7e896d797945e4f4e6b0d22acc1b0: production +39/-24 (net +15), tests +105/-40, docs +3/-2. The remaining production growth provides direct byte scoring and reusable prefix norms; the original patch added 46 net production lines.Evidence
Candidate
8965f2767c3c80f03a086fe18911de836934c6c5.CI: The exact-head gate is red only for an inherited sidebar E2E expectation (run, failed UI job). CI tested merge
0303d0ba33caagainst mainaff6117e9351. Main's #168076 intentionally enabled child-session grouping, but the sidebar test still expected no “Move to group” item. The CI merge has no UI changes relative to that base. Main has already fixed this exact assertion in c355a4c109a8. The memory, core, type, lint, and ratchet jobs passed; the changed-plugin test job took 233 s and the boundary test job 79 s. This needs the native maintainer workflow's inherited-failure handling; no UI repair is included in this memory PR.ClawSweeper reviewed this exact head: Ready for maintainer review, Findings: None, Before merge: None, proof/patch 5/6.
Real local-model proof
The supported
pnpm openclaw --profile memory-misc memory index/searchcommands use isolated state and direct Ollamabge-m3through its OpenAI-compatible endpoint. Vector acceleration is disabled, and inspection confirms no sqlite-vec table. The real index contains 6,600 chunks, 1,024 dimensions, built from 33 synthetic memory entries repeated at distinct line numbers. The expansion reused all 33 cached model vectors without another document embedding request. Every indexed vector matches its seed cache bytes.The candidate searches the same main-created index without reindexing. A task-only observer captures actual vector-worker requests and responses; it does not modify production code or results. CPU and heap sampling run separately. The supplemental warm benchmark replays the actual CLI model query through the real source owner against that same database, with 3 warmups and 12 measured scans.
Both sides ran on Node 26.11.1, V8 14.6.202.34-node.37, using the same preserved executable and unchanged index. All four live searches produced the same query vector, the same 200 ranked IDs and exact scores, and identical final CLI result objects. Every warm replay also matched.
Warm CPU ranges were 65.776–91.306 ms on main and 51.206–60.683 ms on the candidate. A final read-only inspection confirmed unchanged chunk identity order and exact index/cache-vector pairing.
Commands used the real entry point, with task-owned configuration/state and
store.vector.enabled: false:The full candidate build passed (3,382.33 s wall). An initial build was interrupted when host maintenance replaced the running Homebrew Node executable; the retry used a preserved copy of the installed runtime. Both performance arms were rerun on that same version. The build emits the same nonfatal UI startup-size warning as main; no UI files changed.
Allocation samples include objects collected by minor and major GC. They estimate V8 heap allocation, not retained heap, RSS, or SQLite/external-buffer memory. The host is shared; CLI startup, model latency, and heap-profiled CPU are excluded from speed comparisons. Native sqlite-vec performance is outside this optimization; its focused behavior tests pass.