@@ -779,7 +779,7 @@ public void testSuccessfulParse() throws IOException {
779779 Model model1 = TestModel .createRandomInstance (taskType );
780780 Model model2 = TestModel .createRandomInstance (taskType );
781781 ChunkingSettings chunkingSettings = null ; // Some chunking settings configs can produce different Lucene docs counts
782- SemanticTextIndexOptions indexOptions = randomSemanticTextIndexOptions (taskType );
782+ SemanticTextIndexOptions indexOptions = randomSemanticTextIndexOptions (taskType , IndexVersion . current () );
783783 XContentBuilder mapping = mapping (b -> {
784784 addSemanticTextMapping (
785785 b ,
@@ -1054,7 +1054,7 @@ public void testModelSettingsRequiredWithChunks() throws IOException {
10541054 TaskType taskType = TaskType .SPARSE_EMBEDDING ;
10551055 Model model = TestModel .createRandomInstance (taskType );
10561056 ChunkingSettings chunkingSettings = generateRandomChunkingSettings (false );
1057- SemanticTextIndexOptions indexOptions = randomSemanticTextIndexOptions (taskType );
1057+ SemanticTextIndexOptions indexOptions = randomSemanticTextIndexOptions (taskType , IndexVersion . current () );
10581058 SemanticTextField randomSemanticText = randomSemanticText (
10591059 useLegacyFormat ,
10601060 "field" ,
@@ -1185,8 +1185,12 @@ private static DenseVectorFieldMapper.DenseVectorIndexOptions defaultDenseVector
11851185 return new DenseVectorFieldMapper .Int8HnswIndexOptions (m , efConstruction , null , null );
11861186 }
11871187
1188- private static SemanticTextIndexOptions defaultDenseVectorSemanticIndexOptions () {
1189- return new SemanticTextIndexOptions (SemanticTextIndexOptions .SupportedIndexOptions .DENSE_VECTOR , defaultDenseVectorIndexOptions ());
1188+ private static SemanticTextIndexOptions defaultDenseVectorSemanticIndexOptions (IndexVersion indexVersion ) {
1189+ return new SemanticTextIndexOptions (
1190+ SemanticTextIndexOptions .SupportedIndexOptions .DENSE_VECTOR ,
1191+ defaultDenseVectorIndexOptions (),
1192+ indexVersion
1193+ );
11901194 }
11911195
11921196 private static DenseVectorFieldMapper .DenseVectorIndexOptions defaultBbqHnswDenseVectorIndexOptions () {
@@ -1196,16 +1200,22 @@ private static DenseVectorFieldMapper.DenseVectorIndexOptions defaultBbqHnswDens
11961200 return new DenseVectorFieldMapper .BBQHnswIndexOptions (m , efConstruction , rescoreVector );
11971201 }
11981202
1199- private static SemanticTextIndexOptions defaultBbqHnswSemanticTextIndexOptions () {
1203+ private static SemanticTextIndexOptions defaultBbqHnswSemanticTextIndexOptions (IndexVersion indexVersion ) {
12001204 return new SemanticTextIndexOptions (
12011205 SemanticTextIndexOptions .SupportedIndexOptions .DENSE_VECTOR ,
1202- defaultBbqHnswDenseVectorIndexOptions ()
1206+ defaultBbqHnswDenseVectorIndexOptions (),
1207+ indexVersion
12031208 );
12041209 }
12051210
12061211 public void testDefaultIndexOptions () throws IOException {
12071212
12081213 // We default to BBQ for eligible dense vectors
1214+ var indexVersion = IndexVersionUtils .randomVersionBetween (
1215+ random (),
1216+ IndexVersions .SEMANTIC_TEXT_DEFAULTS_TO_BBQ ,
1217+ IndexVersion .current ()
1218+ );
12091219 var mapperService = createMapperService (fieldMapping (b -> {
12101220 b .field ("type" , "semantic_text" );
12111221 b .field ("inference_id" , "another_inference_id" );
@@ -1215,8 +1225,8 @@ public void testDefaultIndexOptions() throws IOException {
12151225 b .field ("similarity" , "cosine" );
12161226 b .field ("element_type" , "float" );
12171227 b .endObject ();
1218- }), useLegacyFormat , IndexVersions . SEMANTIC_TEXT_DEFAULTS_TO_BBQ );
1219- assertSemanticTextField (mapperService , "field" , true , null , defaultBbqHnswSemanticTextIndexOptions ());
1228+ }), useLegacyFormat , indexVersion , indexVersion );
1229+ assertSemanticTextField (mapperService , "field" , true , null , defaultBbqHnswSemanticTextIndexOptions (indexVersion ));
12201230
12211231 // Element types that are incompatible with BBQ will continue to use dense_vector defaults
12221232 mapperService = createMapperService (fieldMapping (b -> {
@@ -1228,7 +1238,7 @@ public void testDefaultIndexOptions() throws IOException {
12281238 b .field ("similarity" , "cosine" );
12291239 b .field ("element_type" , "byte" );
12301240 b .endObject ();
1231- }), useLegacyFormat , IndexVersions . SEMANTIC_TEXT_DEFAULTS_TO_BBQ );
1241+ }), useLegacyFormat , indexVersion , indexVersion );
12321242 assertSemanticTextField (mapperService , "field" , true , null , null );
12331243
12341244 // A dim count of 10 is too small to support BBQ, so we continue to use dense_vector defaults
@@ -1241,13 +1251,17 @@ public void testDefaultIndexOptions() throws IOException {
12411251 b .field ("similarity" , "cosine" );
12421252 b .field ("element_type" , "float" );
12431253 b .endObject ();
1244- }), useLegacyFormat , IndexVersions . SEMANTIC_TEXT_DEFAULTS_TO_BBQ );
1254+ }), useLegacyFormat , indexVersion , indexVersion );
12451255 assertSemanticTextField (
12461256 mapperService ,
12471257 "field" ,
12481258 true ,
12491259 null ,
1250- new SemanticTextIndexOptions (SemanticTextIndexOptions .SupportedIndexOptions .DENSE_VECTOR , defaultDenseVectorIndexOptions ())
1260+ new SemanticTextIndexOptions (
1261+ SemanticTextIndexOptions .SupportedIndexOptions .DENSE_VECTOR ,
1262+ defaultDenseVectorIndexOptions (),
1263+ indexVersion
1264+ )
12511265 );
12521266
12531267 // If we explicitly set index options, we respect those over the defaults
@@ -1267,19 +1281,25 @@ public void testDefaultIndexOptions() throws IOException {
12671281 b .field ("ef_construction" , 100 );
12681282 b .endObject ();
12691283 b .endObject ();
1270- }), useLegacyFormat , IndexVersions . SEMANTIC_TEXT_DEFAULTS_TO_BBQ );
1284+ }), useLegacyFormat , indexVersion , indexVersion );
12711285 assertSemanticTextField (
12721286 mapperService ,
12731287 "field" ,
12741288 true ,
12751289 null ,
12761290 new SemanticTextIndexOptions (
12771291 SemanticTextIndexOptions .SupportedIndexOptions .DENSE_VECTOR ,
1278- new DenseVectorFieldMapper .Int4HnswIndexOptions (25 , 100 , null , null )
1292+ new DenseVectorFieldMapper .Int4HnswIndexOptions (25 , 100 , null , null ),
1293+ indexVersion
12791294 )
12801295 );
12811296
12821297 // Previous index versions do not set BBQ index options
1298+ indexVersion = IndexVersionUtils .randomVersionBetween (
1299+ random (),
1300+ IndexVersions .INFERENCE_METADATA_FIELDS ,
1301+ IndexVersionUtils .getPreviousVersion (IndexVersions .SEMANTIC_TEXT_DEFAULTS_TO_BBQ )
1302+ );
12831303 mapperService = createMapperService (fieldMapping (b -> {
12841304 b .field ("type" , "semantic_text" );
12851305 b .field ("inference_id" , "another_inference_id" );
@@ -1289,14 +1309,15 @@ public void testDefaultIndexOptions() throws IOException {
12891309 b .field ("similarity" , "cosine" );
12901310 b .field ("element_type" , "float" );
12911311 b .endObject ();
1292- }),
1293- useLegacyFormat ,
1294- IndexVersions .INFERENCE_METADATA_FIELDS ,
1295- IndexVersionUtils .getPreviousVersion (IndexVersions .SEMANTIC_TEXT_DEFAULTS_TO_BBQ )
1296- );
1297- assertSemanticTextField (mapperService , "field" , true , null , defaultDenseVectorSemanticIndexOptions ());
1312+ }), useLegacyFormat , indexVersion , indexVersion );
1313+ assertSemanticTextField (mapperService , "field" , true , null , defaultDenseVectorSemanticIndexOptions (indexVersion ));
12981314
12991315 // 8.x index versions that use backported default BBQ set default BBQ index options as expected
1316+ indexVersion = IndexVersionUtils .randomVersionBetween (
1317+ random (),
1318+ IndexVersions .SEMANTIC_TEXT_DEFAULTS_TO_BBQ_BACKPORT_8_X ,
1319+ IndexVersions .UPGRADE_TO_LUCENE_10_0_0
1320+ );
13001321 mapperService = createMapperService (fieldMapping (b -> {
13011322 b .field ("type" , "semantic_text" );
13021323 b .field ("inference_id" , "another_inference_id" );
@@ -1306,10 +1327,15 @@ public void testDefaultIndexOptions() throws IOException {
13061327 b .field ("similarity" , "cosine" );
13071328 b .field ("element_type" , "float" );
13081329 b .endObject ();
1309- }), useLegacyFormat , IndexVersions . SEMANTIC_TEXT_DEFAULTS_TO_BBQ_BACKPORT_8_X , IndexVersions . UPGRADE_TO_LUCENE_10_0_0 );
1310- assertSemanticTextField (mapperService , "field" , true , null , defaultBbqHnswSemanticTextIndexOptions ());
1330+ }), useLegacyFormat , indexVersion , indexVersion );
1331+ assertSemanticTextField (mapperService , "field" , true , null , defaultBbqHnswSemanticTextIndexOptions (indexVersion ));
13111332
13121333 // Previous 8.x index versions do not set BBQ index options
1334+ indexVersion = IndexVersionUtils .randomVersionBetween (
1335+ random (),
1336+ IndexVersions .INFERENCE_METADATA_FIELDS_BACKPORT ,
1337+ IndexVersions .SEMANTIC_TEXT_DEFAULTS_TO_BBQ_BACKPORT_8_X
1338+ );
13131339 mapperService = createMapperService (fieldMapping (b -> {
13141340 b .field ("type" , "semantic_text" );
13151341 b .field ("inference_id" , "another_inference_id" );
@@ -1319,17 +1345,18 @@ public void testDefaultIndexOptions() throws IOException {
13191345 b .field ("similarity" , "cosine" );
13201346 b .field ("element_type" , "float" );
13211347 b .endObject ();
1322- }),
1323- useLegacyFormat ,
1324- IndexVersions .INFERENCE_METADATA_FIELDS_BACKPORT ,
1325- IndexVersionUtils .getPreviousVersion (IndexVersions .SEMANTIC_TEXT_DEFAULTS_TO_BBQ_BACKPORT_8_X )
1326- );
1327- assertSemanticTextField (mapperService , "field" , true , null , defaultDenseVectorSemanticIndexOptions ());
1348+ }), useLegacyFormat , indexVersion , indexVersion );
1349+ assertSemanticTextField (mapperService , "field" , true , null , defaultDenseVectorSemanticIndexOptions (indexVersion ));
13281350 }
13291351
13301352 public void testSpecifiedDenseVectorIndexOptions () throws IOException {
13311353
13321354 // Specifying index options will override default index option settings
1355+ var indexVersion = IndexVersionUtils .randomVersionBetween (
1356+ random (),
1357+ IndexVersions .INFERENCE_METADATA_FIELDS_BACKPORT ,
1358+ IndexVersion .current ()
1359+ );
13331360 var mapperService = createMapperService (fieldMapping (b -> {
13341361 b .field ("type" , "semantic_text" );
13351362 b .field ("inference_id" , "another_inference_id" );
@@ -1347,15 +1374,16 @@ public void testSpecifiedDenseVectorIndexOptions() throws IOException {
13471374 b .field ("confidence_interval" , 0.4 );
13481375 b .endObject ();
13491376 b .endObject ();
1350- }), useLegacyFormat , IndexVersions . INFERENCE_METADATA_FIELDS_BACKPORT );
1377+ }), useLegacyFormat , indexVersion , indexVersion );
13511378 assertSemanticTextField (
13521379 mapperService ,
13531380 "field" ,
13541381 true ,
13551382 null ,
13561383 new SemanticTextIndexOptions (
13571384 SemanticTextIndexOptions .SupportedIndexOptions .DENSE_VECTOR ,
1358- new DenseVectorFieldMapper .Int4HnswIndexOptions (20 , 90 , 0.4f , null )
1385+ new DenseVectorFieldMapper .Int4HnswIndexOptions (20 , 90 , 0.4f , null ),
1386+ indexVersion
13591387 )
13601388 );
13611389
@@ -1374,15 +1402,16 @@ public void testSpecifiedDenseVectorIndexOptions() throws IOException {
13741402 b .field ("type" , "int4_hnsw" );
13751403 b .endObject ();
13761404 b .endObject ();
1377- }), useLegacyFormat , IndexVersions . INFERENCE_METADATA_FIELDS_BACKPORT );
1405+ }), useLegacyFormat , indexVersion , indexVersion );
13781406 assertSemanticTextField (
13791407 mapperService ,
13801408 "field" ,
13811409 true ,
13821410 null ,
13831411 new SemanticTextIndexOptions (
13841412 SemanticTextIndexOptions .SupportedIndexOptions .DENSE_VECTOR ,
1385- new DenseVectorFieldMapper .Int4HnswIndexOptions (16 , 100 , 0f , null )
1413+ new DenseVectorFieldMapper .Int4HnswIndexOptions (16 , 100 , 0f , null ),
1414+ indexVersion
13861415 )
13871416 );
13881417
@@ -1440,15 +1469,19 @@ public void testSpecifiedDenseVectorIndexOptions() throws IOException {
14401469
14411470 public static SemanticTextIndexOptions randomSemanticTextIndexOptions () {
14421471 TaskType taskType = randomFrom (TaskType .SPARSE_EMBEDDING , TaskType .TEXT_EMBEDDING );
1443- return randomSemanticTextIndexOptions (taskType );
1472+ return randomSemanticTextIndexOptions (taskType , IndexVersion . current () );
14441473 }
14451474
1446- public static SemanticTextIndexOptions randomSemanticTextIndexOptions (TaskType taskType ) {
1475+ public static SemanticTextIndexOptions randomSemanticTextIndexOptions (TaskType taskType , IndexVersion indexVersion ) {
14471476
14481477 if (taskType == TaskType .TEXT_EMBEDDING ) {
14491478 return randomBoolean ()
14501479 ? null
1451- : new SemanticTextIndexOptions (SemanticTextIndexOptions .SupportedIndexOptions .DENSE_VECTOR , randomIndexOptionsAll ());
1480+ : new SemanticTextIndexOptions (
1481+ SemanticTextIndexOptions .SupportedIndexOptions .DENSE_VECTOR ,
1482+ randomIndexOptionsAll (),
1483+ indexVersion
1484+ );
14521485 }
14531486
14541487 return null ;
0 commit comments