Skip to content

Commit 6425c61

Browse files
Bugfix by moving onResponse call into the new action listener; also add new test to catch this bug (#113898)
1 parent bcc5caf commit 6425c61

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elser/ElserInternalService.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,16 @@ public void parseRequestConfig(
101101
serviceSettingsBuilder.setModelId(
102102
selectDefaultModelVariantBasedOnClusterArchitecture(arch, ELSER_V2_MODEL_LINUX_X86, ELSER_V2_MODEL)
103103
);
104+
parsedModelListener.onResponse(
105+
new ElserInternalModel(
106+
inferenceEntityId,
107+
taskType,
108+
NAME,
109+
new ElserInternalServiceSettings(serviceSettingsBuilder.build()),
110+
taskSettings
111+
)
112+
);
104113
}));
105-
106-
parsedModelListener.onResponse(
107-
new ElserInternalModel(
108-
inferenceEntityId,
109-
taskType,
110-
NAME,
111-
new ElserInternalServiceSettings(serviceSettingsBuilder.build()),
112-
taskSettings
113-
)
114-
);
115114
} else {
116115
parsedModelListener.onResponse(
117116
new ElserInternalModel(

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elser/ElserInternalServiceTests.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,31 @@ public void testParseConfigStrict() {
120120

121121
}
122122

123+
public void testParseConfigWithoutModelId() {
124+
Client mockClient = mock(Client.class);
125+
when(mockClient.threadPool()).thenReturn(threadPool);
126+
var service = createService(mockClient);
127+
128+
var settings = new HashMap<String, Object>();
129+
settings.put(
130+
ModelConfigurations.SERVICE_SETTINGS,
131+
new HashMap<>(Map.of(ElserInternalServiceSettings.NUM_ALLOCATIONS, 1, ElserInternalServiceSettings.NUM_THREADS, 4))
132+
);
133+
134+
var expectedModel = new ElserInternalModel(
135+
"foo",
136+
TaskType.SPARSE_EMBEDDING,
137+
ElserInternalService.NAME,
138+
new ElserInternalServiceSettings(1, 4, ".elser_model_2", null),
139+
ElserMlNodeTaskSettings.DEFAULT
140+
);
141+
142+
var modelVerificationListener = getModelVerificationListener(expectedModel);
143+
144+
service.parseRequestConfig("foo", TaskType.SPARSE_EMBEDDING, settings, modelVerificationListener);
145+
146+
}
147+
123148
public void testParseConfigLooseWithOldModelId() {
124149
var service = createService(mock(Client.class));
125150

0 commit comments

Comments
 (0)