fix: delete document cleans up store files and embeddings
This commit is contained in:
parent
00d0b0a0d7
commit
a73ae5c03e
1
db.go
1
db.go
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
8
main.go
8
main.go
|
|
@ -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"})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue