From 3abec7216819968c9447f610e57d05aec0bec60c Mon Sep 17 00:00:00 2001 From: Arun Sharma Date: Tue, 17 Mar 2026 16:54:25 -0700 Subject: [PATCH] fix for metadata defaulting None Also minimum icebug version is 12.2 --- pyproject.toml | 4 +-- src/memory/ladybug.py | 61 ++++++++++++++----------------------------- 2 files changed, 22 insertions(+), 43 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 45b3bc2..f202e26 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,10 +5,10 @@ description = "Agent memory interface implemented using LadybugDB" readme = "README.md" requires-python = ">=3.10" dependencies = [ - "real-ladybug>=0.14.0", + "real-ladybug>=0.15.2", "fastembed", "gliner2>=1.2.4", - "icebug>=12.0", + "icebug>=12.2", "polars>=1.38.1", "dotenv>=0.9.9", "litellm>=1.81.15", diff --git a/src/memory/ladybug.py b/src/memory/ladybug.py index 696bfa3..ef82618 100644 --- a/src/memory/ladybug.py +++ b/src/memory/ladybug.py @@ -1,5 +1,6 @@ from datetime import datetime from typing import Any, cast +import json import uuid import real_ladybug as lb @@ -232,40 +233,24 @@ def store( "updated_at": now.strftime("%Y-%m-%d %H:%M:%S"), } - if metadata: - import json - - parameters["metadata"] = json.dumps(metadata) - raw_result = self.conn.execute( - """ - CREATE (m:Memory { - content: $content, - memory_type: $memory_type, - importance: $importance, - metadata: CAST($metadata AS JSON), - embedding: $embedding, - created_at: timestamp($created_at), - updated_at: timestamp($updated_at) - }) - RETURN m.id - """, - parameters=parameters, - ) - else: - raw_result = self.conn.execute( - """ - CREATE (m:Memory { - content: $content, - memory_type: $memory_type, - importance: $importance, - embedding: $embedding, - created_at: timestamp($created_at), - updated_at: timestamp($updated_at) - }) - RETURN m.id - """, - parameters=parameters, - ) + if not metadata: + metadata = {} + parameters["metadata"] = json.dumps(metadata) + raw_result = self.conn.execute( + """ + CREATE (m:Memory { + content: $content, + memory_type: $memory_type, + importance: $importance, + metadata: CAST($metadata AS JSON), + embedding: $embedding, + created_at: timestamp($created_at), + updated_at: timestamp($updated_at) + }) + RETURN m.id + """, + parameters=parameters, + ) result = _get_result(raw_result) row = result.get_next() @@ -711,8 +696,6 @@ def _store_relations( start_timestamp: datetime | None = None, end_timestamp: datetime | None = None, ) -> None: - import json - now = datetime.now() start_ts = start_timestamp or now end_ts = end_timestamp or now @@ -783,7 +766,7 @@ def _store_relations( CREATE (s)-[r:Relations { relation_type: $relation_type, confidence: $confidence, - metadata: $metadata, + metadata: CAST($metadata AS JSON), start_timestamp: timestamp($start_timestamp), end_timestamp: timestamp($end_timestamp) }]->(t) @@ -1109,8 +1092,6 @@ def store_schema_hierarchy( Returns: Number of schema types stored """ - import json - now = datetime.now() count = 0 @@ -1170,8 +1151,6 @@ def get_schema_hierarchy(self) -> list[dict[str, Any]]: Returns: List of schema type dicts with type_name, base_type, etc. """ - import json - cypher = """ MATCH (s:DiscoveredSchemaType) RETURN s.type_name, s.base_type, s.confidence, s.sample_entities, s.entity_count