Skip to content

Commit 64a2877

Browse files
committed
fix(adapters): fix wildcard [r] in refresh_schema, depth default, docstrings
- refresh_schema: build typed [r:T1|T2|...] pattern from rel_props keys (CoordiNode wildcard [r] returns no results) - get_rel_map: change default depth from 2 to 1 (depth != 1 now raises) - _stable_document_id docstring: clarify only __Document__ node ID is stable; MENTIONS edges are not deduplicated (unconditional CREATE) - upsert_relations: add comment explaining WHERE NOT (pattern) returns 0 rows silently in CoordiNode, hence unconditional CREATE is used
1 parent 19a3b34 commit 64a2877

2 files changed

Lines changed: 27 additions & 16 deletions

File tree

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

langchain-coordinode/langchain_coordinode/graph.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,23 @@ def refresh_schema(self) -> None:
7171
structured = _parse_schema(text)
7272
# Augment with relationship triples (start_label, type, end_label) via
7373
# Cypher — get_schema_text() only lists edge types without direction.
74-
try:
75-
rows = self._client.cypher(
76-
"MATCH (a)-[r]->(b) RETURN DISTINCT a.__label__ AS src, r.__type__ AS rel, b.__label__ AS dst"
77-
)
78-
structured["relationships"] = [
79-
{"start": row["src"], "type": row["rel"], "end": row["dst"]}
80-
for row in rows
81-
if row.get("src") and row.get("rel") and row.get("dst")
82-
]
83-
except Exception: # noqa: BLE001
84-
pass # Graph may have no relationships yet; structured["relationships"] stays []
74+
# CoordiNode: wildcard [r] returns no results; build typed pattern from
75+
# the rel_props keys returned by _parse_schema().
76+
rel_types = list(structured.get("rel_props", {}).keys())
77+
if rel_types:
78+
try:
79+
rel_filter = "|".join(_cypher_ident(t) for t in rel_types)
80+
rows = self._client.cypher(
81+
f"MATCH (a)-[r:{rel_filter}]->(b) "
82+
"RETURN DISTINCT a.__label__ AS src, r.__type__ AS rel, b.__label__ AS dst"
83+
)
84+
structured["relationships"] = [
85+
{"start": row["src"], "type": row["rel"], "end": row["dst"]}
86+
for row in rows
87+
if row.get("src") and row.get("rel") and row.get("dst")
88+
]
89+
except Exception: # noqa: BLE001
90+
pass # Graph may have no relationships yet; structured["relationships"] stays []
8591
self._structured_schema = structured
8692

8793
def add_graph_documents(
@@ -199,8 +205,11 @@ def _stable_document_id(source: Any) -> str:
199205
"""Return a deterministic ID for a LangChain Document.
200206
201207
Combines ``page_content`` and sorted ``metadata`` items so the same
202-
document produces the same node across different Python processes,
203-
making ``include_source=True`` re-ingest truly idempotent.
208+
document produces the same ``__Document__`` node ID across different
209+
Python processes. This makes document-node creation stable when
210+
``include_source=True`` is used, but does not make re-ingest fully
211+
idempotent because ``MENTIONS`` edges are not deduplicated until edge
212+
``MERGE``/dedup support is added to CoordiNode.
204213
"""
205214
content = getattr(source, "page_content", "") or ""
206215
metadata = getattr(source, "metadata", {}) or {}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def get_triplets(
164164
def get_rel_map(
165165
self,
166166
graph_nodes: list[LabelledNode],
167-
depth: int = 2,
167+
depth: int = 1,
168168
limit: int = 30,
169169
ignore_rels: list[str] | None = None,
170170
) -> list[list[LabelledNode]]:
@@ -235,10 +235,12 @@ def upsert_relations(self, relations: list[Relation]) -> None:
235235
props = rel.properties or {}
236236
label = _cypher_ident(rel.label)
237237
# CoordiNode does not yet support MERGE for edge patterns; use CREATE.
238+
# A WHERE NOT (src)-[:TYPE]->(dst) guard was tested but returns 0
239+
# rows silently in CoordiNode, making all CREATE statements no-ops.
240+
# Until server-side MERGE or pattern predicates are supported,
241+
# repeated calls will create duplicate edges.
238242
# SET r += $props is skipped when props is empty — SET r += {} is
239243
# not supported by all server versions.
240-
# Note: repeated calls will create duplicate edges until MERGE for
241-
# edges is implemented server-side.
242244
if props:
243245
cypher = (
244246
f"MATCH (src {{id: $src_id}}) MATCH (dst {{id: $dst_id}}) "

0 commit comments

Comments
 (0)