Skip to content

Fix #2331: 删除记忆接口返回成功但记忆未实际删除 - #2574

Merged
endxxxx merged 4 commits into
MemTensor:dev-v2.0.37from
Memtensor-AI:bugfix/autodev-2331-20260902095324632
Nov 19, 2026
Merged

endxxxx merged 4 commits into
MemTensor:dev-v2.0.37from
Memtensor-AI:bugfix/autodev-2331-20260902095324632

Conversation

@syzsunshine219

@syzsunshine219 syzsunshine219 commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Restores the change proposed in #2332 for review against main after its former base branch, dev-v2.0.33, was deleted. The source commits and authors are preserved.

Source head: 55178d01f9194f8bebd58a1f8812732ca7cf0c5a

This PR is open for review. Review and CI against the current base are pending; validation claims in the original description below refer to the earlier snapshot. The original discussion and evidence remain in #2332.


Original change description

Description

Fixed bug #2331: delete memory API returned success but the memory remained searchable after deletion.

Root cause: Neo4jCommunityGraphDB.delete_node_by_prams in src/memos/graph_dbs/neo4j_community.py only removed nodes from the Neo4j graph but never purged the corresponding embedding vectors from vec_db (Qdrant). Since all search calls go through vector similarity on vec_db, stale vectors caused deleted memories to keep surfacing in search results. The clear() method and the reorganize path both cleaned vec_db correctly — delete_node_by_prams simply omitted that step.

Fix: replaced the pre-delete count query with an ID-collecting query (MATCH ... RETURN n.id AS id), then called self.vec_db.delete(collected_ids) after the graph DETACH DELETE. A vec_db failure is caught and logged as a warning rather than re-raised, so a transient vector store error does not roll back an already-committed graph deletion. Added 5 regression tests in tests/graph_dbs/test_delete_vec_cleanup.py covering delete-by-memory-ids, delete-by-filter, empty-list early-return, no-args early-return, and vec_db failure resilience. All 5 tests pass; all 36 existing graph_dbs tests continue to pass; ruff lint clean.

Related Issue (Required): Fixes #2331

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g. code style improvements, linting)
  • Documentation update

How Has This Been Tested?

Automated tests are pending.

  • Unit Test
  • Test Script Or Test Steps (please provide)
  • Pipeline Automated API Test (please provide)

Checklist

  • I have performed a self-review of my own code
  • I have commented my code in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have created related documentation issue/PR in MemOS-Docs (if applicable)
  • I have linked the issue to this PR (if applicable)
  • I have mentioned the person who will review this PR

@MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller please review this PR.

Reviewer Checklist

AutoDev Bot and others added 2 commits September 2, 2026 18:13
- Filter None ids out of collected_ids before vec_db.delete to avoid
  passing Null neo4j values to the vector store.
- Use lazy %-style formatting for id_collect_query log call, matching
  the sibling log line's style.
- Assert get_by_metadata is called in the filter-path regression test
  so the mock actually exercises the branch it documents.
@syzsunshine219
syzsunshine219 marked this pull request as ready for review November 9, 2026 15:47
@endxxxx
endxxxx changed the base branch from main to dev-v2.0.37 November 19, 2026 11:36
@endxxxx
endxxxx merged commit ad9cf7b into MemTensor:dev-v2.0.37 Nov 19, 2026
16 checks passed
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.

删除记忆接口返回成功但记忆未实际删除

2 participants