2929import java .util .Locale ;
3030import java .util .Map ;
3131import java .util .Set ;
32- import java .util .function .Function ;
33- import java .util .function .Supplier ;
3432
3533import static org .elasticsearch .index .IndexSettings .INDEX_MAPPER_SOURCE_MODE_SETTING ;
3634import static org .elasticsearch .index .mapper .SourceFieldMapper .Mode .SYNTHETIC ;
@@ -54,40 +52,39 @@ public class DenseVectorFieldTypeIT extends AbstractEsqlIntegTestCase {
5452 private final ElementType elementType ;
5553 private final DenseVectorFieldMapper .VectorSimilarity similarity ;
5654 private final boolean synthetic ;
57- private final String indexType ;
5855 private final boolean index ;
5956
6057 @ ParametersFactory
6158 public static Iterable <Object []> parameters () throws Exception {
6259 List <Object []> params = new ArrayList <>();
63- // Indexed field types
64- Supplier <ElementType > elementTypeProvider = () -> randomFrom (ElementType .FLOAT , ElementType .BYTE );
65- Function <ElementType , String > indexTypeProvider = e -> e == ElementType .FLOAT
66- ? randomFrom (ALL_DENSE_VECTOR_INDEX_TYPES )
67- : randomFrom (NON_QUANTIZED_DENSE_VECTOR_INDEX_TYPES );
68- Supplier <DenseVectorFieldMapper .VectorSimilarity > vectorSimilarityProvider = () -> randomFrom (
60+ List <DenseVectorFieldMapper .VectorSimilarity > similarities = List .of (
6961 DenseVectorFieldMapper .VectorSimilarity .DOT_PRODUCT ,
7062 DenseVectorFieldMapper .VectorSimilarity .L2_NORM ,
7163 DenseVectorFieldMapper .VectorSimilarity .MAX_INNER_PRODUCT
7264 );
73- params .add (new Object [] { elementTypeProvider , indexTypeProvider , vectorSimilarityProvider , true , false });
74- // No indexing
75- params .add (new Object [] { elementTypeProvider , null , null , false , false });
76- // No indexing, synthetic source
77- params .add (new Object [] { elementTypeProvider , null , null , false , true });
65+
66+ for (ElementType elementType : List .of (ElementType .BYTE , ElementType .FLOAT )) {
67+ // Test all similarities for element types
68+ for (DenseVectorFieldMapper .VectorSimilarity similarity : similarities ) {
69+ params .add (new Object [] { elementType , similarity , true , false });
70+ }
71+
72+ // No indexing
73+ params .add (new Object [] { elementType , null , false , false });
74+ // No indexing, synthetic source
75+ params .add (new Object [] { elementType , null , false , true });
76+ }
7877 return params ;
7978 }
8079
8180 public DenseVectorFieldTypeIT (
82- @ Name ("elementType" ) Supplier <ElementType > elementTypeProvider ,
83- @ Name ("indexType" ) Function <ElementType , String > indexTypeProvider ,
84- @ Name ("similarity" ) Supplier <DenseVectorFieldMapper .VectorSimilarity > similarityProvider ,
81+ @ Name ("elementType" ) ElementType elementType ,
82+ @ Name ("similarity" ) DenseVectorFieldMapper .VectorSimilarity similarity ,
8583 @ Name ("index" ) boolean index ,
8684 @ Name ("synthetic" ) boolean synthetic
8785 ) {
88- this .elementType = elementTypeProvider .get ();
89- this .indexType = indexTypeProvider == null ? null : indexTypeProvider .apply (this .elementType );
90- this .similarity = similarityProvider == null ? null : similarityProvider .get ();
86+ this .elementType = elementType ;
87+ this .similarity = similarity == null ? null : similarity ;
9188 this .index = index ;
9289 this .synthetic = synthetic ;
9390 }
@@ -244,8 +241,9 @@ private void createIndexWithDenseVector(String indexName) throws IOException {
244241 .field ("index" , index );
245242 if (index ) {
246243 mapping .field ("similarity" , similarity .name ().toLowerCase (Locale .ROOT ));
247- }
248- if (indexType != null ) {
244+ String indexType = elementType == ElementType .FLOAT
245+ ? randomFrom (ALL_DENSE_VECTOR_INDEX_TYPES )
246+ : randomFrom (NON_QUANTIZED_DENSE_VECTOR_INDEX_TYPES );
249247 mapping .startObject ("index_options" ).field ("type" , indexType ).endObject ();
250248 }
251249 mapping .endObject ().endObject ().endObject ();
0 commit comments