|
110 | 110 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextField.getEmbeddingsFieldName; |
111 | 111 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.DEFAULT_ELSER_2_INFERENCE_ID; |
112 | 112 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.DEFAULT_RESCORE_OVERSAMPLE; |
| 113 | +import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.ERROR_MESSAGE_UNSUPPORTED_SPARSE_VECTOR; |
113 | 114 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.INDEX_OPTIONS_FIELD; |
114 | 115 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.generateRandomChunkingSettings; |
115 | 116 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.generateRandomChunkingSettingsOtherThan; |
@@ -1748,6 +1749,28 @@ public static void addSemanticTextInferenceResults( |
1748 | 1749 | } |
1749 | 1750 | } |
1750 | 1751 |
|
| 1752 | + public void testOldIndexSemanticTextSparseVersionRaisesError() throws IOException { |
| 1753 | + final XContentBuilder fieldMapping = fieldMapping(b -> { |
| 1754 | + b.field("type", "semantic_text"); |
| 1755 | + b.field("inference_id", "another_inference_id"); |
| 1756 | + b.startObject("model_settings"); |
| 1757 | + b.field("task_type", "sparse_embedding"); |
| 1758 | + b.endObject(); |
| 1759 | + }); |
| 1760 | + |
| 1761 | + MapperParsingException exception = assertThrows( |
| 1762 | + MapperParsingException.class, |
| 1763 | + () -> createMapperService( |
| 1764 | + fieldMapping, |
| 1765 | + true, |
| 1766 | + IndexVersions.V_8_0_0, |
| 1767 | + IndexVersionUtils.getPreviousVersion(IndexVersions.NEW_SPARSE_VECTOR) |
| 1768 | + ) |
| 1769 | + ); |
| 1770 | + assertTrue(exception.getMessage().contains(ERROR_MESSAGE_UNSUPPORTED_SPARSE_VECTOR)); |
| 1771 | + assertTrue(exception.getRootCause() instanceof IllegalArgumentException); |
| 1772 | + } |
| 1773 | + |
1751 | 1774 | static String randomFieldName(int numLevel) { |
1752 | 1775 | StringBuilder builder = new StringBuilder(); |
1753 | 1776 | for (int i = 0; i < numLevel; i++) { |
|
0 commit comments