Skip to content

fix(neo4j): cascade delete vectors from Qdrant when deleting memory nodes#1862

Open
AYin-Z wants to merge 1 commit into
MemTensor:mainfrom
AYin-Z:fix/qdrant-cascade-delete
Open

fix(neo4j): cascade delete vectors from Qdrant when deleting memory nodes#1862
AYin-Z wants to merge 1 commit into
MemTensor:mainfrom
AYin-Z:fix/qdrant-cascade-delete

Conversation

@AYin-Z

@AYin-Z AYin-Z commented Jun 2, 2026

Copy link
Copy Markdown

Description

delete_node_by_prams() only ran DETACH DELETE on Neo4j, leaving orphan vectors behind in Qdrant. Every memory deletion via the API created a leaked vector in Qdrant with no corresponding Neo4j node.

Root Cause

The write path (add_node / add_nodes_batch) is symmetric — it writes to both Neo4j and Qdrant in the same method. But the delete path only touched Neo4j:

# Before: count then delete Neo4j only
count_query = f"MATCH (n:Memory) WHERE ... RETURN count(n) AS node_count"
...
session.run("MATCH (n:Memory) WHERE ... DETACH DELETE n", **params)
# ← No vec_db.delete() call

Note that clear() and the newer delete_node_by_mem_cube_id() both correctly call vec_db.delete() — this was simply an omission in delete_node_by_prams.

Fix

  1. Replace count_query with an ids_query that collects node IDs
  2. Delete from Neo4j (same as before)
  3. Call self.vec_db.delete(deleted_ids) after successful Neo4j deletion

Verification

  • BaseVecDB.delete(ids) is an abstract method with working implementations in both QdrantVecDB and MilvusVecDB
  • self.vec_db is initialized in the constructor and used elsewhere in the same class
  • The fix gracefully falls back with a warning log if Qdrant cleanup fails

…odes

delete_node_by_prams only ran DETACH DELETE on Neo4j, leaving orphan
vectors in Qdrant. Since add_node/add_nodes_batch write to both
stores symmetrically, the delete path should also clean up Qdrant.

This collects matching node IDs before Neo4j deletion, then calls
vec_db.delete() with the collected IDs. Falls back gracefully with
a warning if Qdrant cleanup fails.
@Memtensor-AI Memtensor-AI changed the base branch from main to dev-20260604-v2.0.19 June 10, 2026 15:43
@Memtensor-AI Memtensor-AI changed the base branch from dev-20260604-v2.0.19 to dev-v2.0.22 July 1, 2026 13:16
@Memtensor-AI

Copy link
Copy Markdown
Collaborator

Automated Test Results: PASSED

Cloud test-engine rerun against dev-v2.0.22 completed successfully.

  • Run: tr-c67f3a71-38d on cloud test-engine 10011
  • memos_python_core/changed-python-source: 2 passed, 0 failed, 0 skipped

Manual code review is still required before merge.

@CarltonXiang CarltonXiang deleted the branch MemTensor:main July 3, 2026 07:25
@syzsunshine219 syzsunshine219 reopened this Jul 3, 2026
@syzsunshine219 syzsunshine219 added the needs-audit Requires manual audit before merge label Jul 3, 2026
@syzsunshine219 syzsunshine219 changed the base branch from dev-v2.0.22 to main July 3, 2026 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-audit Requires manual audit before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants