From a73ae5c03ed92ed647803a36e02b9c2f98962835 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 8 Feb 2026 03:55:42 -0500 Subject: [PATCH] fix: delete document cleans up store files and embeddings --- db.go | 1 + main.go | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/db.go b/db.go index e250141..8d5d00a 100644 --- a/db.go +++ b/db.go @@ -381,6 +381,7 @@ func UpdateDocumentMetadata(id string, metadata map[string]string) error { // DeleteDocument removes a document from the database func DeleteDocument(id string) error { deleteFTS(id) + db.Exec(`DELETE FROM embeddings WHERE doc_id = ?`, id) _, err := db.Exec(`DELETE FROM documents WHERE id = ?`, id) return err } diff --git a/main.go b/main.go index 3319cd3..beeebb6 100644 --- a/main.go +++ b/main.go @@ -501,7 +501,7 @@ func deleteDocumentHandler(w http.ResponseWriter, r *http.Request) { return } - // Delete from database + // Delete from database (includes FTS and embeddings) DeleteDocument(id) // Delete record file @@ -509,6 +509,12 @@ func deleteDocumentHandler(w http.ResponseWriter, r *http.Request) { os.Remove(doc.RecordPath) } + // Delete store files (PDF/TXT) + for _, ext := range []string{".pdf", ".txt", ""} { + path := filepath.Join(storeDir, id+ext) + os.Remove(path) // ignore errors for non-existent files + } + w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(map[string]string{"status": "deleted"}) }