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