fix: add thread-safe write lock to ChromaDB operations
This commit is contained in:
+13
-11
@@ -206,12 +206,13 @@ class DocumentIngestor:
|
||||
for i, c in enumerate(chunks)
|
||||
]
|
||||
|
||||
self.collection.add(
|
||||
ids=ids,
|
||||
embeddings=embeddings,
|
||||
documents=texts,
|
||||
metadatas=metadatas,
|
||||
)
|
||||
with self.db.write_lock:
|
||||
self.collection.add(
|
||||
ids=ids,
|
||||
embeddings=embeddings,
|
||||
documents=texts,
|
||||
metadatas=metadatas,
|
||||
)
|
||||
|
||||
return len(chunks)
|
||||
|
||||
@@ -226,10 +227,11 @@ class DocumentIngestor:
|
||||
def _remove_by_source(self, file_name: str) -> None:
|
||||
"""按 source_file 删除已有 chunks."""
|
||||
try:
|
||||
existing = self.collection.get(
|
||||
where={"source_file": file_name}
|
||||
)
|
||||
if existing and existing["ids"]:
|
||||
self.collection.delete(ids=existing["ids"])
|
||||
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"])
|
||||
except Exception:
|
||||
pass # collection 为空时 get 可能抛异常
|
||||
|
||||
Reference in New Issue
Block a user