From 6a086e405b675c7868fbd1d9109f552cabcef0a3 Mon Sep 17 00:00:00 2001 From: Mayya Sharipova Date: Thu, 23 Oct 2025 12:25:18 -0400 Subject: [PATCH] Fix test failure ES92GpuHnswSQVectorsFormatTests. 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 --- .../vectors/DenseVectorFieldTypeTests.java | 4 ++-- .../plugin/gpu/GPUPluginInitializationIT.java | 18 +++++++++--------- .../codec/ES92GpuHnswSQVectorsFormatTests.java | 6 +++++- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldTypeTests.java b/server/src/test/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldTypeTests.java index 4a191fe0f5679..24db52cb10c0c 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldTypeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldTypeTests.java @@ -97,9 +97,9 @@ public static DenseVectorFieldMapper.DenseVectorIndexOptions randomGpuSupportedI } public static DenseVectorFieldMapper.VectorSimilarity randomGPUSupportedSimilarity( - DenseVectorFieldMapper.DenseVectorIndexOptions indexOptions + DenseVectorFieldMapper.VectorIndexType vectorIndexType ) { - if (indexOptions.getType() == DenseVectorFieldMapper.VectorIndexType.INT8_HNSW) { + if (vectorIndexType == DenseVectorFieldMapper.VectorIndexType.INT8_HNSW) { return randomFrom(VectorSimilarity.L2_NORM, VectorSimilarity.COSINE, VectorSimilarity.DOT_PRODUCT); } return randomFrom(VectorSimilarity.values()); diff --git a/x-pack/plugin/gpu/src/internalClusterTest/java/org/elasticsearch/plugin/gpu/GPUPluginInitializationIT.java b/x-pack/plugin/gpu/src/internalClusterTest/java/org/elasticsearch/plugin/gpu/GPUPluginInitializationIT.java index dd46a469dfbb0..29645f566a8e6 100644 --- a/x-pack/plugin/gpu/src/internalClusterTest/java/org/elasticsearch/plugin/gpu/GPUPluginInitializationIT.java +++ b/x-pack/plugin/gpu/src/internalClusterTest/java/org/elasticsearch/plugin/gpu/GPUPluginInitializationIT.java @@ -139,7 +139,7 @@ public void testFFOffGPUFormatNull() { var format = vectorsFormatProvider.getKnnVectorsFormat( settings, indexOptions, - DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions) + DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions.getType()) ); assertNull(format); } @@ -158,7 +158,7 @@ public void testIndexSettingOnIndexTypeSupportedGPUSupported() { var format = vectorsFormatProvider.getKnnVectorsFormat( settings, indexOptions, - DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions) + DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions.getType()) ); assertNotNull(format); } @@ -179,7 +179,7 @@ public void testIndexSettingOnIndexTypeNotSupportedThrows() { () -> vectorsFormatProvider.getKnnVectorsFormat( settings, indexOptions, - DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions) + DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions.getType()) ) ); assertThat(ex.getMessage(), startsWith("[index.vectors.indexing.use_gpu] doesn't support [index_options.type] of")); @@ -201,7 +201,7 @@ public void testIndexSettingOnGPUNotSupportedThrows() { () -> vectorsFormatProvider.getKnnVectorsFormat( settings, indexOptions, - DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions) + DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions.getType()) ) ); assertThat( @@ -227,7 +227,7 @@ public void testIndexSettingOnGPUSupportThrowsRethrows() { () -> vectorsFormatProvider.getKnnVectorsFormat( settings, indexOptions, - DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions) + DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions.getType()) ) ); assertThat( @@ -250,7 +250,7 @@ public void testIndexSettingAutoIndexTypeSupportedGPUSupported() { var format = vectorsFormatProvider.getKnnVectorsFormat( settings, indexOptions, - DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions) + DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions.getType()) ); assertNotNull(format); } @@ -269,7 +269,7 @@ public void testIndexSettingAutoGPUNotSupported() { var format = vectorsFormatProvider.getKnnVectorsFormat( settings, indexOptions, - DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions) + DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions.getType()) ); assertNull(format); } @@ -288,7 +288,7 @@ public void testIndexSettingAutoIndexTypeNotSupported() { var format = vectorsFormatProvider.getKnnVectorsFormat( settings, indexOptions, - DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions) + DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions.getType()) ); assertNull(format); } @@ -307,7 +307,7 @@ public void testIndexSettingOff() { var format = vectorsFormatProvider.getKnnVectorsFormat( settings, indexOptions, - DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions) + DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(indexOptions.getType()) ); assertNull(format); } diff --git a/x-pack/plugin/gpu/src/test/java/org/elasticsearch/xpack/gpu/codec/ES92GpuHnswSQVectorsFormatTests.java b/x-pack/plugin/gpu/src/test/java/org/elasticsearch/xpack/gpu/codec/ES92GpuHnswSQVectorsFormatTests.java index f1c13b15795c5..798cb726427ce 100644 --- a/x-pack/plugin/gpu/src/test/java/org/elasticsearch/xpack/gpu/codec/ES92GpuHnswSQVectorsFormatTests.java +++ b/x-pack/plugin/gpu/src/test/java/org/elasticsearch/xpack/gpu/codec/ES92GpuHnswSQVectorsFormatTests.java @@ -13,6 +13,9 @@ import org.apache.lucene.tests.util.LuceneTestCase; import org.apache.lucene.tests.util.TestUtil; import org.elasticsearch.common.logging.LogConfigurator; +import org.elasticsearch.index.IndexVersion; +import org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper; +import org.elasticsearch.index.mapper.vectors.DenseVectorFieldTypeTests; import org.elasticsearch.xpack.gpu.GPUSupport; import org.junit.BeforeClass; @@ -39,7 +42,8 @@ protected Codec getCodec() { @Override protected VectorSimilarityFunction randomSimilarity() { - return VectorSimilarityFunction.values()[random().nextInt(VectorSimilarityFunction.values().length)]; + return DenseVectorFieldTypeTests.randomGPUSupportedSimilarity(DenseVectorFieldMapper.VectorIndexType.INT8_HNSW) + .vectorSimilarityFunction(IndexVersion.current(), DenseVectorFieldMapper.ElementType.FLOAT); } @Override