Skip to content

Commit ab3559e

Browse files
committed
fix(langchain): align similarity_search() signature with Sequence protocol and issue spec
- Change query_vector type annotation from list[float] to Sequence[float] (matches existing code comment that explicitly documents numpy.ndarray support and aligns with CoordinodeClient.vector_search() signature) - Change default k from 10 to 5 (matches issue #20 acceptance criteria) - Strengthen test_similarity_search_returns_results: replace non-negativity check with full ascending-order assertion on adjacent distances - Use store.structured_query(param_map=...) in test_upsert_relations_idempotent instead of store._client.cypher() — keeps integration test stable vs internal API
1 parent 951b487 commit ab3559e

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

langchain-coordinode/langchain_coordinode/graph.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import hashlib
66
import json
77
import re
8+
from collections.abc import Sequence
89
from typing import Any
910

1011
from langchain_community.graphs.graph_store import GraphStore
@@ -196,8 +197,8 @@ def query(
196197

197198
def similarity_search(
198199
self,
199-
query_vector: list[float],
200-
k: int = 10,
200+
query_vector: Sequence[float],
201+
k: int = 5,
201202
label: str = "Chunk",
202203
property: str = "embedding",
203204
) -> list[dict[str, Any]]:

tests/integration/adapters/test_langchain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def test_similarity_search_returns_results(graph, unique_tag):
164164
assert len(results) >= 1
165165
assert all("id" in r and "node" in r and "distance" in r for r in results)
166166
assert any(r["id"] == seeded_internal_id for r in results)
167-
assert results[0]["distance"] >= 0.0
167+
assert all(results[i]["distance"] <= results[i + 1]["distance"] for i in range(len(results) - 1))
168168
finally:
169169
graph.query("MATCH (n:LCSim {id: $id}) DELETE n", params={"id": f"lcsim-{unique_tag}"})
170170

tests/integration/adapters/test_llama_index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ def test_upsert_relations_idempotent(store, tag):
8282
store.upsert_relations([rel])
8383
store.upsert_relations([rel]) # second call must not duplicate
8484

85-
rows = store._client.cypher(
85+
rows = store.structured_query(
8686
"MATCH (a {id: $src})-[r:LI_IDEMP_REL]->(b {id: $dst}) RETURN count(r) AS cnt",
87-
params={"src": src.id, "dst": dst.id},
87+
param_map={"src": src.id, "dst": dst.id},
8888
)
8989
assert rows[0]["cnt"] == 1, f"expected exactly 1 edge after double upsert, got: {rows}"
9090

0 commit comments

Comments
 (0)