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