Skip to content

Commit

Permalink
update graph
Browse files Browse the repository at this point in the history
  • Loading branch information
ILSparkle committed Dec 11, 2024
1 parent ef218d4 commit a2bf27e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/cardinal/graph/neo4j.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def insert_edge(self, head_key: Sequence[str], tail_key: Sequence[str], edge: Se
"""
MATCH (h:Node {key: $head_key})
MATCH (t:Node {key: $tail_key})
MERGE (h)-[r:EDGE {properties: $properties}]->(t)
CREATE (h)-[r:EDGE $properties]->(t)
""",
head_key=h,
tail_key=t,
properties=e,
properties=e.model_dump(),
)

def query_node(self, key: str) -> Optional[T]:
Expand Down
4 changes: 1 addition & 3 deletions tests/graph/test_graph_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ def test_graph_storage():
relation_keys_head = ["entity1"]
relation_keys_tail = ["entity2"]
relations = [
Relation(head="entity1", tail="entity2", desc="Connected", strength=1).model_dump_json()
Relation(head="entity1", tail="entity2", desc="Connected", strength=1)
]
storage.insert_edge(relation_keys_head, relation_keys_tail, relations)

# 查询边
relation = storage.query_edge("entity1", "entity2")
assert relation is not None, "Relation from entity1 to entity2 should exist"
import json
relation = json.loads(relation["properties"])
assert relation["desc"] == "Connected" and relation["strength"] == 1

# 查询节点的所有出边
Expand Down

0 comments on commit a2bf27e

Please sign in to comment.