Skip to content

feat: add DELETE endpoint for individual memory units - #796

Closed
chriscoey wants to merge 3 commits into
vectorize-io:mainfrom
chriscoey:feat/delete-memory-unit
Closed

feat: add DELETE endpoint for individual memory units#796
chriscoey wants to merge 3 commits into
vectorize-io:mainfrom
chriscoey:feat/delete-memory-unit

Conversation

@chriscoey

@chriscoey chriscoey commented Mar 31, 2026

Copy link
Copy Markdown

Closes #791.

Summary

Add DELETE /v1/default/banks/{bank_id}/memories/{memory_id} — exposes the existing MemoryEngine.delete_memory_unit() method as an HTTP route.

The engine method already handled CASCADE deletion, observation invalidation, and re-consolidation. This PR adds the HTTP route and fixes two gaps in the engine method:

  1. Bank isolation: delete_memory_unit() previously accepted only unit_id without bank scoping — a caller could delete a memory from any bank by knowing its UUID. Now filters with AND bank_id = $2 and passes bank_id from the URL path.
  2. Write authorization: Added validate_bank_write() call, matching every other destructive method in the engine.

Also: response model with OpenAPI example, UUID validation (400 not 500), cross-bank isolation test, updated all callers (MCP tools, existing engine tests).

Note: Checked-in OpenAPI spec and generated clients will need regeneration via ./scripts/generate-openapi.sh after merge.

Test plan

  • Existing engine tests (test_observation_invalidation.py) — updated to pass bank_id
  • HTTP integration: create → delete → verify gone → 404 on re-delete
  • Cross-bank isolation: delete via wrong bank returns 404
  • Invalid UUID returns 400
  • Verify audit log records the deletion
  • Regenerate OpenAPI spec after merge

chriscoey and others added 3 commits March 30, 2026 22:18
Expose the existing `MemoryEngine.delete_memory_unit()` as an HTTP
DELETE route at `/v1/default/banks/{bank_id}/memories/{memory_id}`.

The engine method (line 3729) already handles CASCADE deletion of links
and entity associations, observation invalidation, and re-consolidation
triggering. This commit only adds the HTTP route and response model.

Closes vectorize-io#791

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Tests the new DELETE /v1/default/banks/{bank_id}/memories/{memory_id}
endpoint: successful deletion (200), memory removed from list, and
404 on non-existent or already-deleted memory.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ry_unit

The engine's delete_memory_unit() had two gaps:

1. No bank_id filter on SQL queries — a caller could delete a memory
   from any bank by knowing its UUID, violating bank isolation.
2. No validate_bank_write() call — bypassed write authorization that
   all other destructive methods enforce.

Changes:
- Add bank_id parameter to interface and implementation
- Add AND bank_id = $2 to SELECT and DELETE queries
- Add validate_bank_write() call matching delete_document pattern
- Update all callers: HTTP handler, MCP tools, existing tests
- Rename response field unit_id → memory_id for consistency
- Add model_config with json_schema_extra example
- Add UUID validation in handler (400 instead of 500)
- Add cross-bank isolation test and invalid UUID test
- Use explicit response model construction

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

@nicoloboschi nicoloboschi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@chriscoey

Copy link
Copy Markdown
Author

Makes sense, you're right. I see the document delete endpoint already handles cascading cleanup correctly.

The use case I had in mind was individual memory units becoming stale over time while other units from the same document are still valid — document-level deletion felt too coarse for that. But I see now that the document is the right unit of management here, and punching holes in it at the unit level breaks that integrity.

Happy to close this.

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.

feat: expose delete_memory_unit as HTTP DELETE route

2 participants