Agent Zero AI framework
fix: use async versions of faiss methods in memory helper (#406)
ehl0wr0ld662d8be8eb14
diff --git a/python/helpers/memory.py b/python/helpers/memory.pyindex 29d85cb44..7c43042d5 100644--- a/python/helpers/memory.py+++ b/python/helpers/memory.py@@ -326,7 +326,7 @@ class Memory:# fnd = self.db.get(where={"id": {"$in": document_ids}})# if fnd["ids"]: self.db.delete(ids=fnd["ids"])# tot += len(fnd["ids"])- self.db.delete(ids=document_ids)+ await self.db.adelete(ids=document_ids)tot += len(document_ids)# If fewer than K document IDs, break the loop@@ -339,7 +339,7 @@ class Memory:async def delete_documents_by_ids(self, ids: list[str]):# aget_by_ids is not yet implemented in faiss, need to do a workaround- rem_docs = self.db.get_by_ids(ids) # existing docs to remove (prevents error)+ rem_docs = await self.db.aget_by_ids(ids) # existing docs to remove (prevents error)if rem_docs:rem_ids = [doc.metadata["id"] for doc in rem_docs] # ids to removeawait self.db.adelete(ids=rem_ids)@@ -370,7 +370,7 @@ class Memory:model_config=self.agent.config.embeddings_model, input=docs_txt)- self.db.add_documents(documents=docs, ids=ids)+ await self.db.aadd_documents(documents=docs, ids=ids)self._save_db() # persistreturn ids