@@ -415,57 +415,6 @@ public void testInvalidTaskTypes() {
415
415
}
416
416
}
417
417
418
- @ Override
419
- protected IndexVersion boostNotAllowedIndexVersion () {
420
- return IndexVersions .NEW_SPARSE_VECTOR ;
421
- }
422
-
423
- public void testOldIndexSemanticTextDenseVectorRaisesError () throws IOException {
424
- final String fieldName = "field" ;
425
- final XContentBuilder fieldMapping = fieldMapping (b -> {
426
- b .field ("type" , "semantic_text" );
427
- b .field (INFERENCE_ID_FIELD , "test_inference_id" );
428
- b .startObject ("model_settings" );
429
- b .field ("task_type" , "text_embedding" );
430
- b .field ("dimensions" , 384 );
431
- b .field ("similarity" , "cosine" );
432
- b .field ("element_type" , "float" );
433
- b .endObject ();
434
- });
435
- assertOldIndexUnsupported (fieldMapping );
436
- }
437
-
438
- public void testOldIndexSemanticTextMinimalMappingRaisesError () throws IOException {
439
- final XContentBuilder fieldMapping = fieldMapping (this ::minimalMapping );
440
- assertOldIndexUnsupported (fieldMapping );
441
- }
442
-
443
- public void testOldIndexSemanticTextSparseVersionRaisesError () throws IOException {
444
- final XContentBuilder fieldMapping = fieldMapping (b -> {
445
- b .field ("type" , "semantic_text" );
446
- b .field ("inference_id" , "another_inference_id" );
447
- b .startObject ("model_settings" );
448
- b .field ("task_type" , "sparse_embedding" );
449
- b .endObject ();
450
- });
451
- assertOldIndexUnsupported (fieldMapping );
452
- }
453
-
454
- private void assertOldIndexUnsupported (XContentBuilder fieldMapping ) {
455
-
456
- MapperParsingException exception = assertThrows (
457
- MapperParsingException .class ,
458
- () -> createMapperService (
459
- fieldMapping ,
460
- true ,
461
- IndexVersions .V_8_0_0 ,
462
- IndexVersionUtils .getPreviousVersion (IndexVersions .NEW_SPARSE_VECTOR )
463
- )
464
- );
465
- assertTrue (exception .getMessage ().contains (UNSUPPORTED_INDEX_MESSAGE ));
466
- assertTrue (exception .getRootCause () instanceof UnsupportedOperationException );
467
- }
468
-
469
418
public void testMultiFieldsSupport () throws IOException {
470
419
if (useLegacyFormat ) {
471
420
Exception e = expectThrows (MapperParsingException .class , () -> createMapperService (fieldMapping (b -> {
@@ -1265,6 +1214,99 @@ public void testModelSettingsRequiredWithChunks() throws IOException {
1265
1214
assertThat (ex .getMessage (), containsString ("[model_settings] must be set for field [field] when chunks are provided" ));
1266
1215
}
1267
1216
1217
+ public void testPre811IndexSemanticTextDenseVectorRaisesError () throws IOException {
1218
+ Model model = TestModel .createRandomInstance (TaskType .TEXT_EMBEDDING );
1219
+ String fieldName = randomAlphaOfLength (8 );
1220
+
1221
+ MapperService mapperService = createMapperService (
1222
+ mapping (
1223
+ b -> b .startObject (fieldName ).field ("type" , "semantic_text" ).field ("inference_id" , model .getInferenceEntityId ()).endObject ()
1224
+ ),
1225
+ true ,
1226
+ IndexVersions .V_8_0_0 ,
1227
+ IndexVersionUtils .getPreviousVersion (IndexVersions .NEW_SPARSE_VECTOR )
1228
+ );
1229
+ assertSemanticTextField (mapperService , fieldName , false , null , null );
1230
+
1231
+ merge (
1232
+ mapperService ,
1233
+ mapping (
1234
+ b -> b .startObject (fieldName )
1235
+ .field ("type" , "semantic_text" )
1236
+ .field ("inference_id" , model .getInferenceEntityId ())
1237
+ .startObject ("model_settings" )
1238
+ .field ("task_type" , TaskType .TEXT_EMBEDDING .toString ())
1239
+ .field ("dimensions" , model .getServiceSettings ().dimensions ())
1240
+ .field ("similarity" , model .getServiceSettings ().similarity ())
1241
+ .field ("element_type" , model .getServiceSettings ().elementType ())
1242
+ .endObject ()
1243
+ .endObject ()
1244
+ )
1245
+ );
1246
+ assertSemanticTextField (mapperService , fieldName , true , null , null );
1247
+
1248
+ DocumentMapper documentMapper = mapperService .documentMapper ();
1249
+ DocumentParsingException e = assertThrows (
1250
+ DocumentParsingException .class ,
1251
+ () -> documentMapper .parse (
1252
+ source (
1253
+ b -> addSemanticTextInferenceResults (
1254
+ true ,
1255
+ b ,
1256
+ List .of (randomSemanticText (true , fieldName , model , null , List .of ("foo" , "bar" ), XContentType .JSON ))
1257
+ )
1258
+ )
1259
+ )
1260
+ );
1261
+ assertThat (e .getCause (), instanceOf (UnsupportedOperationException .class ));
1262
+ assertThat (e .getCause ().getMessage (), equalTo (UNSUPPORTED_INDEX_MESSAGE ));
1263
+ }
1264
+
1265
+ public void testPre811IndexSemanticTextSparseVectorRaisesError () throws IOException {
1266
+ Model model = TestModel .createRandomInstance (TaskType .SPARSE_EMBEDDING );
1267
+ String fieldName = randomAlphaOfLength (8 );
1268
+
1269
+ MapperService mapperService = createMapperService (
1270
+ mapping (
1271
+ b -> b .startObject (fieldName ).field ("type" , "semantic_text" ).field ("inference_id" , model .getInferenceEntityId ()).endObject ()
1272
+ ),
1273
+ true ,
1274
+ IndexVersions .V_8_0_0 ,
1275
+ IndexVersionUtils .getPreviousVersion (IndexVersions .NEW_SPARSE_VECTOR )
1276
+ );
1277
+ assertSemanticTextField (mapperService , fieldName , false , null , null );
1278
+
1279
+ merge (
1280
+ mapperService ,
1281
+ mapping (
1282
+ b -> b .startObject (fieldName )
1283
+ .field ("type" , "semantic_text" )
1284
+ .field ("inference_id" , model .getInferenceEntityId ())
1285
+ .startObject ("model_settings" )
1286
+ .field ("task_type" , TaskType .SPARSE_EMBEDDING .toString ())
1287
+ .endObject ()
1288
+ .endObject ()
1289
+ )
1290
+ );
1291
+ assertSemanticTextField (mapperService , fieldName , true , null , null );
1292
+
1293
+ DocumentMapper documentMapper = mapperService .documentMapper ();
1294
+ DocumentParsingException e = assertThrows (
1295
+ DocumentParsingException .class ,
1296
+ () -> documentMapper .parse (
1297
+ source (
1298
+ b -> addSemanticTextInferenceResults (
1299
+ true ,
1300
+ b ,
1301
+ List .of (randomSemanticText (true , fieldName , model , null , List .of ("foo" , "bar" ), XContentType .JSON ))
1302
+ )
1303
+ )
1304
+ )
1305
+ );
1306
+ assertThat (e .getCause (), instanceOf (UnsupportedOperationException .class ));
1307
+ assertThat (e .getCause ().getMessage (), equalTo (UNSUPPORTED_INDEX_MESSAGE ));
1308
+ }
1309
+
1268
1310
private MapperService mapperServiceForFieldWithModelSettings (String fieldName , String inferenceId , MinimalServiceSettings modelSettings )
1269
1311
throws IOException {
1270
1312
return mapperServiceForFieldWithModelSettings (fieldName , inferenceId , null , modelSettings );
0 commit comments