Skip to content

Commit 13792bd

Browse files
Revert endpoint creation validation for ELSER and E5
1 parent 31bb3d1 commit 13792bd

File tree

3 files changed

+214
-142
lines changed

3 files changed

+214
-142
lines changed

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/validation/ElasticsearchInternalServiceModelValidator.java

Lines changed: 70 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,91 @@
99

1010
import org.elasticsearch.ElasticsearchStatusException;
1111
import org.elasticsearch.action.ActionListener;
12+
import org.elasticsearch.common.Strings;
1213
import org.elasticsearch.core.TimeValue;
1314
import org.elasticsearch.inference.InferenceService;
15+
import org.elasticsearch.inference.InferenceServiceResults;
1416
import org.elasticsearch.inference.Model;
17+
import org.elasticsearch.inference.TaskType;
1518
import org.elasticsearch.rest.RestStatus;
19+
import org.elasticsearch.xpack.core.inference.results.TextEmbeddingFloatResults;
20+
import org.elasticsearch.xpack.core.inference.results.TextEmbeddingResults;
21+
import org.elasticsearch.xpack.inference.services.elasticsearch.CustomElandEmbeddingModel;
1622

1723
public class ElasticsearchInternalServiceModelValidator implements ModelValidator {
1824

19-
ModelValidator modelValidator;
25+
private final ServiceIntegrationValidator serviceIntegrationValidator;
2026

21-
public ElasticsearchInternalServiceModelValidator(ModelValidator modelValidator) {
22-
this.modelValidator = modelValidator;
27+
public ElasticsearchInternalServiceModelValidator(ServiceIntegrationValidator serviceIntegrationValidator) {
28+
this.serviceIntegrationValidator = serviceIntegrationValidator;
2329
}
2430

2531
@Override
2632
public void validate(InferenceService service, Model model, TimeValue timeout, ActionListener<Model> listener) {
27-
service.start(model, timeout, ActionListener.wrap((modelDeploymentStarted) -> {
28-
if (modelDeploymentStarted) {
29-
try {
30-
modelValidator.validate(service, model, timeout, listener.delegateResponse((l, exception) -> {
31-
stopModelDeployment(service, model, l, exception);
32-
}));
33-
} catch (Exception e) {
34-
stopModelDeployment(service, model, listener, e);
35-
}
36-
} else {
37-
listener.onFailure(
38-
new ElasticsearchStatusException("Could not deploy model for inference endpoint", RestStatus.INTERNAL_SERVER_ERROR)
33+
if (model instanceof CustomElandEmbeddingModel elandModel && elandModel.getTaskType() == TaskType.TEXT_EMBEDDING) {
34+
var temporaryModelWithModelId = new CustomElandEmbeddingModel(
35+
elandModel.getServiceSettings().modelId(),
36+
elandModel.getTaskType(),
37+
elandModel.getConfigurations().getService(),
38+
elandModel.getServiceSettings(),
39+
elandModel.getConfigurations().getChunkingSettings()
40+
);
41+
42+
serviceIntegrationValidator.validate(
43+
service,
44+
temporaryModelWithModelId,
45+
timeout,
46+
listener.delegateFailureAndWrap((delegate, r) -> {
47+
delegate.onResponse(postValidate(service, model, r));
48+
})
49+
);
50+
} else {
51+
listener.onResponse(model);
52+
}
53+
}
54+
55+
private Model postValidate(InferenceService service, Model model, InferenceServiceResults results) {
56+
if (results instanceof TextEmbeddingResults<?> embeddingResults) {
57+
var serviceSettings = model.getServiceSettings();
58+
var dimensions = serviceSettings.dimensions();
59+
int embeddingSize = getEmbeddingSize(embeddingResults);
60+
61+
if (Boolean.TRUE.equals(serviceSettings.dimensionsSetByUser())
62+
&& dimensions != null
63+
&& (dimensions.equals(embeddingSize) == false)) {
64+
throw new ElasticsearchStatusException(
65+
Strings.format(
66+
"The retrieved embeddings size [%s] does not match the size specified in the settings [%s]. "
67+
+ "Please recreate the [%s] configuration with the correct dimensions",
68+
embeddingResults.getFirstEmbeddingSize(),
69+
serviceSettings.dimensions(),
70+
model.getInferenceEntityId()
71+
),
72+
RestStatus.BAD_REQUEST
3973
);
4074
}
41-
}, listener::onFailure));
75+
76+
return service.updateModelWithEmbeddingDetails(model, embeddingSize);
77+
} else {
78+
throw new ElasticsearchStatusException(
79+
"Validation call did not return expected results type."
80+
+ "Expected a result of type ["
81+
+ TextEmbeddingFloatResults.NAME
82+
+ "] got ["
83+
+ (results == null ? "null" : results.getWriteableName())
84+
+ "]",
85+
RestStatus.BAD_REQUEST
86+
);
87+
}
4288
}
4389

44-
private void stopModelDeployment(InferenceService service, Model model, ActionListener<Model> listener, Exception e) {
45-
service.stop(
46-
model,
47-
ActionListener.wrap(
48-
(v) -> listener.onFailure(e),
49-
(ex) -> listener.onFailure(
50-
new ElasticsearchStatusException(
51-
"Model validation failed and model deployment could not be stopped",
52-
RestStatus.INTERNAL_SERVER_ERROR,
53-
ex
54-
)
55-
)
56-
)
57-
);
90+
private int getEmbeddingSize(TextEmbeddingResults<?> embeddingResults) {
91+
int embeddingSize;
92+
try {
93+
embeddingSize = embeddingResults.getFirstEmbeddingSize();
94+
} catch (Exception e) {
95+
throw new ElasticsearchStatusException("Could not determine embedding size", RestStatus.BAD_REQUEST, e);
96+
}
97+
return embeddingSize;
5898
}
5999
}

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/validation/ModelValidatorBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212

1313
public class ModelValidatorBuilder {
1414
public static ModelValidator buildModelValidator(TaskType taskType, boolean isElasticsearchInternalService) {
15-
var modelValidator = buildModelValidatorForTaskType(taskType);
1615
if (isElasticsearchInternalService) {
17-
return new ElasticsearchInternalServiceModelValidator(modelValidator);
16+
return new ElasticsearchInternalServiceModelValidator(new SimpleServiceIntegrationValidator());
1817
} else {
19-
return modelValidator;
18+
return buildModelValidatorForTaskType(taskType);
2019
}
2120
}
2221

0 commit comments

Comments
 (0)