Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions docs/changelog/113563.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.elasticsearch.xpack.inference.rank.random.RandomRankRetrieverBuilder;
import org.elasticsearch.xpack.inference.rank.textsimilarity.TextSimilarityRankRetrieverBuilder;

import java.util.HashSet;
import java.util.Set;

/**
Expand All @@ -22,13 +23,15 @@ public class InferenceFeatures implements FeatureSpecification {

@Override
public Set<NodeFeature> getFeatures() {
return Set.of(
TextSimilarityRankRetrieverBuilder.TEXT_SIMILARITY_RERANKER_RETRIEVER_SUPPORTED,
RandomRankRetrieverBuilder.RANDOM_RERANKER_RETRIEVER_SUPPORTED,
SemanticTextFieldMapper.SEMANTIC_TEXT_SEARCH_INFERENCE_ID,
SemanticTextFieldMapper.SEMANTIC_TEXT_DEFAULT_ELSER_2,
TextSimilarityRankRetrieverBuilder.TEXT_SIMILARITY_RERANKER_COMPOSITION_SUPPORTED
);
var features = new HashSet<NodeFeature>();
features.add(TextSimilarityRankRetrieverBuilder.TEXT_SIMILARITY_RERANKER_RETRIEVER_SUPPORTED);
features.add(RandomRankRetrieverBuilder.RANDOM_RERANKER_RETRIEVER_SUPPORTED);
features.add(SemanticTextFieldMapper.SEMANTIC_TEXT_SEARCH_INFERENCE_ID);
features.add(TextSimilarityRankRetrieverBuilder.TEXT_SIMILARITY_RERANKER_COMPOSITION_SUPPORTED);
if (DefaultElserFeatureFlag.isEnabled()) {
features.add(SemanticTextFieldMapper.SEMANTIC_TEXT_DEFAULT_ELSER_2);
}
return Set.copyOf(features);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xpack.core.ml.inference.results.MlTextEmbeddingResults;
import org.elasticsearch.xpack.core.ml.inference.results.TextExpansionResults;
import org.elasticsearch.xpack.inference.DefaultElserFeatureFlag;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -108,12 +109,16 @@ public static class Builder extends FieldMapper.Builder {
INFERENCE_ID_FIELD,
false,
mapper -> ((SemanticTextFieldType) mapper.fieldType()).inferenceId,
DEFAULT_ELSER_2_INFERENCE_ID
DefaultElserFeatureFlag.isEnabled() ? DEFAULT_ELSER_2_INFERENCE_ID : null
).addValidator(v -> {
if (Strings.isEmpty(v)) {
throw new IllegalArgumentException(
"[" + INFERENCE_ID_FIELD + "] on mapper [" + leafName() + "] of type [" + CONTENT_TYPE + "] must not be empty"
);
// If the default ELSER feature flag is enabled, the only way we get here is if the user explicitly sets the param to an
// empty value. However, if the feature flag is disabled, we can get here if the user didn't set the param.
// Adjust the error message appropriately.
String message = DefaultElserFeatureFlag.isEnabled()
? "[" + INFERENCE_ID_FIELD + "] on mapper [" + leafName() + "] of type [" + CONTENT_TYPE + "] must not be empty"
: "[" + INFERENCE_ID_FIELD + "] on mapper [" + leafName() + "] of type [" + CONTENT_TYPE + "] must be specified";
throw new IllegalArgumentException(message);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.xcontent.json.JsonXContent;
import org.elasticsearch.xpack.inference.DefaultElserFeatureFlag;
import org.elasticsearch.xpack.inference.InferencePlugin;
import org.elasticsearch.xpack.inference.model.TestModel;
import org.junit.AssumptionViolatedException;
Expand Down Expand Up @@ -102,6 +103,9 @@ protected Collection<? extends Plugin> getPlugins() {
@Override
protected void minimalMapping(XContentBuilder b) throws IOException {
b.field("type", "semantic_text");
if (DefaultElserFeatureFlag.isEnabled() == false) {
b.field("inference_id", "test_model");
}
}

@Override
Expand Down Expand Up @@ -171,7 +175,9 @@ public void testDefaults() throws Exception {
DocumentMapper mapper = mapperService.documentMapper();
assertEquals(Strings.toString(fieldMapping), mapper.mappingSource().toString());
assertSemanticTextField(mapperService, fieldName, false);
assertInferenceEndpoints(mapperService, fieldName, DEFAULT_ELSER_2_INFERENCE_ID, DEFAULT_ELSER_2_INFERENCE_ID);
if (DefaultElserFeatureFlag.isEnabled()) {
assertInferenceEndpoints(mapperService, fieldName, DEFAULT_ELSER_2_INFERENCE_ID, DEFAULT_ELSER_2_INFERENCE_ID);
}

ParsedDocument doc1 = mapper.parse(source(this::writeField));
List<IndexableField> fields = doc1.rootDoc().getFields("field");
Expand Down Expand Up @@ -205,13 +211,15 @@ public void testSetInferenceEndpoints() throws IOException {
assertSerialization.accept(fieldMapping, mapperService);
}
{
final XContentBuilder fieldMapping = fieldMapping(
b -> b.field("type", "semantic_text").field(SEARCH_INFERENCE_ID_FIELD, searchInferenceId)
);
final MapperService mapperService = createMapperService(fieldMapping);
assertSemanticTextField(mapperService, fieldName, false);
assertInferenceEndpoints(mapperService, fieldName, DEFAULT_ELSER_2_INFERENCE_ID, searchInferenceId);
assertSerialization.accept(fieldMapping, mapperService);
if (DefaultElserFeatureFlag.isEnabled()) {
final XContentBuilder fieldMapping = fieldMapping(
b -> b.field("type", "semantic_text").field(SEARCH_INFERENCE_ID_FIELD, searchInferenceId)
);
final MapperService mapperService = createMapperService(fieldMapping);
assertSemanticTextField(mapperService, fieldName, false);
assertInferenceEndpoints(mapperService, fieldName, DEFAULT_ELSER_2_INFERENCE_ID, searchInferenceId);
assertSerialization.accept(fieldMapping, mapperService);
}
}
{
final XContentBuilder fieldMapping = fieldMapping(
Expand All @@ -238,18 +246,26 @@ public void testInvalidInferenceEndpoints() {
);
}
{
final String expectedMessage = DefaultElserFeatureFlag.isEnabled()
? "[inference_id] on mapper [field] of type [semantic_text] must not be empty"
: "[inference_id] on mapper [field] of type [semantic_text] must be specified";
Exception e = expectThrows(
MapperParsingException.class,
() -> createMapperService(fieldMapping(b -> b.field("type", "semantic_text").field(INFERENCE_ID_FIELD, "")))
);
assertThat(e.getMessage(), containsString("[inference_id] on mapper [field] of type [semantic_text] must not be empty"));
assertThat(e.getMessage(), containsString(expectedMessage));
}
{
Exception e = expectThrows(
MapperParsingException.class,
() -> createMapperService(fieldMapping(b -> b.field("type", "semantic_text").field(SEARCH_INFERENCE_ID_FIELD, "")))
);
assertThat(e.getMessage(), containsString("[search_inference_id] on mapper [field] of type [semantic_text] must not be empty"));
if (DefaultElserFeatureFlag.isEnabled()) {
Exception e = expectThrows(
MapperParsingException.class,
() -> createMapperService(fieldMapping(b -> b.field("type", "semantic_text").field(SEARCH_INFERENCE_ID_FIELD, "")))
);
assertThat(
e.getMessage(),
containsString("[search_inference_id] on mapper [field] of type [semantic_text] must not be empty")
);
}
}
}

Expand Down