Skip to content

Commit b4f887f

Browse files
committed
fix(langchain): catch gRPC errors in keyword_search, add missing methods to README
- keyword_search() now returns [] instead of raising when server returns UNIMPLEMENTED (older server versions without TextSearch endpoint) - Add regression test for the raising-client case - Add keyword_search, similarity_search, and structured_schema to API table in langchain-coordinode README
1 parent 984f1f3 commit b4f887f

3 files changed

Lines changed: 42 additions & 7 deletions

File tree

langchain-coordinode/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ graph = CoordinodeGraph("localhost:7080", timeout=60.0)
120120
| `query(query, params)` | Execute Cypher, returns `List[Dict[str, Any]]` |
121121
| `refresh_schema()` | Reload node/relationship schema from database |
122122
| `add_graph_documents(docs)` | Batch MERGE nodes + relationships from `GraphDocument` list |
123+
| `keyword_search(query, k, label, fuzzy, language)` | Full-text BM25 search — returns `[{"id", "score", "snippet"}, …]` |
124+
| `similarity_search(query_vector, k, label, property)` | Vector nearest-neighbour search — returns `[{"id", "node", "distance"}, …]` |
123125
| `schema` | Schema string for LLM context |
126+
| `structured_schema` | Structured schema dict for programmatic access |
124127

125128
## Related Packages
126129

langchain-coordinode/langchain_coordinode/graph.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,22 @@ def keyword_search(
307307
# Injected clients (e.g. bare coordinode-embedded LocalClient) may
308308
# not implement text_search — return empty rather than AttributeError.
309309
return []
310-
results = self._client.text_search(
311-
label,
312-
query,
313-
limit=k,
314-
fuzzy=fuzzy,
315-
language=language,
316-
)
310+
try:
311+
results = self._client.text_search(
312+
label,
313+
query,
314+
limit=k,
315+
fuzzy=fuzzy,
316+
language=language,
317+
)
318+
except Exception:
319+
# Server may return UNIMPLEMENTED (feature not yet available in the
320+
# deployed version) or NOT_FOUND (no text index for *label*).
321+
# We catch broad Exception (rather than grpc.RpcError specifically)
322+
# because langchain-coordinode does not take a hard grpc dependency.
323+
# The exception is logged at DEBUG so it remains observable.
324+
logger.debug("text_search() failed — returning empty list", exc_info=True)
325+
return []
317326
# Use "id" (not "node_id") for consistency with similarity_search() return
318327
# format, so callers can write generic code over both methods.
319328
return [{"id": r.node_id, "score": r.score, "snippet": r.snippet} for r in results]

tests/unit/test_langchain_graph.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ def close(self) -> None:
6565
return None
6666

6767

68+
class _ClientWithRaisingTextSearch:
69+
"""Fake client whose text_search raises (e.g. gRPC UNIMPLEMENTED)."""
70+
71+
def cypher(self, query: str, params: dict | None = None) -> list[dict]:
72+
return []
73+
74+
def text_search(self, label: str, query: str, **kwargs: Any) -> list[Any]:
75+
raise RuntimeError("StatusCode.UNIMPLEMENTED")
76+
77+
def close(self) -> None:
78+
# No-op: keeps interface parity with real CoordinodeClient.
79+
return None
80+
81+
6882
# ── Tests: keyword_search ─────────────────────────────────────────────────────
6983

7084

@@ -150,3 +164,12 @@ def test_empty_snippet_preserved(self) -> None:
150164
out = graph.keyword_search("test")
151165

152166
assert out[0]["snippet"] == ""
167+
168+
def test_returns_empty_when_text_search_raises(self) -> None:
169+
"""Returns [] when text_search raises (e.g. gRPC UNIMPLEMENTED from older server)."""
170+
client = _ClientWithRaisingTextSearch()
171+
graph = CoordinodeGraph(client=client)
172+
173+
out = graph.keyword_search("query")
174+
175+
assert out == []

0 commit comments

Comments
 (0)