Skip to content

improve(memory): reduce text loaded during vector recall - #146380

Merged
steipete merged 1 commit into
mainfrom
codex/sqlite-memory-snippets-round3-0912
Sep 12, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/sqlite-memory-snippets-round3-0912

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #146197

What Problem This Solves

Vector memory recall loads complete note chunks from SQLite even when it only displays a short snippet.

User Impact

Memory search returns the same snippets and rankings while transferring less temporary text from SQLite. Typical 1,600-byte chunks need 56% fewer fetched body bytes; very large stored chunks benefit more. Small chunks can incur a small query overhead. No migration or user action is required.

Why This Change Was Made

Limit the text projection in the existing KNN query. A bounded byte check preserves embedded NUL characters, and the existing Unicode-safe truncation remains authoritative. Query count, filtering, widening, and read consistency stay unchanged.

Evidence

  • All 70 search and subprocess tests pass, including real sqlite-vec, WAL writer visibility, cancellation, source/model filtering, and oversized child responses.
  • New owner regressions preserve snippets across UTF-8, UTF-16LE, and UTF-16BE, empty text, embedded NUL, emoji, CJK, and normalized unpaired surrogates. Against the original owner, all snippet comparisons pass; only the fetched-body budget fails (501,504 bytes versus 57,360).
  • File-backed WAL benchmark: 200 synthetic rows, 100 retained hits, 700-unit snippets, 10 warmups and 50 alternating before/after samples. Complete result hashes match; each request still executes one query and returns 100 rows.
Body size per row Fetched body bytes before → after Median query time before → after
400 bytes (small control) 40,000 → 40,000 0.778 → 0.930 ms
1,600 bytes (normal chunk size) 160,000 → 70,000 1.012 → 1.044 ms
16,000 bytes (large stored-row stress) 1,600,000 → 70,000 2.678 → 2.003 ms
160,000 bytes (oversized stress) 16,000,000 → 70,000 68.082 → 12.651 ms

These are native query measurements, not end-to-end search latency or disk-I/O savings. Current fresh indexing bounds ordinary chunks near 1,600 characters; the larger rows exercise existing oversized stored data.

Validation also passed extension production/test typechecks, targeted lint, six plugin contract guard tests, formatting, and the remaining changed-file guards. Fresh independent review found no actionable P0–P2 issues.

The broad unused-export scan still reports two unchanged tooling exports (canonicalProviderName and listPackagedStaticExtensionAssetOutputs), matching the baseline. The Windows lint launcher required direct invocation of its canonical declaration preparer, followed by lint with the supported skip-already-prepared flag; both completed successfully.

@clawsweeper

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

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

clawsweeper Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 12, 2026, 3:58 PM ET / 19:58 UTC.

ClawSweeper review

What this changes

Memory Core limits text fetched during vector search while preserving existing snippets, with regression coverage for Unicode and embedded NUL characters.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused optimization absent from current main and the latest release. No actionable correctness or security defect was found; the maintainer-protected PR should remain open for landing.

Priority: P2
Reviewed head: 274b1c9bfb7fba5edd61375cce1df543da1046b2

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level optimization with useful native benchmark evidence, meaningful encoding regressions, and no identified blocking defect.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured body reports before/after execution of the changed native KNN query against a file-backed WAL database, with matching complete result hashes and reduced fetched text across larger rows. This supports the stated materialization improvement; the author explicitly excludes end-to-end latency and disk-I/O claims.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured body reports before/after execution of the changed native KNN query against a file-backed WAL database, with matching complete result hashes and reduced fetched text across larger rows. This supports the stated materialization improvement; the author explicitly excludes end-to-end latency and disk-I/O claims.
Evidence reviewed 10 items Introduced query change: The pinned introduced diff changes only the text projection and its bound parameters. Ranking, source/model predicates, widening, fallback decisions, and final Unicode-safe truncation remain intact.
Current main still fetches complete text: Fetched main selects c.text before truncating each returned row, so this PR's reduction in text transferred into JavaScript remains unimplemented there.
Latest release comparison: The supplied latest release, v2026.9.4, also selects complete chunk text in this owner.
Findings None None.
Security None None.

How this fits together

Memory Core searches indexed notes and session content using query embeddings. Its SQLite worker returns ranked matches and short snippets to the memory search manager.

flowchart LR
  A[Query embedding] --> B[Memory search manager]
  B --> C[SQLite vector worker]
  D[Indexed note chunks] --> C
  C --> E[Bounded text projection]
  E --> F[Unicode-safe truncation]
  F --> G[Ranked search snippets]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +10, Tests +80. Total +90 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 11 1 +10
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 91 1 +90

Review metrics

Metric Value Why it matters
Measured text-transfer reduction 56.25% fewer fetched body bytes for 1,600-byte rows The reported paired benchmark preserves result hashes and query count; this measures native-query materialization savings, not end-to-end search latency.

Technical review

Best possible solution:

Keep bounded snippet projection inside the existing SQLite query owner, preserving stored text and the established ranking and truncation contracts.

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

Not applicable as a functional bug: current source establishes excess full-text fetching, and the supplied paired benchmark measures its cost.

Is this the best way to solve the issue?

Yes. Narrowing the existing query projection avoids a second hydration pass and preserves snapshot consistency; the byte-prefix branch handles the NUL behavior that plain TEXT substring would lose.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded memory-search efficiency improvement with measured benefits and no reported urgent user-facing failure.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured body reports before/after execution of the changed native KNN query against a file-backed WAL database, with matching complete result hashes and reduced fetched text across larger rows. This supports the stated materialization improvement; the author explicitly excludes end-to-end latency and disk-I/O claims.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured body reports before/after execution of the changed native KNN query against a file-backed WAL database, with matching complete result hashes and reduced fetched text across larger rows. This supports the stated materialization improvement; the author explicitly excludes end-to-end latency and disk-I/O claims.

Label justifications:

  • P2: This is a bounded memory-search efficiency improvement with measured benefits and no reported urgent user-facing failure.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured body reports before/after execution of the changed native KNN query against a file-backed WAL database, with matching complete result hashes and reduced fetched text across larger rows. This supports the stated materialization improvement; the author explicitly excludes end-to-end latency and disk-I/O claims.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured body reports before/after execution of the changed native KNN query against a file-backed WAL database, with matching complete result hashes and reduced fetched text across larger rows. This supports the stated materialization improvement; the author explicitly excludes end-to-end latency and disk-I/O claims.

Evidence

What I checked:

Likely related people:

  • anyech: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • steipete: 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 d520b09 into main Sep 12, 2026
163 checks passed
@steipete
steipete deleted the codex/sqlite-memory-snippets-round3-0912 branch September 12, 2026 20:34
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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