Fix #2331: 删除记忆接口返回成功但记忆未实际删除 - #2332
Conversation
🤖 Open Code ReviewTarget: PR #2332 🔍 OpenCodeReview found 2 issue(s) in this PR. 1.
|
🔧 Open Code Review requested Agent fixOpen Code Review found 3 issue(s). I have resumed the development Agent to fix them.
The Agent will push a new commit to this PR branch. OCR will recheck after the commit is pushed. |
- 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.
Description
Fixed bug #2331: delete memory API returned success but the memory remained searchable after deletion.
Root cause:
Neo4jCommunityGraphDB.delete_node_by_pramsinsrc/memos/graph_dbs/neo4j_community.pyonly removed nodes from the Neo4j graph but never purged the corresponding embedding vectors fromvec_db(Qdrant). Since all search calls go through vector similarity onvec_db, stale vectors caused deleted memories to keep surfacing in search results. Theclear()method and the reorganize path both cleanedvec_dbcorrectly —delete_node_by_pramssimply omitted that step.Fix: replaced the pre-delete count query with an ID-collecting query (
MATCH ... RETURN n.id AS id), then calledself.vec_db.delete(collected_ids)after the graphDETACH DELETE. Avec_dbfailure 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 intests/graph_dbs/test_delete_vec_cleanup.pycovering 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.
How Has This Been Tested?
Automated tests are pending.
Checklist
@MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller please review this PR.
Reviewer Checklist