|
107 | 107 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.DEFAULT_ELSER_2_INFERENCE_ID;
|
108 | 108 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.DEFAULT_RESCORE_OVERSAMPLE;
|
109 | 109 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.INDEX_OPTIONS_FIELD;
|
| 110 | +import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.UNSUPPORTED_INDEX_MESSAGE; |
110 | 111 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.generateRandomChunkingSettings;
|
111 | 112 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.generateRandomChunkingSettingsOtherThan;
|
112 | 113 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.randomSemanticText;
|
| 114 | +import static org.hamcrest.Matchers.anyOf; |
113 | 115 | import static org.hamcrest.Matchers.containsString;
|
114 | 116 | import static org.hamcrest.Matchers.equalTo;
|
115 | 117 | import static org.hamcrest.Matchers.instanceOf;
|
@@ -400,6 +402,57 @@ public void testInvalidTaskTypes() {
|
400 | 402 | }
|
401 | 403 | }
|
402 | 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 | + |
403 | 456 | public void testMultiFieldsSupport() throws IOException {
|
404 | 457 | if (useLegacyFormat) {
|
405 | 458 | Exception e = expectThrows(MapperParsingException.class, () -> createMapperService(fieldMapping(b -> {
|
@@ -1364,6 +1417,34 @@ public void testSpecifiedDenseVectorIndexOptions() throws IOException {
|
1364 | 1417 |
|
1365 | 1418 | }
|
1366 | 1419 |
|
| 1420 | + /** |
| 1421 | + * Semantic text version error supersedes deprecated boost warning |
| 1422 | + * @throws IOException |
| 1423 | + */ |
| 1424 | + @Override |
| 1425 | + public void testDeprecatedBoostWarning() throws IOException { |
| 1426 | + try { |
| 1427 | + createMapperService(DEPRECATED_BOOST_INDEX_VERSION, fieldMapping(b -> { |
| 1428 | + minimalMapping(b, DEPRECATED_BOOST_INDEX_VERSION); |
| 1429 | + b.field("boost", 2.0); |
| 1430 | + })); |
| 1431 | + String[] warnings = Strings.concatStringArrays( |
| 1432 | + getParseMinimalWarnings(DEPRECATED_BOOST_INDEX_VERSION), |
| 1433 | + new String[] { "Parameter [boost] on field [field] is deprecated and has no effect" } |
| 1434 | + ); |
| 1435 | + assertWarnings(warnings); |
| 1436 | + } catch (MapperParsingException e) { |
| 1437 | + assertThat( |
| 1438 | + e.getMessage(), |
| 1439 | + anyOf( |
| 1440 | + containsString(UNSUPPORTED_INDEX_MESSAGE), |
| 1441 | + containsString("Unknown parameter [boost]"), |
| 1442 | + containsString("[boost : 2.0]") |
| 1443 | + ) |
| 1444 | + ); |
| 1445 | + } |
| 1446 | + } |
| 1447 | + |
1367 | 1448 | public static SemanticTextIndexOptions randomSemanticTextIndexOptions() {
|
1368 | 1449 | TaskType taskType = randomFrom(TaskType.SPARSE_EMBEDDING, TaskType.TEXT_EMBEDDING);
|
1369 | 1450 | return randomSemanticTextIndexOptions(taskType);
|
|
0 commit comments