fix: delete document cleans up store files and embeddings

This commit is contained in:
James 2026-02-08 03:55:42 -05:00
parent 00d0b0a0d7
commit a73ae5c03e
2 changed files with 8 additions and 1 deletions

1
db.go
View File

@ -381,6 +381,7 @@ func UpdateDocumentMetadata(id string, metadata map[string]string) error {
// DeleteDocument removes a document from the database // DeleteDocument removes a document from the database
func DeleteDocument(id string) error { func DeleteDocument(id string) error {
deleteFTS(id) deleteFTS(id)
db.Exec(`DELETE FROM embeddings WHERE doc_id = ?`, id)
_, err := db.Exec(`DELETE FROM documents WHERE id = ?`, id) _, err := db.Exec(`DELETE FROM documents WHERE id = ?`, id)
return err return err
} }

View File

@ -501,7 +501,7 @@ func deleteDocumentHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
// Delete from database // Delete from database (includes FTS and embeddings)
DeleteDocument(id) DeleteDocument(id)
// Delete record file // Delete record file
@ -509,6 +509,12 @@ func deleteDocumentHandler(w http.ResponseWriter, r *http.Request) {
os.Remove(doc.RecordPath) 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") w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]string{"status": "deleted"}) json.NewEncoder(w).Encode(map[string]string{"status": "deleted"})
} }