From 6b0408d47ca06153663424d3befb76f33cad0300 Mon Sep 17 00:00:00 2001 From: Robert Brennan Date: Thu, 18 Apr 2024 07:31:39 -0400 Subject: [PATCH] use threading to insert docs into the db (#1191) --- agenthub/monologue_agent/utils/memory.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/agenthub/monologue_agent/utils/memory.py b/agenthub/monologue_agent/utils/memory.py index e14fdf1e08..c0222efd3e 100644 --- a/agenthub/monologue_agent/utils/memory.py +++ b/agenthub/monologue_agent/utils/memory.py @@ -1,3 +1,5 @@ +from threading import Thread + import chromadb from llama_index.core import Document from llama_index.core.retrievers import VectorIndexRetriever @@ -85,6 +87,10 @@ class LongTermMemory: ) self.thought_idx += 1 logger.debug('Adding %s event to memory: %d', t, self.thought_idx) + thread = Thread(target=self._add_doc, args=(doc,)) + thread.start() # We add the doc concurrently so we don't have to wait ~500ms for the insert + + def _add_doc(self, doc): self.index.insert(doc) def search(self, query: str, k: int = 10):