Skip to content

Commit d01c8cf

Browse files
authored
hotfix:noe4j community dataformat (#353)
1 parent ccef651 commit d01c8cf

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/memos/graph_dbs/neo4j.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ def _prepare_node_metadata(metadata: dict[str, Any]) -> dict[str, Any]:
3838
if embedding and isinstance(embedding, list):
3939
metadata["embedding"] = [float(x) for x in embedding]
4040

41+
# serialization
42+
if metadata["sources"]:
43+
for idx in range(len(metadata["sources"])):
44+
metadata["sources"][idx] = json.dumps(metadata["sources"][idx])
4145
return metadata
4246

4347

src/memos/graph_dbs/neo4j_community.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from typing import Any
23

34
from memos.configs.graph_db import Neo4jGraphDBConfig
@@ -49,6 +50,10 @@ def add_node(self, id: str, memory: str, metadata: dict[str, Any]) -> None:
4950
# Safely process metadata
5051
metadata = _prepare_node_metadata(metadata)
5152

53+
# serialization
54+
if metadata["sources"]:
55+
for idx in range(len(metadata["sources"])):
56+
metadata["sources"][idx] = json.dumps(metadata["sources"][idx])
5257
# Extract required fields
5358
embedding = metadata.pop("embedding", None)
5459
if embedding is None:
@@ -298,7 +303,16 @@ def _parse_node(self, node_data: dict[str, Any]) -> dict[str, Any]:
298303
if time_field in node and hasattr(node[time_field], "isoformat"):
299304
node[time_field] = node[time_field].isoformat()
300305
node.pop("user_name", None)
301-
306+
# serialization
307+
if node["sources"]:
308+
for idx in range(len(node["sources"])):
309+
if not (
310+
isinstance(node["sources"][idx], str)
311+
and node["sources"][idx][0] == "{"
312+
and node["sources"][idx][0] == "}"
313+
):
314+
break
315+
node["sources"][idx] = json.loads(node["sources"][idx])
302316
new_node = {"id": node.pop("id"), "memory": node.pop("memory", ""), "metadata": node}
303317
try:
304318
vec_item = self.vec_db.get_by_id(new_node["id"])

0 commit comments

Comments
 (0)