Skip to content

Commit 720ad1e

Browse files
committed
Fix vectorstore tests
There were three different problems: * Elasticsearch automatically applied certain index_options that were missing * Two tests were using FakeEmbeddings instead of ConsistentFakeEmbeddings * One test used [1, ..., 1, i] with i going from 0 to 2. Making it going from 1 to 3 allowed the cosine similarity to work as expected.
1 parent 8e2b2c2 commit 720ad1e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

test_elasticsearch/test_server/test_vectorstore/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def embed_documents(self, texts: List[str]) -> List[List[float]]:
6969
if text not in self.known_texts:
7070
self.known_texts.append(text)
7171
vector = [float(1.0)] * (self.dimensionality - 1) + [
72-
float(self.known_texts.index(text))
72+
float(self.known_texts.index(text) + 1)
7373
]
7474
out_vectors.append(vector)
7575
return out_vectors

test_elasticsearch/test_server/test_vectorstore/test_vectorstore.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ def assert_query(query_body: dict, query: Optional[str]) -> dict:
7373
"filter": [],
7474
"k": 1,
7575
"num_candidates": 50,
76-
"query_vector": [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0],
76+
"query_vector": [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0],
7777
}
7878
}
7979
return query_body
8080

8181
store = VectorStore(
8282
index=index,
8383
retrieval_strategy=DenseVectorStrategy(),
84-
embedding_service=FakeEmbeddings(),
84+
embedding_service=ConsistentFakeEmbeddings(),
8585
client=sync_client,
8686
)
8787

@@ -98,7 +98,7 @@ def test_search_without_metadata_async(
9898
store = VectorStore(
9999
index=index,
100100
retrieval_strategy=DenseVectorStrategy(),
101-
embedding_service=FakeEmbeddings(),
101+
embedding_service=ConsistentFakeEmbeddings(),
102102
client=sync_client,
103103
)
104104

@@ -1030,6 +1030,11 @@ def test_metadata_mapping(self, sync_client: Elasticsearch, index: str) -> None:
10301030
"type": "dense_vector",
10311031
"dims": 10,
10321032
"index": True,
1033+
"index_options": {
1034+
"ef_construction": 100,
1035+
"m": 16,
1036+
"type": "int8_hnsw",
1037+
},
10331038
"similarity": "cosine",
10341039
}
10351040

0 commit comments

Comments
 (0)