Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
61 changes: 20 additions & 41 deletions src/memory/ladybug.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime
from typing import Any, cast
import json
import uuid

import real_ladybug as lb
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1109,8 +1092,6 @@ def store_schema_hierarchy(
Returns:
Number of schema types stored
"""
import json

now = datetime.now()
count = 0

Expand Down Expand Up @@ -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
Expand Down
Loading