Skip to content

Commit c06a820

Browse files
committed
fix(llama-index): use __type__ for rel type and MATCH+CREATE for edges
- Fix upsert_relations(): CoordiNode does not support MERGE for edge patterns; replace MATCH+MERGE with MATCH+MATCH+CREATE - Fix get_triplets(): type(r) returns null; use r.__type__ instead. Also use `or "RELATED"` guard (not default arg) since null differs from missing key - Fix get_rel_map(): same __type__ fix for variable-length path results where relationship data arrives as a list of dicts Closes #14
1 parent 50fb1f1 commit c06a820

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

  • llama-index-coordinode/llama_index/graph_stores/coordinode

llama-index-coordinode/llama_index/graph_stores/coordinode/base.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,20 @@ def get_triplets(
134134
rel_pattern = "[r]"
135135

136136
where = f"WHERE {' AND '.join(conditions)}" if conditions else ""
137+
# CoordiNode: use r.__type__ instead of type(r) — type() returns null.
138+
# Wildcard [r] pattern also returns no results; caller must supply
139+
# relation_names for wildcard queries to work.
137140
cypher = (
138141
f"MATCH (n)-{rel_pattern}->(m) {where} "
139-
"RETURN n, type(r) AS rel_type, m, n.id AS _src_id, m.id AS _dst_id "
142+
"RETURN n, r.__type__ AS rel_type, m, n.id AS _src_id, m.id AS _dst_id "
140143
"LIMIT 1000"
141144
)
142145
result = self._client.cypher(cypher, params=params)
143146

144147
triplets: list[list[LabelledNode]] = []
145148
for row in result:
146149
src_data = row.get("n", {})
147-
rel_type = row.get("rel_type", "RELATED")
150+
rel_type = row.get("rel_type") or "RELATED"
148151
dst_data = row.get("m", {})
149152
src_id = str(row.get("_src_id", ""))
150153
dst_id = str(row.get("_dst_id", ""))
@@ -195,7 +198,8 @@ def get_rel_map(
195198
rels = row.get("r", [])
196199
if isinstance(rels, list) and rels:
197200
first_rel = rels[0]
198-
rel_label = first_rel.get("type", "RELATED") if isinstance(first_rel, dict) else str(first_rel)
201+
# CoordiNode: use __type__ key instead of "type" — type() returns null
202+
rel_label = first_rel.get("__type__") or first_rel.get("type", "RELATED") if isinstance(first_rel, dict) else str(first_rel)
199203
else:
200204
rel_label = "RELATED"
201205
src = _node_result_to_labelled(src_id, src_data)
@@ -217,9 +221,13 @@ def upsert_relations(self, relations: list[Relation]) -> None:
217221
"""Upsert relationships into the graph."""
218222
for rel in relations:
219223
props = rel.properties or {}
224+
label = _cypher_ident(rel.label)
225+
# CoordiNode does not yet support MERGE for edge patterns; use CREATE.
226+
# Note: repeated calls will create duplicate edges until MERGE for
227+
# edges is implemented server-side.
220228
cypher = (
221-
f"MATCH (src {{id: $src_id}}), (dst {{id: $dst_id}}) "
222-
f"MERGE (src)-[r:{_cypher_ident(rel.label)}]->(dst) SET r += $props"
229+
f"MATCH (src {{id: $src_id}}) MATCH (dst {{id: $dst_id}}) "
230+
f"CREATE (src)-[r:{label}]->(dst) SET r += $props"
223231
)
224232
self._client.cypher(
225233
cypher,

0 commit comments

Comments
 (0)