Skip to content

Commit e5a3e94

Browse files
authored
Always Enable Default ELSER Endpoint For Semantic Text (elastic#114711)
1 parent 35792c3 commit e5a3e94

File tree

3 files changed

+25
-49
lines changed

3 files changed

+25
-49
lines changed

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.elasticsearch.xpack.inference.rank.random.RandomRankRetrieverBuilder;
1414
import org.elasticsearch.xpack.inference.rank.textsimilarity.TextSimilarityRankRetrieverBuilder;
1515

16-
import java.util.HashSet;
1716
import java.util.Set;
1817

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

2423
@Override
2524
public Set<NodeFeature> getFeatures() {
26-
var features = new HashSet<NodeFeature>();
27-
features.add(TextSimilarityRankRetrieverBuilder.TEXT_SIMILARITY_RERANKER_RETRIEVER_SUPPORTED);
28-
features.add(RandomRankRetrieverBuilder.RANDOM_RERANKER_RETRIEVER_SUPPORTED);
29-
features.add(SemanticTextFieldMapper.SEMANTIC_TEXT_SEARCH_INFERENCE_ID);
30-
features.add(TextSimilarityRankRetrieverBuilder.TEXT_SIMILARITY_RERANKER_COMPOSITION_SUPPORTED);
31-
if (DefaultElserFeatureFlag.isEnabled()) {
32-
features.add(SemanticTextFieldMapper.SEMANTIC_TEXT_DEFAULT_ELSER_2);
33-
}
34-
return Set.copyOf(features);
25+
return Set.of(
26+
TextSimilarityRankRetrieverBuilder.TEXT_SIMILARITY_RERANKER_RETRIEVER_SUPPORTED,
27+
RandomRankRetrieverBuilder.RANDOM_RERANKER_RETRIEVER_SUPPORTED,
28+
SemanticTextFieldMapper.SEMANTIC_TEXT_SEARCH_INFERENCE_ID,
29+
SemanticTextFieldMapper.SEMANTIC_TEXT_DEFAULT_ELSER_2,
30+
TextSimilarityRankRetrieverBuilder.TEXT_SIMILARITY_RERANKER_COMPOSITION_SUPPORTED
31+
);
3532
}
3633

3734
}

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import org.elasticsearch.xcontent.XContentParserConfiguration;
5555
import org.elasticsearch.xpack.core.ml.inference.results.MlTextEmbeddingResults;
5656
import org.elasticsearch.xpack.core.ml.inference.results.TextExpansionResults;
57-
import org.elasticsearch.xpack.inference.DefaultElserFeatureFlag;
5857

5958
import java.io.IOException;
6059
import java.util.ArrayList;
@@ -105,16 +104,12 @@ public static class Builder extends FieldMapper.Builder {
105104
INFERENCE_ID_FIELD,
106105
false,
107106
mapper -> ((SemanticTextFieldType) mapper.fieldType()).inferenceId,
108-
DefaultElserFeatureFlag.isEnabled() ? DEFAULT_ELSER_2_INFERENCE_ID : null
107+
DEFAULT_ELSER_2_INFERENCE_ID
109108
).addValidator(v -> {
110109
if (Strings.isEmpty(v)) {
111-
// If the default ELSER feature flag is enabled, the only way we get here is if the user explicitly sets the param to an
112-
// empty value. However, if the feature flag is disabled, we can get here if the user didn't set the param.
113-
// Adjust the error message appropriately.
114-
String message = DefaultElserFeatureFlag.isEnabled()
115-
? "[" + INFERENCE_ID_FIELD + "] on mapper [" + leafName() + "] of type [" + CONTENT_TYPE + "] must not be empty"
116-
: "[" + INFERENCE_ID_FIELD + "] on mapper [" + leafName() + "] of type [" + CONTENT_TYPE + "] must be specified";
117-
throw new IllegalArgumentException(message);
110+
throw new IllegalArgumentException(
111+
"[" + INFERENCE_ID_FIELD + "] on mapper [" + leafName() + "] of type [" + CONTENT_TYPE + "] must not be empty"
112+
);
118113
}
119114
});
120115

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

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
import org.elasticsearch.xcontent.XContentBuilder;
6060
import org.elasticsearch.xcontent.XContentType;
6161
import org.elasticsearch.xcontent.json.JsonXContent;
62-
import org.elasticsearch.xpack.inference.DefaultElserFeatureFlag;
6362
import org.elasticsearch.xpack.inference.InferencePlugin;
6463
import org.elasticsearch.xpack.inference.model.TestModel;
6564
import org.junit.AssumptionViolatedException;
@@ -97,9 +96,6 @@ protected Collection<? extends Plugin> getPlugins() {
9796
@Override
9897
protected void minimalMapping(XContentBuilder b) throws IOException {
9998
b.field("type", "semantic_text");
100-
if (DefaultElserFeatureFlag.isEnabled() == false) {
101-
b.field("inference_id", "test_model");
102-
}
10399
}
104100

105101
@Override
@@ -169,9 +165,7 @@ public void testDefaults() throws Exception {
169165
DocumentMapper mapper = mapperService.documentMapper();
170166
assertEquals(Strings.toString(fieldMapping), mapper.mappingSource().toString());
171167
assertSemanticTextField(mapperService, fieldName, false);
172-
if (DefaultElserFeatureFlag.isEnabled()) {
173-
assertInferenceEndpoints(mapperService, fieldName, DEFAULT_ELSER_2_INFERENCE_ID, DEFAULT_ELSER_2_INFERENCE_ID);
174-
}
168+
assertInferenceEndpoints(mapperService, fieldName, DEFAULT_ELSER_2_INFERENCE_ID, DEFAULT_ELSER_2_INFERENCE_ID);
175169

176170
ParsedDocument doc1 = mapper.parse(source(this::writeField));
177171
List<IndexableField> fields = doc1.rootDoc().getFields("field");
@@ -205,15 +199,13 @@ public void testSetInferenceEndpoints() throws IOException {
205199
assertSerialization.accept(fieldMapping, mapperService);
206200
}
207201
{
208-
if (DefaultElserFeatureFlag.isEnabled()) {
209-
final XContentBuilder fieldMapping = fieldMapping(
210-
b -> b.field("type", "semantic_text").field(SEARCH_INFERENCE_ID_FIELD, searchInferenceId)
211-
);
212-
final MapperService mapperService = createMapperService(fieldMapping);
213-
assertSemanticTextField(mapperService, fieldName, false);
214-
assertInferenceEndpoints(mapperService, fieldName, DEFAULT_ELSER_2_INFERENCE_ID, searchInferenceId);
215-
assertSerialization.accept(fieldMapping, mapperService);
216-
}
202+
final XContentBuilder fieldMapping = fieldMapping(
203+
b -> b.field("type", "semantic_text").field(SEARCH_INFERENCE_ID_FIELD, searchInferenceId)
204+
);
205+
final MapperService mapperService = createMapperService(fieldMapping);
206+
assertSemanticTextField(mapperService, fieldName, false);
207+
assertInferenceEndpoints(mapperService, fieldName, DEFAULT_ELSER_2_INFERENCE_ID, searchInferenceId);
208+
assertSerialization.accept(fieldMapping, mapperService);
217209
}
218210
{
219211
final XContentBuilder fieldMapping = fieldMapping(
@@ -240,26 +232,18 @@ public void testInvalidInferenceEndpoints() {
240232
);
241233
}
242234
{
243-
final String expectedMessage = DefaultElserFeatureFlag.isEnabled()
244-
? "[inference_id] on mapper [field] of type [semantic_text] must not be empty"
245-
: "[inference_id] on mapper [field] of type [semantic_text] must be specified";
246235
Exception e = expectThrows(
247236
MapperParsingException.class,
248237
() -> createMapperService(fieldMapping(b -> b.field("type", "semantic_text").field(INFERENCE_ID_FIELD, "")))
249238
);
250-
assertThat(e.getMessage(), containsString(expectedMessage));
239+
assertThat(e.getMessage(), containsString("[inference_id] on mapper [field] of type [semantic_text] must not be empty"));
251240
}
252241
{
253-
if (DefaultElserFeatureFlag.isEnabled()) {
254-
Exception e = expectThrows(
255-
MapperParsingException.class,
256-
() -> createMapperService(fieldMapping(b -> b.field("type", "semantic_text").field(SEARCH_INFERENCE_ID_FIELD, "")))
257-
);
258-
assertThat(
259-
e.getMessage(),
260-
containsString("[search_inference_id] on mapper [field] of type [semantic_text] must not be empty")
261-
);
262-
}
242+
Exception e = expectThrows(
243+
MapperParsingException.class,
244+
() -> createMapperService(fieldMapping(b -> b.field("type", "semantic_text").field(SEARCH_INFERENCE_ID_FIELD, "")))
245+
);
246+
assertThat(e.getMessage(), containsString("[search_inference_id] on mapper [field] of type [semantic_text] must not be empty"));
263247
}
264248
}
265249

0 commit comments

Comments
 (0)