Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
328d079
Defaulting EIS on ELSER
mridula-s109 Sep 15, 2025
0b89373
Extended testing
mridula-s109 Sep 15, 2025
1cc9fd4
[CI] Auto commit changes from spotless
Sep 15, 2025
0829058
Merge branch 'main' into default_elser_on_eis_semantic
mridula-s109 Sep 17, 2025
7dcd31f
Edited to include the default
mridula-s109 Sep 17, 2025
f19972e
Cleaned up the mapper implementation
mridula-s109 Sep 17, 2025
3d58a50
COmpile issue
mridula-s109 Sep 17, 2025
394bf99
[CI] Auto commit changes from spotless
Sep 17, 2025
213aa24
Merge branch 'main' into default_elser_on_eis_semantic
mridula-s109 Sep 25, 2025
c92d2b3
Added tests
mridula-s109 Sep 30, 2025
1301a43
[CI] Auto commit changes from spotless
Sep 30, 2025
6ecdb6c
Merge branch 'main' into default_elser_on_eis_semantic
mridula-s109 Oct 1, 2025
9f662ce
Refactored the variable names
mridula-s109 Oct 2, 2025
904a242
Cleanup done
mridula-s109 Oct 2, 2025
6355bed
Removed unnecessary files
mridula-s109 Oct 2, 2025
b4ed763
Unit tests and mock is working
mridula-s109 Oct 3, 2025
4f0d7c0
[CI] Auto commit changes from spotless
Oct 3, 2025
4680417
Merge branch 'main' into default_elser_on_eis_semantic
mridula-s109 Oct 3, 2025
18f38b8
Fix test
mridula-s109 Oct 3, 2025
cc2e978
yaml addition failure
mridula-s109 Oct 3, 2025
33f4eaa
[CI] Auto commit changes from spotless
Oct 3, 2025
6ef7543
Resolved the import issue or duplication of variables in mock
mridula-s109 Oct 6, 2025
7733cfe
Resolved PR comments
mridula-s109 Oct 7, 2025
70a80a4
Restored error
mridula-s109 Oct 7, 2025
9564444
Update docs/changelog/134708.yaml
mridula-s109 Oct 7, 2025
0a678ed
Integration test
mridula-s109 Oct 8, 2025
d23256b
[CI] Auto commit changes from spotless
Oct 8, 2025
f0fc256
Merge branch 'main' into default_elser_on_eis_semantic
mridula-s109 Oct 8, 2025
0edfb91
Resolved all PR comments
mridula-s109 Oct 14, 2025
f3c0da5
Merge branch 'main' into default_elser_on_eis_semantic
mridula-s109 Oct 14, 2025
dd765ae
[CI] Auto commit changes from spotless
Oct 14, 2025
5d932ef
Merge branch 'main' into default_elser_on_eis_semantic
mridula-s109 Oct 14, 2025
536d326
Cleaned up the redudant reference of TestInferencePlugin
mridula-s109 Oct 17, 2025
cd98727
Included both before and before test
mridula-s109 Oct 17, 2025
cf797e4
[CI] Auto commit changes from spotless
Oct 17, 2025
9e50bdc
Merge branch 'main' into default_elser_on_eis_semantic
mridula-s109 Oct 17, 2025
d5c4841
Merge branch 'main' into default_elser_on_eis_semantic
mridula-s109 Oct 27, 2025
f059474
Made changes to accomodate the old constant version string
mridula-s109 Oct 29, 2025
bc7a73a
Merge branch 'main' into default_elser_on_eis_semantic
mridula-s109 Oct 29, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
import static org.elasticsearch.inference.TaskType.TEXT_EMBEDDING;
import static org.elasticsearch.lucene.search.uhighlight.CustomUnifiedHighlighter.MULTIVAL_SEP_CHAR;
import static org.elasticsearch.search.SearchService.DEFAULT_SIZE;
import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceService.DEFAULT_ELSER_ENDPOINT_ID_V2;
import static org.elasticsearch.xpack.inference.mapper.SemanticTextField.CHUNKED_EMBEDDINGS_FIELD;
import static org.elasticsearch.xpack.inference.mapper.SemanticTextField.CHUNKED_OFFSET_FIELD;
import static org.elasticsearch.xpack.inference.mapper.SemanticTextField.CHUNKING_SETTINGS_FIELD;
Expand Down Expand Up @@ -153,9 +154,22 @@ public class SemanticTextFieldMapper extends FieldMapper implements InferenceFie

public static final String CONTENT_TYPE = "semantic_text";
public static final String DEFAULT_ELSER_2_INFERENCE_ID = DEFAULT_ELSER_ID;
private static final String EIS_ELSER_INFERENCE_ID = DEFAULT_ELSER_ENDPOINT_ID_V2;

public static final float DEFAULT_RESCORE_OVERSAMPLE = 3.0f;

/**
* Determines the preferred ELSER inference ID based on EIS availability.
* Returns .elser-2-elastic (EIS) when available, otherwise falls back to .elser-2-elasticsearch (ML nodes).
* This enables automatic selection of EIS for better performance while maintaining compatibility with on-prem deployments.
*/
private static String getPreferredElserInferenceId(ModelRegistry modelRegistry) {
if (modelRegistry != null && modelRegistry.containsDefaultConfigId(EIS_ELSER_INFERENCE_ID)) {
return EIS_ELSER_INFERENCE_ID;
}
return DEFAULT_ELSER_ID;
}

static final String INDEX_OPTIONS_FIELD = "index_options";

public static final TypeParser parser(Supplier<ModelRegistry> modelRegistry) {
Expand Down Expand Up @@ -242,7 +256,7 @@ public Builder(
INFERENCE_ID_FIELD,
false,
mapper -> ((SemanticTextFieldType) mapper.fieldType()).inferenceId,
DEFAULT_ELSER_2_INFERENCE_ID
getPreferredElserInferenceId(modelRegistry)
).addValidator(v -> {
if (Strings.isEmpty(v)) {
throw new IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public class ElasticInferenceService extends SenderService {

// elser-2
static final String DEFAULT_ELSER_2_MODEL_ID = "elser_model_2";
static final String DEFAULT_ELSER_ENDPOINT_ID_V2 = defaultEndpointId("elser-2");
public static final String DEFAULT_ELSER_ENDPOINT_ID_V2 = defaultEndpointId("elser-2");

// multilingual-text-embed
static final String DEFAULT_MULTILINGUAL_EMBED_MODEL_ID = "multilingual-embed-v1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,44 @@ public void testDefaults() throws Exception {
assertTrue(fields.isEmpty());
}

public void testDynamicElserDefaultSelection() throws Exception {
final String fieldName = "field";
final XContentBuilder fieldMapping = fieldMapping(this::minimalMapping);

// Test 1: When EIS is available, should default to .elser-2-elastic
when(globalModelRegistry.containsDefaultConfigId(".elser-2-elastic")).thenReturn(true);
MapperService mapperServiceWithEis = createMapperService(fieldMapping, useLegacyFormat);
assertInferenceEndpoints(mapperServiceWithEis, fieldName, ".elser-2-elastic", ".elser-2-elastic");

// Test 2: When EIS is not available, should fallback to .elser-2-elasticsearch
when(globalModelRegistry.containsDefaultConfigId(".elser-2-elastic")).thenReturn(false);
MapperService mapperServiceWithoutEis = createMapperService(fieldMapping, useLegacyFormat);
assertInferenceEndpoints(mapperServiceWithoutEis, fieldName, DEFAULT_ELSER_2_INFERENCE_ID, DEFAULT_ELSER_2_INFERENCE_ID);
}

public void testDynamicElserDefaultSelectionEdgeCases() throws Exception {
final String fieldName = "field";
final XContentBuilder fieldMapping = fieldMapping(this::minimalMapping);

// Test: ModelRegistry throws exception - should fallback gracefully
when(globalModelRegistry.containsDefaultConfigId(".elser-2-elastic")).thenThrow(new RuntimeException("Registry error"));
MapperService mapperServiceWithError = createMapperService(fieldMapping, useLegacyFormat);
assertInferenceEndpoints(mapperServiceWithError, fieldName, DEFAULT_ELSER_2_INFERENCE_ID, DEFAULT_ELSER_2_INFERENCE_ID);
}

public void testExplicitInferenceIdOverridesDynamicSelection() throws Exception {
final String fieldName = "field";
final String explicitInferenceId = "my-custom-model";
final XContentBuilder fieldMapping = fieldMapping(
b -> b.field("type", "semantic_text").field(INFERENCE_ID_FIELD, explicitInferenceId)
);

// Even when EIS is available, explicit inference_id should take precedence
when(globalModelRegistry.containsDefaultConfigId(".elser-2-elastic")).thenReturn(true);
MapperService mapperService = createMapperService(fieldMapping, useLegacyFormat);
assertInferenceEndpoints(mapperService, fieldName, explicitInferenceId, explicitInferenceId);
}

@Override
public void testFieldHasValue() {
MappedFieldType fieldType = getMappedFieldType();
Expand Down