Skip to content

perf(core): remember() no longer scans the namespace or holds the index lock for edge wiring - #1371

Merged
ajianaz merged 3 commits into
developfrom
perf/auto-link-hot-path
Oct 8, 2026
Merged

ajianaz merged 3 commits into
developfrom
perf/auto-link-hot-path

Conversation

@ajianaz

@ajianaz ajianaz commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

What

Hot path of remember (#1368, epic #1345):

  • Store::live_ids_in_namespace: one query over the candidate ids (json_each) replaces memories_in_namespace (a scan + HashSet of every id in the namespace on every write; O(N²) on import). Used by check_duplicate (dedup semantics unchanged) and auto_link_cosine.
  • auto_link_cosine: fetches 4× candidates before filtering by namespace, so a small namespace inside a large index keeps its own neighbours; memories that are deprecated and chunk:<id> document-chunk keys are never link targets.
  • remember: the SQLite writes (insert, source hash, timeline, wire_edges) no longer run under the index write lock, which blocked every concurrent recall for their whole duration; the lock is taken only to mirror the vector (and not at all when there is no embedding). A poisoned lock now yields the honest embedding_written=false + warning (remember: surface embedding write failure — no silent success when vector insert fails #1273) instead of an error after the row was committed.

Why

Graph audit (epic #1345). remember is the path every user hits; the cost grew with namespace size and writers starved readers.

Behaviour change

Only the auto-created similar_to / possible_duplicate edges differ: more links in small namespaces of large indexes, none to deprecated memories. Default fusion recall does not read edges; benchmark gate (LongMemEval fast50, default strategy, develop vs this branch on Modal) is run before merge — results below / in a comment. Not a CORE wire change, but recall-adjacent: noted in uteke-cloud#117 discussion if numbers move.

Testing

  • 4 new tests: small namespace in a big index (fails on the old code: no links at all), deprecated never linked (fails on old code), live_ids_in_namespace, dedup scoped to namespace and ignoring deprecated.
  • cargo fmt --check, cargo clippy --workspace --all-targets clean; cargo test --workspace green (core 633, server 61); vecq-only core build green (630).
  • Not covered: a timing/contention test for the narrowed lock (reasoned from the code, not measured); benchmark gate pending.

Refs #1368

🤖 Generated with Claude Code

…ex lock for edge wiring

- Store::live_ids_in_namespace: one query over the candidate ids (json_each) instead of loading every id of the namespace per write; used by check_duplicate (dedup semantics unchanged) and auto_link_cosine
- auto_link_cosine: fetch 4x candidates before the namespace filter so a small namespace in a big index keeps its own links; deprecated memories and chunk: keys are never link targets
- remember: SQLite writes (insert, hash, timeline, wire_edges) run without the index write lock; the lock is taken only to mirror the vector; a poisoned lock becomes an honest warning instead of an error after the row was committed

Refs #1368

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@ajianaz ajianaz added enhancement New feature or request scope:core Core engine work priority:high Fix in next release labels Oct 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

ajianaz and others added 2 commits October 8, 2026 10:30
@ajianaz

ajianaz commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator Author

Benchmark gate (LongMemEval fast50, Modal, default strategy, 10 shards)

Binaries built from exact SHAs: base = develop b1056e4, candidate = this branch 771ebb8 (before the develop merge; the merge only added unrelated graph/bench changes).

run recall_all@5 recall_all@10 ndcg_any@5 ndcg_any@10
base 0.9800 1.0000 0.8993 0.9062
base (control, 2nd run, same binary) 0.9800 1.0000 0.8993 0.9062
candidate 0.9800 1.0000 0.8993 0.9062

Per-question rankings are NOT bit-identical between runs: base vs base-control is identical for only 18/50 questions, candidate vs base-control 33/50, candidate vs base 23/50. So the difference between base and candidate is within the run-to-run noise of the harness (salience/recency boosts are wall-clock dependent), and every aggregate metric is unchanged. n=50, so this is a gate against regressions, not proof of equality.
Same run also answers #1369 (graph strategy 0.933 recall@5 vs 0.980) - see that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request priority:high Fix in next release scope:core Core engine work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant