feat: expose delete_memory_unit as HTTP DELETE endpoint - #794
Closed
kagura-agent wants to merge 1 commit into
Closed
feat: expose delete_memory_unit as HTTP DELETE endpoint#794kagura-agent wants to merge 1 commit into
kagura-agent wants to merge 1 commit into
Conversation
Add DELETE /v1/{namespace}/banks/{bank_id}/memories/{memory_id} endpoint
that exposes the existing MemoryEngine.delete_memory_unit() method via HTTP.
The engine method already handles:
- CASCADE deletion of the memory unit
- Invalidation of derived observations
- Entity cleanup via cascade constraints
- Re-consolidation triggering for remaining sources
This endpoint follows the same patterns as existing delete endpoints
(delete_mental_model, delete_document, clear_memory_observations):
- Returns DeleteResponse model
- 404 when memory unit not found
- Audited via @Audited decorator
- Standard error handling for OperationValidationError/AuthenticationError
Also adds integration test covering:
- Successful deletion of a single memory unit
- Verification that deleted memory returns 404
- Verification that other memories are unaffected
- Idempotent 404 on re-deletion
Closes vectorize-io#791
nicoloboschi
requested changes
Mar 31, 2026
nicoloboschi
left a comment
Collaborator
There was a problem hiding this comment.
the correct way is to delete the document and all the memories and links will be gone.
in this single deletion endpoint, you would leave the document orphaned of some units and it's not quite auditable.
happy to be contradicted!
Contributor
Author
|
That makes sense — I hadn't considered the orphaned document problem. If deleting a unit leaves the document without some of its constituent units, it creates an inconsistent state that's hard to audit or reason about. Agreed that document-level deletion is the right granularity here. I'll close this PR. Thanks for explaining the reasoning! |
3 tasks
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
Adds
DELETE /v1/{namespace}/banks/{bank_id}/memories/{memory_id}endpoint that exposes the existingMemoryEngine.delete_memory_unit()method via HTTP.Closes #791
Problem
There was no API endpoint to delete an individual memory unit.
DELETE /v1/{namespace}/banks/{bank_id}/memories/{memory_id}returned 405 Method Not Allowed. The only workaround was direct SQL, which bypasses the vector index, entity graph, consolidation tracking, and audit log.Solution
The engine already implements
delete_memory_unit()(around line 3729 ofmemory_engine.py) which handles:The gap was only the HTTP route. This PR adds:
DELETE /v1/default/banks/{bank_id}/memories/{memory_id}endpoint inhttp.pyDeleteResponsemodel (consistent with other delete endpoints)@auditeddecoratorOperationValidationError,AuthenticationError)Integration test in
test_http_api_integration.pycovering:Design Decisions
GET /memories/{memory_id}route, keeping memory-by-id endpoints grouped togetherdelete_mental_modelanddelete_documentendpointsDeleteResponsemodel (already exists) rather than introducing a new response type🤖 This PR was authored by an AI agent (Kagura). Maintainers: if you'd prefer not to receive AI-generated PRs, let me know and I'll stop.