fix(memory): fix inflated edges_created, batch embed/search, add missing tests#1795
Merged
fix(memory): fix inflated edges_created, batch embed/search, add missing tests#1795
Conversation
This was
linked to
issues
Mar 14, 2026
- Deduplicate (src, tgt) pairs within each link_memory_notes pass via a HashSet so both A→B and B→A directions count as one edge, not two. Previously insert_edge returned Ok for the second normalised call (confidence update), inflating edges_created by the number of bidirectional matches (#1792). - Parallelize embed calls: all entity texts are embedded via futures::join_all, reducing N serial HTTP round-trips to one concurrent batch (#1793). - Parallelize search calls: all Qdrant search_collection calls are run via futures::join_all, reducing N serial round-trips to one concurrent batch (#1794). - Add link_memory_notes_edges_created_not_inflated: asserts edges_created == 1 when both endpoints of a pair are in entity_ids (#1792). - Add link_memory_notes_secondary_self_skip_guard: entity A has no qdrant_point_id in SQLite (primary guard inactive), secondary guard target_id == entity_id must prevent self-edges (#1790). - Add link_memory_notes_threshold_rejection: similarity_threshold = 2.0 rejects all candidates (max cosine = 1.0), verifying the score < threshold filter path (#1791). Closes #1790, #1791, #1792, #1793, #1794.
4c5acbc to
24da3bf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
edges_createdstat was inflated when both endpoints of a pair appeared inentity_ids.insert_edgereturnsOkeven for duplicate calls (it updates confidence), so the counter incremented twice per physical edge. AddedHashSet<(i64, i64)>deduplication per pass.provider.embed()calls with a singlefutures::join_all, reducing embed latency from O(N) serial RTTs to O(1) concurrent.embedding_store.search_collection()calls with a singlefutures::join_all, reducing Qdrant search latency from O(N) serial RTTs to O(1) concurrent.link_memory_notes_secondary_self_skip_guard— seeds entity A withoutqdrant_point_idin SQLite (primary point-id guard inactive), verifies secondarytarget_id == entity_idguard blocks self-edges when A appears in its own top-K results.link_memory_notes_threshold_rejection— setssimilarity_threshold = 2.0(above maximum cosine similarity 1.0), asserts zero edges created, covering thescore < thresholdfilter path.link_memory_notes_edges_created_not_inflated— assertsedges_created == 1when both pair endpoints are inentity_ids, acting as a regression guard for the double-count bug.Test plan
link_memory_notesunit tests pass (including 3 new ones)cargo +nightly fmt --checkpassescargo clippy --workspace --features full -- -D warningspasses