fix: use async versions of faiss methods in memory helper (#406)

Co-authored-by: Rafael Uzarowski <uzarowski.rafael@proton.me>

ehl0wr0ld committed May 30, 2025 at 22:03 UTC 662d8be8eb14d77e15e8e76c21518c49c90f8f84
1 file changed +3 -3
python/helpers/memory.py
+3 -3
@@ -326,7 +326,7 @@ class Memory:
326 # fnd = self.db.get(where={"id": {"$in": document_ids}})
327 # if fnd["ids"]: self.db.delete(ids=fnd["ids"])
328 # tot += len(fnd["ids"])
329 - self.db.delete(ids=document_ids)
329 + await self.db.adelete(ids=document_ids)
330 tot += len(document_ids)
331
332 # If fewer than K document IDs, break the loop
@@ -339,7 +339,7 @@ class Memory:
339
340 async def delete_documents_by_ids(self, ids: list[str]):
341 # aget_by_ids is not yet implemented in faiss, need to do a workaround
342 - rem_docs = self.db.get_by_ids(ids) # existing docs to remove (prevents error)
342 + rem_docs = await self.db.aget_by_ids(ids) # existing docs to remove (prevents error)
343 if rem_docs:
344 rem_ids = [doc.metadata["id"] for doc in rem_docs] # ids to remove
345 await self.db.adelete(ids=rem_ids)
@@ -370,7 +370,7 @@ class Memory:
370 model_config=self.agent.config.embeddings_model, input=docs_txt
371 )
372
373 - self.db.add_documents(documents=docs, ids=ids)
373 + await self.db.aadd_documents(documents=docs, ids=ids)
374 self._save_db() # persist
375 return ids
376