Agent Zero AI framework
short memory ids
frdel05a0803cb7a7
diff --git a/python/helpers/guids.py b/python/helpers/guids.pynew file mode 100644index 000000000..f0def4b4c--- /dev/null+++ b/python/helpers/guids.py@@ -0,0 +1,4 @@+import random, string++def generate_id(length: int = 8) -> str:+ return "".join(random.choices(string.ascii_letters + string.digits, k=length))diff --git a/python/helpers/memory.py b/python/helpers/memory.pyindex fcbcf302f..0eb203cbb 100644--- a/python/helpers/memory.py+++ b/python/helpers/memory.py@@ -2,6 +2,7 @@ from datetime import datetimefrom typing import Any, List, Sequencefrom langchain.storage import InMemoryByteStore, LocalFileStorefrom langchain.embeddings import CacheBackedEmbeddings+from python.helpers import guids# from langchain_chroma import Chromafrom langchain_community.vectorstores import FAISS@@ -24,7 +25,6 @@ import numpy as npfrom python.helpers.print_style import PrintStylefrom . import filesfrom langchain_core.documents import Document-import uuidfrom python.helpers import knowledge_importfrom python.helpers.log import Log, LogItemfrom enum import Enum@@ -361,7 +361,7 @@ class Memory:return ids[0]async def insert_documents(self, docs: list[Document]):- ids = [str(uuid.uuid4()) for _ in range(len(docs))]+ ids = [self._generate_doc_id() for _ in range(len(docs))]timestamp = self.get_timestamp()if ids:@@ -378,6 +378,13 @@ class Memory:def _save_db(self):Memory._save_db_file(self.db, self.memory_subdir)+ def _generate_doc_id(self):+ while True:+ doc_id = guids.generate_id(10) # random ID+ if not self.db.get_by_ids(doc_id): # check if exists+ return doc_id++@staticmethoddef _save_db_file(db: MyFaiss, memory_subdir: str):abs_dir = Memory._abs_db_dir(memory_subdir)