Skip to content

Commit 4ee3718

Browse files
mayya-sharipovafzowl
authored andcommitted
Fix test failure ES92GpuHnswSQVectorsFormatTests. (elastic#137051)
ES92GpuHnswSQVectorsFormatTests fails because it may choose not supported vector similarity function max_inner_product This fixes this test to ensure only supported similarity metrics are picked for tests. This change is already a part of 9.2.1 branch, so no backported is needed Related to elastic#136881
1 parent c09b318 commit 4ee3718

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

server/src/test/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldTypeTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ public static DenseVectorFieldMapper.DenseVectorIndexOptions randomGpuSupportedI
9797
}
9898

9999
public static DenseVectorFieldMapper.VectorSimilarity randomGPUSupportedSimilarity(
100-
DenseVectorFieldMapper.DenseVectorIndexOptions indexOptions
100+
DenseVectorFieldMapper.VectorIndexType vectorIndexType
101101
) {
102-
if (indexOptions.getType() == DenseVectorFieldMapper.VectorIndexType.INT8_HNSW) {
102+
if (vectorIndexType == DenseVectorFieldMapper.VectorIndexType.INT8_HNSW) {
103103
return randomFrom(VectorSimilarity.L2_NORM, VectorSimilarity.COSINE, VectorSimilarity.DOT_PRODUCT);
104104
}
105105
return randomFrom(VectorSimilarity.values());

x-pack/plugin/gpu/src/internalClusterTest/java/org/elasticsearch/plugin/gpu/GPUPluginInitializationIT.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void testFFOffGPUFormatNull() {
139139
var format = vectorsFormatProvider.getKnnVectorsFormat(
140140
settings,
141141
indexOptions,
142-
DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions)
142+
DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions.getType())
143143
);
144144
assertNull(format);
145145
}
@@ -158,7 +158,7 @@ public void testIndexSettingOnIndexTypeSupportedGPUSupported() {
158158
var format = vectorsFormatProvider.getKnnVectorsFormat(
159159
settings,
160160
indexOptions,
161-
DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions)
161+
DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions.getType())
162162
);
163163
assertNotNull(format);
164164
}
@@ -179,7 +179,7 @@ public void testIndexSettingOnIndexTypeNotSupportedThrows() {
179179
() -> vectorsFormatProvider.getKnnVectorsFormat(
180180
settings,
181181
indexOptions,
182-
DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions)
182+
DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions.getType())
183183
)
184184
);
185185
assertThat(ex.getMessage(), startsWith("[index.vectors.indexing.use_gpu] doesn't support [index_options.type] of"));
@@ -201,7 +201,7 @@ public void testIndexSettingOnGPUNotSupportedThrows() {
201201
() -> vectorsFormatProvider.getKnnVectorsFormat(
202202
settings,
203203
indexOptions,
204-
DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions)
204+
DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions.getType())
205205
)
206206
);
207207
assertThat(
@@ -227,7 +227,7 @@ public void testIndexSettingOnGPUSupportThrowsRethrows() {
227227
() -> vectorsFormatProvider.getKnnVectorsFormat(
228228
settings,
229229
indexOptions,
230-
DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions)
230+
DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions.getType())
231231
)
232232
);
233233
assertThat(
@@ -250,7 +250,7 @@ public void testIndexSettingAutoIndexTypeSupportedGPUSupported() {
250250
var format = vectorsFormatProvider.getKnnVectorsFormat(
251251
settings,
252252
indexOptions,
253-
DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions)
253+
DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions.getType())
254254
);
255255
assertNotNull(format);
256256
}
@@ -269,7 +269,7 @@ public void testIndexSettingAutoGPUNotSupported() {
269269
var format = vectorsFormatProvider.getKnnVectorsFormat(
270270
settings,
271271
indexOptions,
272-
DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions)
272+
DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions.getType())
273273
);
274274
assertNull(format);
275275
}
@@ -288,7 +288,7 @@ public void testIndexSettingAutoIndexTypeNotSupported() {
288288
var format = vectorsFormatProvider.getKnnVectorsFormat(
289289
settings,
290290
indexOptions,
291-
DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions)
291+
DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions.getType())
292292
);
293293
assertNull(format);
294294
}
@@ -307,7 +307,7 @@ public void testIndexSettingOff() {
307307
var format = vectorsFormatProvider.getKnnVectorsFormat(
308308
settings,
309309
indexOptions,
310-
DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions)
310+
DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions.getType())
311311
);
312312
assertNull(format);
313313
}

x-pack/plugin/gpu/src/test/java/org/elasticsearch/xpack/gpu/codec/ES92GpuHnswSQVectorsFormatTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
import org.apache.lucene.tests.util.LuceneTestCase;
1414
import org.apache.lucene.tests.util.TestUtil;
1515
import org.elasticsearch.common.logging.LogConfigurator;
16+
import org.elasticsearch.index.IndexVersion;
17+
import org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper;
18+
import org.elasticsearch.index.mapper.vectors.DenseVectorFieldTypeTests;
1619
import org.elasticsearch.xpack.gpu.GPUSupport;
1720
import org.junit.BeforeClass;
1821

@@ -39,7 +42,8 @@ protected Codec getCodec() {
3942

4043
@Override
4144
protected VectorSimilarityFunction randomSimilarity() {
42-
return VectorSimilarityFunction.values()[random().nextInt(VectorSimilarityFunction.values().length)];
45+
return DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(DenseVectorFieldMapper.VectorIndexType.INT8_HNSW)
46+
.vectorSimilarityFunction(IndexVersion.current(), DenseVectorFieldMapper.ElementType.FLOAT);
4347
}
4448

4549
@Override

0 commit comments

Comments
 (0)