Skip to content

Commit e9b092d

Browse files
Strip linux suffix from model_id for default stats
1 parent bb96040 commit e9b092d

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,20 @@ private static Map<String, List<InferenceFieldMetadata>> filterFields(
232232

233233
private record DefaultModelStatsKey(String service, TaskType taskType, String modelId) {
234234

235+
// Some of the default models have optimized variants for linux that will have the following suffix.
236+
private static final String MODEL_ID_LINUX_SUFFIX = "-x86_64";
237+
235238
@Override
236239
public String toString() {
237240
// Inference ids cannot start with '_'. Thus, default stats do to avoid conflicts with user-defined inference ids.
238-
return "_" + service + "_" + modelId.replace('.', '_');
241+
return "_" + service + "_" + stripLinuxSuffix(modelId).replace('.', '_');
242+
}
243+
244+
private static String stripLinuxSuffix(String modelId) {
245+
if (modelId.endsWith(MODEL_ID_LINUX_SUFFIX)) {
246+
return modelId.substring(0, modelId.length() - MODEL_ID_LINUX_SUFFIX.length());
247+
}
248+
return modelId;
239249
}
240250
}
241251

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/action/TransportInferenceUsageActionTests.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,39 @@ public void testGivenServices_SemanticTextFieldsDefaultModels() throws Exception
220220
assertStats(response, 8, new ModelStats("openai", TaskType.TEXT_EMBEDDING, 1, new SemanticTextStats()));
221221
}
222222

223+
public void testGivenDefaultModelWithLinuxSuffix() throws Exception {
224+
givenInferenceEndpoints(
225+
new ModelConfigurations(".endpoint-001", TaskType.TEXT_EMBEDDING, "eis", mockServiceSettings(".model-id-001-x86_64")),
226+
new ModelConfigurations("endpoint-002", TaskType.TEXT_EMBEDDING, "eis", mockServiceSettings(".model-id-001-x86_64"))
227+
);
228+
229+
givenDefaultEndpoints(".endpoint-001");
230+
231+
givenInferenceFields(
232+
Map.of(
233+
"index_1",
234+
List.of(
235+
new InferenceFieldMetadata("semantic-1", ".endpoint-001", new String[0], null),
236+
new InferenceFieldMetadata("semantic-2", ".endpoint-001", new String[0], null),
237+
new InferenceFieldMetadata("semantic-3", "endpoint-002", new String[0], null)
238+
),
239+
"index_2",
240+
List.of(
241+
new InferenceFieldMetadata("semantic-1", ".endpoint-001", new String[0], null),
242+
new InferenceFieldMetadata("semantic-2", ".endpoint-001", new String[0], null),
243+
new InferenceFieldMetadata("semantic-3", "endpoint-002", new String[0], null)
244+
)
245+
)
246+
);
247+
248+
XContentSource response = executeAction();
249+
250+
assertThat(response.getValue("models"), hasSize(3));
251+
assertStats(response, 0, new ModelStats("_all", TaskType.TEXT_EMBEDDING, 2, new SemanticTextStats(6, 2, 2)));
252+
assertStats(response, 1, new ModelStats("_eis__model-id-001", TaskType.TEXT_EMBEDDING, 2, new SemanticTextStats(6, 2, 2)));
253+
assertStats(response, 2, new ModelStats("eis", TaskType.TEXT_EMBEDDING, 2, new SemanticTextStats(6, 2, 2)));
254+
}
255+
223256
public void testGivenExternalServiceModelIsNull() throws Exception {
224257
givenInferenceEndpoints(new ModelConfigurations("endpoint-001", TaskType.TEXT_EMBEDDING, "openai", mockServiceSettings(null)));
225258
givenInferenceFields(Map.of("index_1", List.of(new InferenceFieldMetadata("semantic", "endpoint-001", new String[0], null))));

0 commit comments

Comments
 (0)