fix: add thread-safe write lock to ChromaDB operations

This commit is contained in:
2026-07-05 01:34:36 +08:00
parent 10eda446ea
commit 81a8173a38
3 changed files with 35 additions and 24 deletions
+8 -7
View File
@@ -75,14 +75,15 @@ class Searcher:
return sorted(sources)
def delete_by_source(self, file_name: str) -> bool:
"""按文件名删除文档."""
"""按文件名删除文档 (线程安全)."""
try:
existing = self.collection.get(
where={"source_file": file_name}
)
if existing and existing["ids"]:
self.collection.delete(ids=existing["ids"])
return True
with self.db.write_lock:
existing = self.collection.get(
where={"source_file": file_name}
)
if existing and existing["ids"]:
self.collection.delete(ids=existing["ids"])
return True
except Exception:
pass
return False