Skip to content

improve(memory): bound vector recall decision counts - #147900

Merged
steipete merged 1 commit into
mainfrom
codex/sqlite-round15-memory-landing
Sep 14, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/sqlite-round15-memory-landing

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #146197

What Problem This Solves

Underfilled vector recall counts complete chunk and vector sets even after it has enough information to choose widening or fallback.

User Impact

Search results and fallback decisions remain unchanged. This bounds count work on large indexes; it is not a general search-speed claim. Small counts add some overhead. No schema or row format changes, migration, rebuild, or operator action is required.

Why This Change Was Made

Count at most the requested number of matching chunks and 4,097 vectors. These thresholds preserve the existing widening and 4,096-vector fallback decisions, statement order and readonly boundaries. Native statement, returned-row and byte counts remain unchanged.

Evidence

  • Real sqlite-vec regression: original passes complete behavior assertions, then fails the count-work bound; candidate passes. Final search/KNN/subprocess coverage passes 74 tests. Canonical formatting, scoped lint, selected production/test types and all guards pass; independent P0–P2 review is clean.
  • Seven file-backed fixtures and 78 differential cases preserve complete outputs, schema/typed state, errors, readonly reopen and subsequent admitted writes on existing databases.
  • With 20,000 matching chunks and two indexed vectors, the searchVector algorithm falls from 3.403 to 0.513 ms (CPU 3.429 to 0.528 ms); matching count alone falls from 2.093 to 0.111 ms. This is a sparse-vector scaling control. Query/row/byte totals stay 3/4/122.
  • For 20,064 vectors, count alone moves 4.221 to 3.059 ms. Small counts cost more: singleton matching count 0.0137 to 0.0303 ms and two-vector count 0.0123 to 0.0204 ms.

Timings use Node 26.8.2, default memory source filtering and the normal 200-candidate window: one warmup plus five alternating pairs, seven diagnostic count pairs. They measure searchVector with the actual KNN owner and locally executed fallback algorithm, excluding process/worker dispatch and manager ranking. Compilers/static guards were active. The unchanged complete-result control moved 2.564 to 3.073 ms while its kernel moved the other way, so small whole-flow differences are not claimed as gains. Singleton flow was 0.489 to 0.526 ms; filtered-small was 1.638 to 1.904 ms. Synthetic two-dimensional data does not establish production prevalence or universal speedup.

The observing-view regression establishes work bounds, not native-table timing. Capped scans can avoid corruption diagnostics beyond the decision prefix; accessed-row validation remains intact, and these readonly counts do not authorize deletion. Initial fixture and syntax failures were retained; the completed fixed run was not rerun to improve medians.

@clawsweeper

clawsweeper Bot commented Sep 14, 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.

@steipete
steipete marked this pull request as ready for review September 14, 2026 04:34
@openclaw-barnacle openclaw-barnacle Bot added extensions: memory-core Extension: memory-core size: S maintainer Maintainer-authored PR labels Sep 14, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 14, 2026
@clawsweeper

clawsweeper Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 14, 2026, 12:46 AM ET / 04:46 UTC.

ClawSweeper review

What this changes

Memory Core bounds the counts used when vector search returns too few matches and adds a native SQLite regression test for the reduced counting work.

Merge readiness

✅ Ready for maintainer review

Keep open: this is a useful, focused optimization absent from current main and the latest release. The count caps preserve the existing widening and fallback decisions; no blocking defect was found.

Priority: P2
Reviewed head: 21815c776552bcafb30962dccda22263484075e4

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with sound threshold equivalence, meaningful native regression coverage, and appropriately bounded performance claims.
Proof confidence 🌊 off-meta tidepool Not applicable: The repository state identifies this as maintainer-authored, so the external-contributor proof gate does not apply; the body nevertheless reports file-backed runs through the changed KNN owner, output parity, and workload-specific timing results.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository state identifies this as maintainer-authored, so the external-contributor proof gate does not apply; the body nevertheless reports file-backed runs through the changed KNN owner, output parity, and workload-specific timing results.
Evidence reviewed 7 items Threshold equivalence: The initial result count is below the requested limit before counting begins. Capping matching chunks at that limit preserves both the comparison with returned rows and requiredMatches. Capping vectors at 4,097 preserves min(vectorCount, 4,096) and the greater-than-4,096 fallback condition. Input validation already requires a positive safe-integer limit.
Current main still uses complete counts: The fetched main implementation retains uncapped matching-chunk and vector COUNT queries. Its recent snippet optimization does not implement this counting change.
Latest-release comparison: The source at the supplied latest release, v2026.9.4, also performs complete counts; the requested optimization is not present there.
Findings None None.
Security None None.

How this fits together

Memory Core searches indexed memory using query embeddings and model/source filters. Its SQLite query worker returns matching snippets or asks the search owner to scan stored embeddings as a fallback.

flowchart TD
  A[Query embedding and filters] --> B[Memory search]
  B --> C[SQLite vector query worker]
  C --> D{Enough matches?}
  D -->|Yes| G[Ranked memory snippets]
  D -->|No| E[Bounded counts and wider query]
  E -->|Recall still incomplete beyond cap| F[Embedding fallback scan]
  E -->|Recall complete| G
  F --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +3, Tests +80. Total +83 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 7 4 +3
Tests 1 80 0 +80
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 87 4 +83

Review metrics

Metric Value Why it matters
Decision-count ceilings Requested matching-chunk limit; 4,097 vectors Both ceilings retain precisely the information needed for the existing widening and fallback decisions.

Technical review

Best possible solution:

Keep the counting optimization within the existing read-only query owner while preserving result filtering, widening thresholds, and fallback behavior.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a functional bug: this preserves search behavior while reducing counting work. Current source confirms the complete-count path; the reported performance measurements were not rerun during this read-only review.

Is this the best way to solve the issue?

Yes. Limiting the existing count subqueries is a narrow solution that preserves all downstream threshold comparisons without adding an API, migration, or competing implementation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against fe645cd77de7.

Labels

Label changes:

  • add P2: This is a bounded search-performance improvement with reported large-index benefits and no demonstrated urgent user-facing failure.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository state identifies this as maintainer-authored, so the external-contributor proof gate does not apply; the body nevertheless reports file-backed runs through the changed KNN owner, output parity, and workload-specific timing results.

Label justifications:

  • P2: This is a bounded search-performance improvement with reported large-index benefits and no demonstrated urgent user-facing failure.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository state identifies this as maintainer-authored, so the external-contributor proof gate does not apply; the body nevertheless reports file-backed runs through the changed KNN owner, output parity, and workload-specific timing results.

Evidence

What I checked:

  • Threshold equivalence: The initial result count is below the requested limit before counting begins. Capping matching chunks at that limit preserves both the comparison with returned rows and requiredMatches. Capping vectors at 4,097 preserves min(vectorCount, 4,096) and the greater-than-4,096 fallback condition. Input validation already requires a positive safe-integer limit. (extensions/memory-core/src/memory/manager-search-knn.ts:158, 21815c776552)
  • Current main still uses complete counts: The fetched main implementation retains uncapped matching-chunk and vector COUNT queries. Its recent snippet optimization does not implement this counting change. (extensions/memory-core/src/memory/manager-search-knn.ts:161, fe645cd77de7)
  • Latest-release comparison: The source at the supplied latest release, v2026.9.4, also performs complete counts; the requested optimization is not present there. (extensions/memory-core/src/memory/manager-search-knn.ts, 3a9d69db306c)
  • Regression coverage and production connection: The new test invokes the actual KNN owner with sqlite-vec and observing views over 6,000 rows, checking fallback output and bounded row visits without a new production seam. Existing search coverage checks widening below the cap, model aliases, source filtering, and fallback beyond the native cap. The production child invokes this same owner on a read-only connection. (extensions/memory-core/src/memory/manager-search-knn.test.ts:13, 21815c776552)
  • Captured performance and compatibility evidence: The supplied PR body reports seven file-backed fixtures, 78 differential cases, and 74 passing search/KNN/subprocess tests. Its Node 26.8.2 benchmark exercises searchVector with the real KNN owner and local fallback, reporting a sparse-vector improvement from 3.403 to 0.513 ms while explicitly documenting small-case overhead and excluding worker dispatch and manager ranking. These are contributor-reported observations, not reviewer executions. (21815c776552)
  • Feature-history routing: Current-main history includes recent snippet and extension-fallback work by Peter Steinberger, startup work by NianJiu, and query isolation work by JC. GitHub verifies that improve(memory): reduce text loaded during vector recall #146380 was authored by steipete and merged as d520b09. (extensions/memory-core/src/memory/manager-search-knn.ts:127, d520b0964adc)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • NianJiu: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 51b45c2 into main Sep 14, 2026
161 checks passed
@steipete
steipete deleted the codex/sqlite-round15-memory-landing branch September 14, 2026 05:04
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 14, 2026
* commit 'e3d8d0078369b21223c70028c4502c89f1420897': (51 commits)
  fix: background requests delay opening chats (#147845)
  chore(i18n): refresh native locales (#147899)
  feat: start remote sessions without a repository (#147773)
  fix(slack): retire probe sockets after timeout (#147846)
  refactor(agents): share theme ANSI color encoding (#147838)
  improve(memory): bound vector recall decision counts (#147900)
  improve(browser): narrow dashboard lifetime rechecks (#147892)
  test(discord): compact lifecycle matrices (#147855)
  fix(agents): use exact model rows for harness support (#147849)
  test(agents): compact embedded lifecycle matrices (#147856)
  test(agents): compact embedded admission matrices (#147853)
  test(cli): compact node management matrices (#147854)
  feat(artifacts): select assistant-delivered files by run (#147682)
  improve: reduce event-loop work when recording prompts (#147876)
  fix: preserve readable generated image and video filenames (#147833)
  fix(ci): skip SDK rendering for identical revisions (#147572)
  fix: prevent false process failures and stalled background waits (#147871)
  fix(ui): restore live updates when retrying chat history (#147865)
  fix(ui): preserve text and image order in assistant replies (#147731)
  refactor(qa-lab): reuse approval result formatter (#147867)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: memory-core Extension: memory-core maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

1 participant