Bulk delete memories by filter with dry-run default#73
Merged
Conversation
POST /api/v1/memories/delete_bulk deletes every memory matching exact filters (agent_id, run_id, source, confidence, review_status) so a bad import run or a misbehaving capture agent's writes can be undone in two calls instead of scripted one-by-one deletes against a 100-item page cap. Safety rails: dry-run by default (count + 10-item sample, nothing deleted) until the caller re-posts with confirm=true; at least one filter besides user_id is required so an unscoped POST can never wipe the store; deletions are capped at 1000 per call with has_more signalling the caller to loop, bounding request duration under proxy timeouts. Deletions go through Memory.delete per ID, keeping mem0's history consistent. Deliberately not exposed as an MCP tool. Deletions are logged and counted in a new memories_bulk_deleted_total metric. Closes #67 https://claude.ai/code/session_01H2Dbh6kD8bseWZZEf7kGhx
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.
Closes #67
What
POST /api/v1/memories/delete_bulkdeletes every memory matching exact-match filters (agent_id,run_id,source,confidence,review_status, optionaluser_id), so a bad import run or a misbehaving capture agent's writes can be undone in two curl calls instead of scripting one-by-one deletes against the 100-item list page cap:Safety rails
confirm: falsereports the match count and a 10-item sample; nothing is deleted until the caller re-posts withconfirm: true.user_idis required (422 otherwise); deleting the entire store through this endpoint is deliberately impossible.matched/deletedare per-call);has_moretells the caller to loop. This keeps request duration under proxy timeouts."error": "delete_failed_partway"with the partial count instead of losing it to a 500; deletes are idempotent, so the caller just re-posts.Memory.deleteper ID, never a raw vector-store filter delete, so mem0's bookkeeping doesn't drift.Confirmed deletions emit a structlog warning with the filter and counts, and increment a new
memories_bulk_deleted_totalmetric.Tests
8 new tests across
tests/test_rest.py/tests/test_memory.py: unscoped-request 422 (includinguser_id-only), dry-run deletes nothing, confirm deletes each ID through mem0 (raw vector-store delete asserted unused), filter composition, per-call cap +has_more, 10-item sample cap, partial-failure reporting. Full suite: 175 passed,ruffclean.Review
Adversarial review surfaced 5 candidates; 4 were fixed (defensive
getattron point IDs, partial-failure handling,matched-is-per-call doc clarification, clearer 422 wording).https://claude.ai/code/session_01H2Dbh6kD8bseWZZEf7kGhx
Generated by Claude Code