@@ -340,57 +340,6 @@ public void testInvalidTaskTypes() {
340
340
}
341
341
}
342
342
343
- @ Override
344
- protected IndexVersion boostNotAllowedIndexVersion () {
345
- return IndexVersions .NEW_SPARSE_VECTOR ;
346
- }
347
-
348
- public void testOldIndexSemanticTextDenseVectorRaisesError () throws IOException {
349
- final String fieldName = "field" ;
350
- final XContentBuilder fieldMapping = fieldMapping (b -> {
351
- b .field ("type" , "semantic_text" );
352
- b .field (INFERENCE_ID_FIELD , "test_inference_id" );
353
- b .startObject ("model_settings" );
354
- b .field ("task_type" , "text_embedding" );
355
- b .field ("dimensions" , 384 );
356
- b .field ("similarity" , "cosine" );
357
- b .field ("element_type" , "float" );
358
- b .endObject ();
359
- });
360
- assertOldIndexUnsupported (fieldMapping );
361
- }
362
-
363
- public void testOldIndexSemanticTextMinimalMappingRaisesError () throws IOException {
364
- final XContentBuilder fieldMapping = fieldMapping (this ::minimalMapping );
365
- assertOldIndexUnsupported (fieldMapping );
366
- }
367
-
368
- public void testOldIndexSemanticTextSparseVersionRaisesError () throws IOException {
369
- final XContentBuilder fieldMapping = fieldMapping (b -> {
370
- b .field ("type" , "semantic_text" );
371
- b .field ("inference_id" , "another_inference_id" );
372
- b .startObject ("model_settings" );
373
- b .field ("task_type" , "sparse_embedding" );
374
- b .endObject ();
375
- });
376
- assertOldIndexUnsupported (fieldMapping );
377
- }
378
-
379
- private void assertOldIndexUnsupported (XContentBuilder fieldMapping ) {
380
-
381
- MapperParsingException exception = assertThrows (
382
- MapperParsingException .class ,
383
- () -> createMapperService (
384
- fieldMapping ,
385
- true ,
386
- IndexVersions .V_8_0_0 ,
387
- IndexVersionUtils .getPreviousVersion (IndexVersions .NEW_SPARSE_VECTOR )
388
- )
389
- );
390
- assertTrue (exception .getMessage ().contains (UNSUPPORTED_INDEX_MESSAGE ));
391
- assertTrue (exception .getRootCause () instanceof UnsupportedOperationException );
392
- }
393
-
394
343
public void testMultiFieldsSupport () throws IOException {
395
344
if (useLegacyFormat ) {
396
345
Exception e = expectThrows (MapperParsingException .class , () -> createMapperService (fieldMapping (b -> {
@@ -944,6 +893,99 @@ public void testModelSettingsRequiredWithChunks() throws IOException {
944
893
assertThat (ex .getMessage (), containsString ("[model_settings] must be set for field [field] when chunks are provided" ));
945
894
}
946
895
896
+ public void testPre811IndexSemanticTextDenseVectorRaisesError () throws IOException {
897
+ Model model = TestModel .createRandomInstance (TaskType .TEXT_EMBEDDING );
898
+ String fieldName = randomAlphaOfLength (8 );
899
+
900
+ MapperService mapperService = createMapperService (
901
+ mapping (
902
+ b -> b .startObject (fieldName ).field ("type" , "semantic_text" ).field ("inference_id" , model .getInferenceEntityId ()).endObject ()
903
+ ),
904
+ true ,
905
+ IndexVersions .V_8_0_0 ,
906
+ IndexVersionUtils .getPreviousVersion (IndexVersions .NEW_SPARSE_VECTOR )
907
+ );
908
+ assertSemanticTextField (mapperService , fieldName , false );
909
+
910
+ merge (
911
+ mapperService ,
912
+ mapping (
913
+ b -> b .startObject (fieldName )
914
+ .field ("type" , "semantic_text" )
915
+ .field ("inference_id" , model .getInferenceEntityId ())
916
+ .startObject ("model_settings" )
917
+ .field ("task_type" , TaskType .TEXT_EMBEDDING .toString ())
918
+ .field ("dimensions" , model .getServiceSettings ().dimensions ())
919
+ .field ("similarity" , model .getServiceSettings ().similarity ())
920
+ .field ("element_type" , model .getServiceSettings ().elementType ())
921
+ .endObject ()
922
+ .endObject ()
923
+ )
924
+ );
925
+ assertSemanticTextField (mapperService , fieldName , true );
926
+
927
+ DocumentMapper documentMapper = mapperService .documentMapper ();
928
+ DocumentParsingException e = assertThrows (
929
+ DocumentParsingException .class ,
930
+ () -> documentMapper .parse (
931
+ source (
932
+ b -> addSemanticTextInferenceResults (
933
+ true ,
934
+ b ,
935
+ List .of (randomSemanticText (true , fieldName , model , List .of ("foo" , "bar" ), XContentType .JSON ))
936
+ )
937
+ )
938
+ )
939
+ );
940
+ assertThat (e .getCause (), instanceOf (UnsupportedOperationException .class ));
941
+ assertThat (e .getCause ().getMessage (), equalTo (UNSUPPORTED_INDEX_MESSAGE ));
942
+ }
943
+
944
+ public void testPre811IndexSemanticTextSparseVectorRaisesError () throws IOException {
945
+ Model model = TestModel .createRandomInstance (TaskType .SPARSE_EMBEDDING );
946
+ String fieldName = randomAlphaOfLength (8 );
947
+
948
+ MapperService mapperService = createMapperService (
949
+ mapping (
950
+ b -> b .startObject (fieldName ).field ("type" , "semantic_text" ).field ("inference_id" , model .getInferenceEntityId ()).endObject ()
951
+ ),
952
+ true ,
953
+ IndexVersions .V_8_0_0 ,
954
+ IndexVersionUtils .getPreviousVersion (IndexVersions .NEW_SPARSE_VECTOR )
955
+ );
956
+ assertSemanticTextField (mapperService , fieldName , false );
957
+
958
+ merge (
959
+ mapperService ,
960
+ mapping (
961
+ b -> b .startObject (fieldName )
962
+ .field ("type" , "semantic_text" )
963
+ .field ("inference_id" , model .getInferenceEntityId ())
964
+ .startObject ("model_settings" )
965
+ .field ("task_type" , TaskType .SPARSE_EMBEDDING .toString ())
966
+ .endObject ()
967
+ .endObject ()
968
+ )
969
+ );
970
+ assertSemanticTextField (mapperService , fieldName , true );
971
+
972
+ DocumentMapper documentMapper = mapperService .documentMapper ();
973
+ DocumentParsingException e = assertThrows (
974
+ DocumentParsingException .class ,
975
+ () -> documentMapper .parse (
976
+ source (
977
+ b -> addSemanticTextInferenceResults (
978
+ true ,
979
+ b ,
980
+ List .of (randomSemanticText (true , fieldName , model , List .of ("foo" , "bar" ), XContentType .JSON ))
981
+ )
982
+ )
983
+ )
984
+ );
985
+ assertThat (e .getCause (), instanceOf (UnsupportedOperationException .class ));
986
+ assertThat (e .getCause ().getMessage (), equalTo (UNSUPPORTED_INDEX_MESSAGE ));
987
+ }
988
+
947
989
private MapperService mapperServiceForFieldWithModelSettings (String fieldName , String inferenceId , MinimalServiceSettings modelSettings )
948
990
throws IOException {
949
991
return mapperServiceForFieldWithModelSettings (fieldName , inferenceId , null , modelSettings );
0 commit comments