fix: add thread-safe write lock to ChromaDB operations
This commit is contained in:
+8
-7
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user