|
12 | 12 |
|
13 | 13 | import pytest |
14 | 14 | from llama_index.core.graph_stores.types import EntityNode, Relation |
| 15 | +from llama_index.core.vector_stores.types import VectorStoreQuery |
15 | 16 | from llama_index.graph_stores.coordinode import CoordinodePropertyGraphStore |
16 | 17 |
|
17 | 18 | ADDR = os.environ.get("COORDINODE_ADDR", "localhost:7080") |
@@ -150,3 +151,40 @@ def test_delete_by_entity_name(store, tag): |
150 | 151 |
|
151 | 152 | found = store.get(properties={"name": f"DelNamed-{tag}"}) |
152 | 153 | 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