Skip to content

Commit 27e92f3

Browse files
committed
fix(langchain,tests): implement relationship introspection via Cypher, fix formatting
- refresh_schema() now populates relationships via MATCH (a)-[r]->(b) Cypher query since get_schema_text() only lists edge types without direction info - Remove TODO comment from _parse_schema (logic lives in refresh_schema) - Apply ruff format to tests/integration/test_sdk.py (blank line after fixture removal)
1 parent f843229 commit 27e92f3

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

langchain-coordinode/langchain_coordinode/graph.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,21 @@ def refresh_schema(self) -> None:
6767
"""Fetch current schema from CoordiNode."""
6868
text = self._client.get_schema_text()
6969
self._schema = text
70-
# Parse schema text into structured form expected by LangChain
71-
self._structured_schema = _parse_schema(text)
70+
structured = _parse_schema(text)
71+
# Augment with relationship triples (start_label, type, end_label) via
72+
# Cypher — get_schema_text() only lists edge types without direction.
73+
try:
74+
rows = self._client.cypher(
75+
"MATCH (a)-[r]->(b) RETURN DISTINCT labels(a)[0] AS src, type(r) AS rel, labels(b)[0] AS dst"
76+
)
77+
structured["relationships"] = [
78+
{"start": row["src"], "type": row["rel"], "end": row["dst"]}
79+
for row in rows
80+
if row.get("src") and row.get("rel") and row.get("dst")
81+
]
82+
except Exception: # noqa: BLE001
83+
pass # Graph may have no relationships yet; structured["relationships"] stays []
84+
self._structured_schema = structured
7285

7386
def query(
7487
self,
@@ -129,9 +142,6 @@ def _parse_schema(schema_text: str) -> dict[str, Any]:
129142
"""
130143
node_props: dict[str, list[dict[str, str]]] = {}
131144
rel_props: dict[str, list[dict[str, str]]] = {}
132-
# TODO: CoordiNode's schema text does not include relationship direction info
133-
# (start_label → end_label). Populate via Cypher introspection when needed:
134-
# MATCH (a)-[r]->(b) RETURN DISTINCT labels(a)[0], type(r), labels(b)[0]
135145
relationships: list[dict[str, str]] = []
136146

137147
in_nodes = False

tests/integration/test_sdk.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def client():
2626
yield c
2727

2828

29-
3029
def uid() -> str:
3130
return uuid.uuid4().hex[:8]
3231

0 commit comments

Comments
 (0)