Skip to content

perf(C0-PR5): G7/G8/G9/G10 recall hot-path fixes - #66

Draft
m3talux wants to merge 2 commits into
mainfrom
fix/c0-recall
Draft

m3talux wants to merge 2 commits into
mainfrom
fix/c0-recall

Conversation

@m3talux

@m3talux m3talux commented Jun 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • G7: Hoist all db.prepare() calls into openIndex() so zero statements are prepared per method invocation; eliminates N+1 prepare pattern across hydrate, bm25Global, vectorKNNGlobal, globalFallbackNotes, and all other hot-path methods
  • G8: serializeInt8ForSql returns a Buffer over raw int8 bytes instead of a JSON array string; vec_int8(?) accepts a buffer directly, removing per-call JSON serialisation and re-parse on every upsert and KNN query
  • G9: Add CREATE INDEX IF NOT EXISTS notes_project and notes_created at openIndex() time (idempotent); globalFallbackNotes now uses an index scan
  • G10: Remove daily/ and meta/preferences.md path heuristics from global filter methods; the sole filter is note.project = 'global'. indexInto in indexer.ts stamps project='global' for cross-cutting folders (daily/, decisions/, lessons/, knowledge/, meta/) when frontmatter lacks a project value, preventing global-filter starvation without C1

Test plan

  • G7: spy on db.prepare after openIndex(), call each global method 3x, assert zero further prepares
  • G8: unit-assert serializeInt8ForSql returns a Buffer with correct byteLength; round-trip upsert/vectorKNN correctness
  • G9: assert notes_project and notes_created indexes exist; EXPLAIN QUERY PLAN does not show SCAN TABLE notes for the global fallback query
  • G10: a project=global note at a non-daily path is returned; a daily/ note with project=null is excluded
  • Indexer: indexNote stamps project=global for each cross-cutting folder; explicit project in frontmatter is preserved
  • Full suite green (799/799), tsc --noEmit clean

Generated with Claude Code

m3talux added 2 commits June 5, 2026 22:20
…prepare() calls into openIndex() so no statement is\nprepared on every method invocation (eliminates N+1 prepare pattern\nin hydrate, bm25Global, vectorKNNGlobal, globalFallbackNotes, etc.).\n\nG8: serializeInt8ForSql now returns a Buffer over the raw int8 bytes\ninstead of a JSON array string; vec_int8(?) accepts a buffer directly,\navoiding per-call JSON serialisation and re-parse on every upsert/query.\n\nG9: add CREATE INDEX IF NOT EXISTS notes_project ON notes(project) and\nnotes_created ON notes(created DESC) at openIndex() time so the global\nfallback query uses an index scan instead of a full table scan.\n\nG10: remove daily/ and meta/preferences.md path heuristics from\nbm25Global, vectorKNNGlobal, and globalFallbackNotes; the sole filter\nis now note.project = 'global'. To prevent starvation, indexer.ts\nindexNote stamps project='global' for cross-cutting folders (daily/,\ndecisions/, lessons/, knowledge/, meta/) when frontmatter lacks a\nproject value, making G10 self-contained without depending on C1.\n\nCo-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@m3talux
m3talux marked this pull request as draft June 6, 2026 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant