@@ -402,57 +402,6 @@ public void testInvalidTaskTypes() {
402
402
}
403
403
}
404
404
405
- @ Override
406
- protected IndexVersion boostNotAllowedIndexVersion () {
407
- return IndexVersions .NEW_SPARSE_VECTOR ;
408
- }
409
-
410
- public void testOldIndexSemanticTextDenseVectorRaisesError () throws IOException {
411
- final String fieldName = "field" ;
412
- final XContentBuilder fieldMapping = fieldMapping (b -> {
413
- b .field ("type" , "semantic_text" );
414
- b .field (INFERENCE_ID_FIELD , "test_inference_id" );
415
- b .startObject ("model_settings" );
416
- b .field ("task_type" , "text_embedding" );
417
- b .field ("dimensions" , 384 );
418
- b .field ("similarity" , "cosine" );
419
- b .field ("element_type" , "float" );
420
- b .endObject ();
421
- });
422
- assertOldIndexUnsupported (fieldMapping );
423
- }
424
-
425
- public void testOldIndexSemanticTextMinimalMappingRaisesError () throws IOException {
426
- final XContentBuilder fieldMapping = fieldMapping (this ::minimalMapping );
427
- assertOldIndexUnsupported (fieldMapping );
428
- }
429
-
430
- public void testOldIndexSemanticTextSparseVersionRaisesError () throws IOException {
431
- final XContentBuilder fieldMapping = fieldMapping (b -> {
432
- b .field ("type" , "semantic_text" );
433
- b .field ("inference_id" , "another_inference_id" );
434
- b .startObject ("model_settings" );
435
- b .field ("task_type" , "sparse_embedding" );
436
- b .endObject ();
437
- });
438
- assertOldIndexUnsupported (fieldMapping );
439
- }
440
-
441
- private void assertOldIndexUnsupported (XContentBuilder fieldMapping ) {
442
-
443
- MapperParsingException exception = assertThrows (
444
- MapperParsingException .class ,
445
- () -> createMapperService (
446
- fieldMapping ,
447
- true ,
448
- IndexVersions .V_8_0_0 ,
449
- IndexVersionUtils .getPreviousVersion (IndexVersions .NEW_SPARSE_VECTOR )
450
- )
451
- );
452
- assertTrue (exception .getMessage ().contains (UNSUPPORTED_INDEX_MESSAGE ));
453
- assertTrue (exception .getRootCause () instanceof UnsupportedOperationException );
454
- }
455
-
456
405
public void testMultiFieldsSupport () throws IOException {
457
406
if (useLegacyFormat ) {
458
407
Exception e = expectThrows (MapperParsingException .class , () -> createMapperService (fieldMapping (b -> {
@@ -1133,6 +1082,99 @@ public void testModelSettingsRequiredWithChunks() throws IOException {
1133
1082
assertThat (ex .getMessage (), containsString ("[model_settings] must be set for field [field] when chunks are provided" ));
1134
1083
}
1135
1084
1085
+ public void testPre811IndexSemanticTextDenseVectorRaisesError () throws IOException {
1086
+ Model model = TestModel .createRandomInstance (TaskType .TEXT_EMBEDDING );
1087
+ String fieldName = randomAlphaOfLength (8 );
1088
+
1089
+ MapperService mapperService = createMapperService (
1090
+ mapping (
1091
+ b -> b .startObject (fieldName ).field ("type" , "semantic_text" ).field ("inference_id" , model .getInferenceEntityId ()).endObject ()
1092
+ ),
1093
+ true ,
1094
+ IndexVersions .V_8_0_0 ,
1095
+ IndexVersionUtils .getPreviousVersion (IndexVersions .NEW_SPARSE_VECTOR )
1096
+ );
1097
+ assertSemanticTextField (mapperService , fieldName , false , null , null );
1098
+
1099
+ merge (
1100
+ mapperService ,
1101
+ mapping (
1102
+ b -> b .startObject (fieldName )
1103
+ .field ("type" , "semantic_text" )
1104
+ .field ("inference_id" , model .getInferenceEntityId ())
1105
+ .startObject ("model_settings" )
1106
+ .field ("task_type" , TaskType .TEXT_EMBEDDING .toString ())
1107
+ .field ("dimensions" , model .getServiceSettings ().dimensions ())
1108
+ .field ("similarity" , model .getServiceSettings ().similarity ())
1109
+ .field ("element_type" , model .getServiceSettings ().elementType ())
1110
+ .endObject ()
1111
+ .endObject ()
1112
+ )
1113
+ );
1114
+ assertSemanticTextField (mapperService , fieldName , true , null , null );
1115
+
1116
+ DocumentMapper documentMapper = mapperService .documentMapper ();
1117
+ DocumentParsingException e = assertThrows (
1118
+ DocumentParsingException .class ,
1119
+ () -> documentMapper .parse (
1120
+ source (
1121
+ b -> addSemanticTextInferenceResults (
1122
+ true ,
1123
+ b ,
1124
+ List .of (randomSemanticText (true , fieldName , model , null , List .of ("foo" , "bar" ), XContentType .JSON ))
1125
+ )
1126
+ )
1127
+ )
1128
+ );
1129
+ assertThat (e .getCause (), instanceOf (UnsupportedOperationException .class ));
1130
+ assertThat (e .getCause ().getMessage (), equalTo (UNSUPPORTED_INDEX_MESSAGE ));
1131
+ }
1132
+
1133
+ public void testPre811IndexSemanticTextSparseVectorRaisesError () throws IOException {
1134
+ Model model = TestModel .createRandomInstance (TaskType .SPARSE_EMBEDDING );
1135
+ String fieldName = randomAlphaOfLength (8 );
1136
+
1137
+ MapperService mapperService = createMapperService (
1138
+ mapping (
1139
+ b -> b .startObject (fieldName ).field ("type" , "semantic_text" ).field ("inference_id" , model .getInferenceEntityId ()).endObject ()
1140
+ ),
1141
+ true ,
1142
+ IndexVersions .V_8_0_0 ,
1143
+ IndexVersionUtils .getPreviousVersion (IndexVersions .NEW_SPARSE_VECTOR )
1144
+ );
1145
+ assertSemanticTextField (mapperService , fieldName , false , null , null );
1146
+
1147
+ merge (
1148
+ mapperService ,
1149
+ mapping (
1150
+ b -> b .startObject (fieldName )
1151
+ .field ("type" , "semantic_text" )
1152
+ .field ("inference_id" , model .getInferenceEntityId ())
1153
+ .startObject ("model_settings" )
1154
+ .field ("task_type" , TaskType .SPARSE_EMBEDDING .toString ())
1155
+ .endObject ()
1156
+ .endObject ()
1157
+ )
1158
+ );
1159
+ assertSemanticTextField (mapperService , fieldName , true , null , null );
1160
+
1161
+ DocumentMapper documentMapper = mapperService .documentMapper ();
1162
+ DocumentParsingException e = assertThrows (
1163
+ DocumentParsingException .class ,
1164
+ () -> documentMapper .parse (
1165
+ source (
1166
+ b -> addSemanticTextInferenceResults (
1167
+ true ,
1168
+ b ,
1169
+ List .of (randomSemanticText (true , fieldName , model , null , List .of ("foo" , "bar" ), XContentType .JSON ))
1170
+ )
1171
+ )
1172
+ )
1173
+ );
1174
+ assertThat (e .getCause (), instanceOf (UnsupportedOperationException .class ));
1175
+ assertThat (e .getCause ().getMessage (), equalTo (UNSUPPORTED_INDEX_MESSAGE ));
1176
+ }
1177
+
1136
1178
private MapperService mapperServiceForFieldWithModelSettings (String fieldName , String inferenceId , MinimalServiceSettings modelSettings )
1137
1179
throws IOException {
1138
1180
return mapperServiceForFieldWithModelSettings (fieldName , inferenceId , null , modelSettings );
0 commit comments