Skip to content

Commit 951b487

Browse files
committed
fix(langchain): guard empty query_vector via len() for Sequence compatibility
similarity_search() now uses len(query_vector) == 0 instead of truthiness to avoid ValueError on numpy.ndarray and other Sequence types.
1 parent c9246ac commit 951b487

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

langchain-coordinode/langchain_coordinode/graph.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ def similarity_search(
217217
Returns:
218218
List of result dicts sorted by ascending distance.
219219
"""
220-
if not query_vector:
220+
# Use len() instead of truthiness check: numpy.ndarray (and other Sequence
221+
# types) raise ValueError("The truth value of an array is ambiguous") when
222+
# used in a boolean context. len() == 0 works for all sequence types.
223+
if len(query_vector) == 0:
221224
return []
222225
results = sorted(
223226
self._client.vector_search(

tests/integration/adapters/test_langchain.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ def test_similarity_search_returns_results(graph, unique_tag):
152152
"CREATE (n:LCSim {id: $id, embedding: $vec}) RETURN n AS nid",
153153
params={"id": f"lcsim-{unique_tag}", "vec": vec},
154154
)
155+
# graph.query() wraps CoordinodeClient.cypher() which returns raw dict values.
156+
# CoordiNode: CREATE ... RETURN n yields the internal integer node ID directly
157+
# (NOT a node object). similarity_search() also returns {"id": r.node.id, ...}
158+
# where r.node.id is the same integer. Direct equality comparison is correct.
155159
seeded_internal_id = seed_rows[0]["nid"]
156160

157161
results = graph.similarity_search(vec, k=5, label="LCSim", property="embedding")

0 commit comments

Comments
 (0)