Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: patch TEI error in load (#725)
Charles Packer02a8a42cb002
diff --git a/configs/memgpt_hosted.json b/configs/memgpt_hosted.jsonindex e7958cfa6..b75ceabdf 100644--- a/configs/memgpt_hosted.json+++ b/configs/memgpt_hosted.json@@ -7,6 +7,6 @@"embedding_endpoint_type": "hugging-face","embedding_endpoint": "https://embeddings.memgpt.ai","embedding_model": "BAAI/bge-large-en-v1.5",- "embedding_dim": 1536,+ "embedding_dim": 1024,"embedding_chunk_size": 300}\ No newline at end of filediff --git a/memgpt/cli/cli_load.py b/memgpt/cli/cli_load.pyindex 780a28a0f..daccff5fc 100644--- a/memgpt/cli/cli_load.py+++ b/memgpt/cli/cli_load.py@@ -14,6 +14,7 @@ import typerfrom memgpt.embeddings import embedding_modelfrom memgpt.connectors.storage import StorageConnector, Passagefrom memgpt.config import MemGPTConfig+from memgpt.utils import suppress_stdoutfrom llama_index import (VectorStoreIndex,@@ -28,12 +29,14 @@ app = typer.Typer()def store_docs(name, docs, show_progress=True):"""Common function for embedding and storing documents"""- storage = StorageConnector.get_storage_connector(name=name)+ with suppress_stdout():+ storage = StorageConnector.get_storage_connector(name=name)config = MemGPTConfig.load()embed_model = embedding_model()# use llama index to run embeddings code- service_context = ServiceContext.from_defaults(llm=None, embed_model=embed_model, chunk_size=config.embedding_chunk_size)+ with suppress_stdout():+ service_context = ServiceContext.from_defaults(llm=None, embed_model=embed_model, chunk_size=config.embedding_chunk_size)index = VectorStoreIndex.from_documents(docs, service_context=service_context, show_progress=True)embed_dict = index._vector_store._data.embedding_dictnode_dict = index._docstore.docsdiff --git a/memgpt/configs/memgpt_hosted.json b/memgpt/configs/memgpt_hosted.jsonindex e7958cfa6..b75ceabdf 100644--- a/memgpt/configs/memgpt_hosted.json+++ b/memgpt/configs/memgpt_hosted.json@@ -7,6 +7,6 @@"embedding_endpoint_type": "hugging-face","embedding_endpoint": "https://embeddings.memgpt.ai","embedding_model": "BAAI/bge-large-en-v1.5",- "embedding_dim": 1536,+ "embedding_dim": 1024,"embedding_chunk_size": 300}\ No newline at end of filediff --git a/memgpt/embeddings.py b/memgpt/embeddings.pyindex fc3023d43..c5a70cad7 100644--- a/memgpt/embeddings.py+++ b/memgpt/embeddings.py@@ -51,7 +51,22 @@ class EmbeddingEndpoint(BaseEmbedding):timeout=self._timeout,)- return response.json()+ response_json = response.json()++ if isinstance(response_json, list):+ # embedding directly in response+ embedding = response_json+ elif isinstance(response_json, dict):+ # TEI embedding packaged inside openai-style response+ try:+ embedding = response_json["data"][0]["embedding"]+ except (KeyError, IndexError):+ raise TypeError(f"Got back an unexpected payload from text embedding function, response=\n{response_json}")+ else:+ # unknown response, can't parse+ raise TypeError(f"Got back an unexpected payload from text embedding function, response=\n{response_json}")++ return embeddingasync def _acall_api(self, text: str) -> List[float]:import httpx@@ -66,8 +81,22 @@ class EmbeddingEndpoint(BaseEmbedding):json=json_data,timeout=self._timeout,)+ response_json = response.json()++ if isinstance(response_json, list):+ # embedding directly in response+ embedding = response_json+ elif isinstance(response_json, dict):+ # TEI embedding packaged inside openai-style response+ try:+ embedding = response_json["data"][0]["embedding"]+ except (KeyError, IndexError):+ raise TypeError(f"Got back an unexpected payload from text embedding function, response=\n{response_json}")+ else:+ # unknown response, can't parse+ raise TypeError(f"Got back an unexpected payload from text embedding function, response=\n{response_json}")- return response.json()+ return embeddingdef _get_query_embedding(self, query: str) -> list[float]:"""get query embedding."""diff --git a/memgpt/memory.py b/memgpt/memory.pyindex b851895c4..8d8a899fd 100644--- a/memgpt/memory.py+++ b/memgpt/memory.py@@ -341,16 +341,6 @@ class EmbeddingArchivalMemory(ArchivalMemory):# breakup string into passagesfor node in parser.get_nodes_from_documents([Document(text=memory_string)]):embedding = self.embed_model.get_text_embedding(node.text)- # fixing weird bug where type returned isn't a list, but instead is an object- # eg: embedding={'object': 'list', 'data': [{'object': 'embedding', 'embedding': [-0.0071973633, -0.07893023,- if isinstance(embedding, dict):- try:- embedding = embedding["data"][0]["embedding"]- except (KeyError, IndexError):- # TODO as a fallback, see if we can find any lists in the payload- raise TypeError(- f"Got back an unexpected payload from text embedding function, type={type(embedding)}, value={embedding}"- )passages.append(Passage(text=node.text, embedding=embedding, doc_id=f"agent_{self.agent_config.name}_memory"))# insert passages@@ -369,16 +359,6 @@ class EmbeddingArchivalMemory(ArchivalMemory):if query_string not in self.cache:# self.cache[query_string] = self.retriever.retrieve(query_string)query_vec = self.embed_model.get_text_embedding(query_string)- # fixing weird bug where type returned isn't a list, but instead is an object- # eg: embedding={'object': 'list', 'data': [{'object': 'embedding', 'embedding': [-0.0071973633, -0.07893023,- if isinstance(query_vec, dict):- try:- query_vec = query_vec["data"][0]["embedding"]- except (KeyError, IndexError):- # TODO as a fallback, see if we can find any lists in the payload- raise TypeError(- f"Got back an unexpected payload from text embedding function, type={type(query_vec)}, value={query_vec}"- )self.cache[query_string] = self.storage.query(query_string, query_vec, top_k=self.top_k)start = int(start if start else 0)