Skip to content

Commit 69fa991

Browse files
committed
test(llama-index): add vector_query() integration tests
1 parent ab1ea64 commit 69fa991

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

tests/integration/adapters/test_llama_index.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import pytest
1414
from llama_index.core.graph_stores.types import EntityNode, Relation
15+
from llama_index.core.vector_stores.types import VectorStoreQuery
1516
from llama_index.graph_stores.coordinode import CoordinodePropertyGraphStore
1617

1718
ADDR = os.environ.get("COORDINODE_ADDR", "localhost:7080")
@@ -150,3 +151,40 @@ def test_delete_by_entity_name(store, tag):
150151

151152
found = store.get(properties={"name": f"DelNamed-{tag}"})
152153
assert len(found) == 0
154+
155+
156+
# ── Vector query ──────────────────────────────────────────────────────────────
157+
158+
159+
def test_vector_query_returns_results(store, tag):
160+
"""vector_query() returns nodes and scores for an embedding that matches stored data.
161+
162+
vector_query() without filters defaults to label="Chunk", so the seed node must use
163+
that label to be found by the underlying vector_search() call.
164+
"""
165+
vec = [float(i) / 16 for i in range(16)]
166+
# Seed a Chunk node with an embedding directly via Cypher.
167+
# vector_query() defaults label to "Chunk" when no MetadataFilters are provided.
168+
store._client.cypher(
169+
"CREATE (n:Chunk {id: $id, text: $text, embedding: $vec})",
170+
params={"id": f"vec-{tag}", "text": "test chunk", "vec": vec},
171+
)
172+
try:
173+
query = VectorStoreQuery(query_embedding=vec, similarity_top_k=1)
174+
nodes, scores = store.vector_query(query)
175+
176+
assert isinstance(nodes, list)
177+
assert isinstance(scores, list)
178+
assert len(nodes) >= 1
179+
assert len(scores) == len(nodes)
180+
assert scores[0] >= 0.0
181+
finally:
182+
store._client.cypher("MATCH (n:Chunk {id: $id}) DELETE n", params={"id": f"vec-{tag}"})
183+
184+
185+
def test_vector_query_empty_embedding_returns_empty(store):
186+
"""vector_query() with no query_embedding returns empty lists without error."""
187+
query = VectorStoreQuery(query_embedding=None, similarity_top_k=5)
188+
nodes, scores = store.vector_query(query)
189+
assert nodes == []
190+
assert scores == []

0 commit comments

Comments
 (0)