Skip to content

[BUG] DELETE /knowledge/entities/{id} returns 500 for non-markdown (file-type) entities #1033

Description

@ryanstraight

Bug Description

The per-entity delete endpoint returns 500 Internal Server Error for entities whose note_type is file (non-.md: .qmd, .csv, .py, .txt, .yml, sync-conflict files, etc.). Markdown note-entities delete cleanly. POST .../knowledge/delete-directory deletes the same file-type entities without error, so the data model supports their deletion — only the per-entity endpoint fails.

Steps To Reproduce

  1. Install version 0.20.3 (pip install basic-memory) and authenticate a cloud tenant.
  2. Identify a file-type entity (e.g. a .qmd or .csv) and confirm it exists: GET /v2/projects/<project_id>/knowledge/entities/<entity_id> → 200.
  3. Delete it: DELETE /v2/projects/<project_id>/knowledge/entities/<entity_id>500 Internal Server Error (repeatable, not transient — same entity 500s on retry).
  4. Delete its parent directory instead: POST /v2/projects/<project_id>/knowledge/delete-directory with {"directory": "<parent/dir>"}200, deletes it and its siblings successfully.

Expected Behavior

DELETE .../entities/{id} should delete file-type entities the same way delete-directory does — or at minimum return a meaningful error rather than a 500.

Actual Behavior

500 Internal Server Error for every non-.md entity. Observed at scale: in a bulk removal of ~910 entities via the per-entity endpoint, all 571 .md succeeded and all 339 non-.md returned 500. A subsequent delete-directory pass cleared 100% of the 339 with zero failures.

Environment

  • OS: Windows 11 (10.0.26220)
  • Python version: 3.13.2
  • Basic Memory version: 0.20.3
  • Installation method: pip (--user)
  • Claude Desktop version (if applicable): N/A (reproduced via cloud REST API)

Additional Context

  • The 500 body carries no detail (Internal Server Error).
  • Related (checked — distinct): Add delete-note CLI command (bm tool delete-note) #879 (add delete-note CLI) documents these same DELETE .../entities/{id} and delete-directory endpoints as fully working; it does not cover this file-type 500. No existing issue found for the 500-on-non-markdown behavior.

Possible Solution

The per-entity delete path likely assumes markdown structure during post-delete cleanup (search-index removal / relation / embedding cascade) and throws on file-type (note_type: file) entities, whereas entity_service.delete_directory() uses a path that handles them. Aligning the single-entity delete with the directory-delete code path is the likely fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions