Skip to content

Commit 99bbd07

Browse files
committed
reverting most of the stuff
1 parent 0eeee59 commit 99bbd07

File tree

4 files changed

+37
-43
lines changed

4 files changed

+37
-43
lines changed

server/src/main/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldMapper.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,6 @@ protected Parameter<?>[] getParameters() {
406406
return new Parameter<?>[] { elementType, dims, indexed, similarity, indexOptions, meta };
407407
}
408408

409-
public Builder indexed(boolean indexed) {
410-
this.indexed.setValue(indexed);
411-
return this;
412-
}
413-
414409
public Builder similarity(VectorSimilarity vectorSimilarity) {
415410
similarity.setValue(vectorSimilarity);
416411
return this;

server/src/test/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldMapperTests.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2230,27 +2230,6 @@ public void testValidateOnBuild() {
22302230
);
22312231
}
22322232

2233-
public void testSetIndexed() {
2234-
final MapperBuilderContext context = MapperBuilderContext.root(false, false);
2235-
2236-
DenseVectorFieldMapper mapper = new DenseVectorFieldMapper.Builder(
2237-
"test",
2238-
IndexVersionUtils.getPreviousVersion(INDEXED_BY_DEFAULT_INDEX_VERSION),
2239-
false
2240-
).elementType(ElementType.FLOAT).build(context);
2241-
DenseVectorFieldType denseVectorFieldType = mapper.fieldType();
2242-
assertFalse(denseVectorFieldType.isIndexed());
2243-
2244-
mapper = new DenseVectorFieldMapper.Builder("test", IndexVersionUtils.getPreviousVersion(INDEXED_BY_DEFAULT_INDEX_VERSION), false)
2245-
.elementType(ElementType.FLOAT)
2246-
.indexed(true)
2247-
.similarity(VectorSimilarity.COSINE)
2248-
.build(context);
2249-
2250-
denseVectorFieldType = mapper.fieldType();
2251-
assertTrue(denseVectorFieldType.isIndexed());
2252-
}
2253-
22542233
private static float[] decodeDenseVector(IndexVersion indexVersion, BytesRef encodedVector) {
22552234
int dimCount = VectorEncoderDecoder.denseVectorLength(indexVersion, encodedVector);
22562235
float[] vector = new float[dimCount];

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapper.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@
130130
*/
131131
public class SemanticTextFieldMapper extends FieldMapper implements InferenceFieldMapper {
132132
private static final Logger logger = LogManager.getLogger(SemanticTextFieldMapper.class);
133-
public static final String WARNING_MESSAGE_8X = "Creating a `semantic_text` field on this index version may not include"
134-
+ " optimized default settings. Consider creating a new index for better performance.";
133+
public static final String UNSUPPORTED_INDEX_MESSAGE = "[semantic_text] is available on indices created with 8.11+.";
135134
public static final NodeFeature SEMANTIC_TEXT_IN_OBJECT_FIELD_FIX = new NodeFeature("semantic_text.in_object_field_fix");
136135
public static final NodeFeature SEMANTIC_TEXT_SINGLE_FIELD_UPDATE_FIX = new NodeFeature("semantic_text.single_field_update_fix");
137136
public static final NodeFeature SEMANTIC_TEXT_DELETE_FIX = new NodeFeature("semantic_text.delete_fix");
@@ -170,6 +169,9 @@ public static final TypeParser parser(Supplier<ModelRegistry> modelRegistry) {
170169

171170
public static BiConsumer<String, MappingParserContext> validateParserContext(String type) {
172171
return (n, c) -> {
172+
if (c.getIndexSettings().getIndexVersionCreated().before(NEW_SPARSE_VECTOR)) {
173+
throw new UnsupportedOperationException(UNSUPPORTED_INDEX_MESSAGE);
174+
};
173175
if (InferenceMetadataFieldsMapper.isEnabled(c.getIndexSettings().getSettings()) == false) {
174176
notInMultiFields(type).accept(n, c);
175177
}
@@ -1301,11 +1303,6 @@ private static void configureDenseVectorMapperBuilder(
13011303
MinimalServiceSettings modelSettings,
13021304
SemanticTextIndexOptions indexOptions
13031305
) {
1304-
if (indexVersionCreated.before(INDEXED_BY_DEFAULT_INDEX_VERSION)) {
1305-
deprecationLogger.warn(DeprecationCategory.MAPPINGS, "semantic_text", WARNING_MESSAGE_8X);
1306-
}
1307-
denseVectorMapperBuilder.indexed(true);
1308-
13091306
SimilarityMeasure similarity = modelSettings.similarity();
13101307
if (similarity != null) {
13111308
switch (similarity) {

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapperTests.java

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,8 @@
110110
import static org.elasticsearch.xpack.inference.mapper.SemanticTextField.getEmbeddingsFieldName;
111111
import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.DEFAULT_ELSER_2_INFERENCE_ID;
112112
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;
114113
import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.INDEX_OPTIONS_FIELD;
115-
import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.WARNING_MESSAGE_8X;
114+
import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper.UNSUPPORTED_INDEX_MESSAGE;
116115
import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.generateRandomChunkingSettings;
117116
import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.generateRandomChunkingSettingsOtherThan;
118117
import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.randomSemanticText;
@@ -428,16 +427,40 @@ public void testOldIndexSemanticTextDenseVectorCreation() throws IOException {
428427
b.field("element_type", "float");
429428
b.endObject();
430429
});
430+
assertOldIndexUnsupported(fieldMapping);
431+
}
431432

432-
MapperService mapperService = createMapperService(
433-
fieldMapping,
434-
true,
435-
IndexVersions.V_8_0_0,
436-
IndexVersionUtils.getPreviousVersion(IndexVersions.FIRST_DETACHED_INDEX_VERSION)
433+
public void testOldIndexSemanticTextMinimalMappingRaisesError() throws IOException {
434+
final XContentBuilder fieldMapping = fieldMapping(this::minimalMapping);
435+
assertOldIndexUnsupported(fieldMapping);
436+
}
437+
438+
public void testOldIndexSemanticTextSparseVersionRaisesError() throws IOException {
439+
final XContentBuilder fieldMapping = fieldMapping(b -> {
440+
b.field("type", "semantic_text");
441+
b.field("inference_id", "another_inference_id");
442+
b.startObject("model_settings");
443+
b.field("task_type", "sparse_embedding");
444+
b.endObject();
445+
});
446+
assertOldIndexUnsupported(fieldMapping);
447+
}
448+
449+
private void assertOldIndexUnsupported(
450+
XContentBuilder fieldMapping
451+
) {
452+
453+
MapperParsingException exception = assertThrows(
454+
MapperParsingException.class,
455+
() -> createMapperService(
456+
fieldMapping,
457+
true,
458+
IndexVersions.V_8_0_0,
459+
IndexVersionUtils.getPreviousVersion(IndexVersions.NEW_SPARSE_VECTOR)
460+
)
437461
);
438-
assertWarnings(WARNING_MESSAGE_8X);
439-
assertParseMinimalWarnings();
440-
assertSemanticTextField(mapperService, fieldName, true, null, null);
462+
assertTrue(exception.getMessage().contains(UNSUPPORTED_INDEX_MESSAGE));
463+
assertTrue(exception.getRootCause() instanceof UnsupportedOperationException);
441464
}
442465

443466
public void testMultiFieldsSupport() throws IOException {

0 commit comments

Comments
 (0)