Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: Enhancements in CommonVector and test_server for Handling Data (#933)
Adam405b3429a0a8
diff --git a/memgpt/agent_store/db.py b/memgpt/agent_store/db.pyindex f7f5e0204..38cfef8cf 100644--- a/memgpt/agent_store/db.py+++ b/memgpt/agent_store/db.py@@ -1,4 +1,5 @@import os+import base64from sqlalchemy import create_engine, Column, String, BIGINT, select, inspect, text, JSON, BLOB, BINARY, ARRAY, DateTimefrom sqlalchemy import func, or_, and_from sqlalchemy import desc, asc@@ -62,17 +63,23 @@ class CommonVector(TypeDecorator):return dialect.type_descriptor(BINARY())def process_bind_param(self, value, dialect):- if value:- assert isinstance(value, np.ndarray) or isinstance(value, list), f"Value must be of type np.ndarray or list, got {type(value)}"- assert isinstance(value[0], float), f"Value must be of type float, got {type(value[0])}"- return np.array(value).tobytes()- else:+ if value is None:return value+ # Ensure value is a numpy array+ if isinstance(value, list):+ value = np.array(value, dtype=np.float32)+ # Serialize numpy array to bytes, then encode to base64 for universal compatibility+ return base64.b64encode(value.tobytes())def process_result_value(self, value, dialect):if not value:return value- return np.frombuffer(value)+ # Check database type and deserialize accordingly+ if dialect.name == "sqlite":+ # Decode from base64 and convert back to numpy array+ value = base64.b64decode(value)+ # For PostgreSQL, value is already in bytes+ return np.frombuffer(value, dtype=np.float32)# Custom serialization / de-serialization for JSON columnsdiff --git a/memgpt/metadata.py b/memgpt/metadata.pyindex 4d0873b1c..2741e02e1 100644--- a/memgpt/metadata.py+++ b/memgpt/metadata.py@@ -208,8 +208,11 @@ class MetadataStore:else:raise ValueError(f"Invalid metadata storage type: {config.metadata_storage_type}")- # TODO: check to see if table(s) need to be greated or not+ # Ensure valid URI+ if not self.uri:+ raise ValueError("Database URI is not provided or is invalid.")+ # Check if tables need to be createdself.engine = create_engine(self.uri)Base.metadata.create_all(self.engine, tables=[UserModel.__table__, AgentModel.__table__, SourceModel.__table__, AgentSourceMappingModel.__table__]diff --git a/tests/test_server.py b/tests/test_server.pyindex e5071cf02..fd3b65f44 100644--- a/tests/test_server.py+++ b/tests/test_server.py@@ -1,6 +1,7 @@import uuidimport osimport memgpt.utils as utils+from dotenv import load_dotenvutils.DEBUG = Truefrom memgpt.config import MemGPTConfig@@ -12,13 +13,17 @@ from .utils import wipe_config, wipe_memgpt_homedef test_server():+ load_dotenv()wipe_memgpt_home()+ # Use os.getenv with a fallback to os.environ.get+ db_url = os.getenv("PGVECTOR_TEST_DB_URL") or os.environ.get("PGVECTOR_TEST_DB_URL")+if os.getenv("OPENAI_API_KEY"):config = MemGPTConfig(- archival_storage_uri=os.getenv("PGVECTOR_TEST_DB_URL"),- recall_storage_uri=os.getenv("PGVECTOR_TEST_DB_URL"),- metadata_storage_uri=os.getenv("PGVECTOR_TEST_DB_URL"),+ archival_storage_uri=db_url,+ recall_storage_uri=db_url,+ metadata_storage_uri=db_url,archival_storage_type="postgres",recall_storage_type="postgres",metadata_storage_type="postgres",@@ -40,9 +45,9 @@ def test_server():)else: # hostedconfig = MemGPTConfig(- archival_storage_uri=os.getenv("PGVECTOR_TEST_DB_URL"),- recall_storage_uri=os.getenv("PGVECTOR_TEST_DB_URL"),- metadata_storage_uri=os.getenv("PGVECTOR_TEST_DB_URL"),+ archival_storage_uri=db_url,+ recall_storage_uri=db_url,+ metadata_storage_uri=db_url,archival_storage_type="postgres",recall_storage_type="postgres",metadata_storage_type="postgres",@@ -61,6 +66,7 @@ def test_server():),)credentials = MemGPTCredentials()+config.save()credentials.save()