Skip to content

[ML] Remove mention of models in inference actions #107704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 1, 2024
Merged
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"inference.delete_model":{
"inference.delete":{
"documentation":{
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/delete-inference-api.html",
"description":"Delete model in the Inference API"
"description":"Delete and inference endpoint"
},
"stability":"experimental",
"visibility":"public",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"inference.get_model":{
"inference.get":{
"documentation":{
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/get-inference-api.html",
"description":"Get a model in the Inference API"
"description":"Get an inference endpoint"
},
"stability":"experimental",
"visibility":"public",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"inference.inference":{
"documentation":{
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/post-inference-api.html",
"description":"Perform inference on a model"
"description":"Perform inference"
},
"stability":"experimental",
"visibility":"public",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"inference.put_model":{
"inference.put":{
"documentation":{
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/put-inference-api.html",
"description":"Configure a model for use in the Inference API"
"description":"Configure an inference endpoint for use in the Inference API"
},
"stability":"experimental",
"visibility":"public",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void writeTo(StreamOutput out) throws IOException {
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.startArray("models");
builder.startArray("endpoints");
for (var model : models) {
if (model != null) {
model.toFilteredXContent(builder, params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void testStoreModelWithUnknownFields() throws Exception {
statusException.getRootCause().getMessage(),
containsString("mapping set to strict, dynamic introduction of [unknown_field] within [_doc] is not allowed")
);
assertThat(exceptionHolder.get().getMessage(), containsString("Failed to store inference model [" + inferenceEntityId + "]"));
assertThat(exceptionHolder.get().getMessage(), containsString("Failed to store inference endpoint [" + inferenceEntityId + "]"));
}

public void testGetModel() throws Exception {
Expand Down Expand Up @@ -144,7 +144,7 @@ public void testStoreModelFailsWhenModelExists() throws Exception {
assertThat(exceptionHolder.get(), not(nullValue()));
assertThat(
exceptionHolder.get().getMessage(),
containsString("Inference model [test-put-trained-model-config-exists] already exists")
containsString("Inference endpoint [test-put-trained-model-config-exists] already exists")
);
}

Expand All @@ -171,7 +171,7 @@ public void testDeleteModel() throws Exception {

assertThat(exceptionHolder.get(), not(nullValue()));
assertFalse(deleteResponseHolder.get());
assertThat(exceptionHolder.get().getMessage(), containsString("Model not found [model1]"));
assertThat(exceptionHolder.get().getMessage(), containsString("Inference endpoint not found [model1]"));
}

public void testGetModelsByTaskType() throws InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,14 @@ private void getSingleModel(
modelRegistry.getModel(inferenceEntityId, listener.delegateFailureAndWrap((delegate, unparsedModel) -> {
var service = serviceRegistry.getService(unparsedModel.service());
if (service.isEmpty()) {
delegate.onFailure(
new ElasticsearchStatusException(
"Unknown service [{}] for model [{}]. ",
RestStatus.INTERNAL_SERVER_ERROR,
unparsedModel.service(),
unparsedModel.inferenceEntityId()
)
);
delegate.onFailure(serviceNotFoundException(unparsedModel.service(), unparsedModel.inferenceEntityId()));
return;
}

if (requestedTaskType.isAnyOrSame(unparsedModel.taskType()) == false) {
delegate.onFailure(
new ElasticsearchStatusException(
"Requested task type [{}] does not match the model's task type [{}]",
"Requested task type [{}] does not match the inference endpoint's task type [{}]",
RestStatus.BAD_REQUEST,
requestedTaskType,
unparsedModel.taskType()
Expand Down Expand Up @@ -131,12 +124,7 @@ private GetInferenceModelAction.Response parseModels(List<ModelRegistry.Unparsed
for (var unparsedModel : unparsedModels) {
var service = serviceRegistry.getService(unparsedModel.service());
if (service.isEmpty()) {
throw new ElasticsearchStatusException(
"Unknown service [{}] for model [{}]. ",
RestStatus.INTERNAL_SERVER_ERROR,
unparsedModel.service(),
unparsedModel.inferenceEntityId()
);
throw serviceNotFoundException(unparsedModel.service(), unparsedModel.inferenceEntityId());
}
parsedModels.add(
service.get()
Expand All @@ -146,4 +134,13 @@ private GetInferenceModelAction.Response parseModels(List<ModelRegistry.Unparsed
}
return new GetInferenceModelAction.Response(parsedModels);
}

private ElasticsearchStatusException serviceNotFoundException(String service, String inferenceId) {
throw new ElasticsearchStatusException(
"Unknown service [{}] for inference endpoint [{}]. ",
RestStatus.INTERNAL_SERVER_ERROR,
service,
inferenceId
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected void masterOperation(
if (serviceName == null) {
listener.onFailure(
new ElasticsearchStatusException(
"Model configuration is missing [" + ModelConfigurations.SERVICE + "]",
"Inference endpoint configuration is missing the [" + ModelConfigurations.SERVICE + "] setting",
RestStatus.BAD_REQUEST
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void getModelWithSecrets(String inferenceEntityId, ActionListener<Unparse
ActionListener<SearchResponse> searchListener = listener.delegateFailureAndWrap((delegate, searchResponse) -> {
// There should be a hit for the configurations and secrets
if (searchResponse.getHits().getHits().length == 0) {
delegate.onFailure(new ResourceNotFoundException("Model not found [{}]", inferenceEntityId));
delegate.onFailure(inferenceNotFoundException(inferenceEntityId));
return;
}

Expand All @@ -128,7 +128,7 @@ public void getModel(String inferenceEntityId, ActionListener<UnparsedModel> lis
ActionListener<SearchResponse> searchListener = listener.delegateFailureAndWrap((delegate, searchResponse) -> {
// There should be a hit for the configurations and secrets
if (searchResponse.getHits().getHits().length == 0) {
delegate.onFailure(new ResourceNotFoundException("Model not found [{}]", inferenceEntityId));
delegate.onFailure(inferenceNotFoundException(inferenceEntityId));
return;
}

Expand All @@ -147,6 +147,10 @@ public void getModel(String inferenceEntityId, ActionListener<UnparsedModel> lis
client.search(modelSearch, searchListener);
}

private ResourceNotFoundException inferenceNotFoundException(String inferenceEntityId) {
return new ResourceNotFoundException("Inference endpoint not found [{}]", inferenceEntityId);
}

/**
* Get all models of a particular task type.
* Secret settings are not included
Expand Down Expand Up @@ -227,10 +231,10 @@ private ModelConfigMap createModelConfigMap(SearchHits hits, String inferenceEnt
return InferenceSecretsIndex.INDEX_NAME;
}

logger.warn(format("Found invalid index for model [%s] at index [%s]", inferenceEntityId, hit.getIndex()));
logger.warn(format("Found invalid index for inference endpoint [%s] at index [%s]", inferenceEntityId, hit.getIndex()));
throw new IllegalArgumentException(
format(
"Invalid result while loading model [%s] index: [%s]. Try deleting and reinitializing the service",
"Invalid result while loading inference endpoint [%s] index: [%s]. Try deleting and reinitializing the service",
inferenceEntityId,
hit.getIndex()
)
Expand All @@ -241,11 +245,15 @@ private ModelConfigMap createModelConfigMap(SearchHits hits, String inferenceEnt
|| mappedHits.containsKey(InferenceSecretsIndex.INDEX_NAME) == false
|| mappedHits.size() > 2) {
logger.warn(
format("Failed to load model [%s], found model parts from index prefixes: [%s]", inferenceEntityId, mappedHits.keySet())
format(
"Failed to load inference endpoint [%s], found endpoint parts from index prefixes: [%s]",
inferenceEntityId,
mappedHits.keySet()
)
);
throw new IllegalStateException(
format(
"Failed to load model, model [%s] is in an invalid state. Try deleting and reinitializing the service",
"Failed to load inference endpoint [%s]. Enpoint is in an invalid state try deleting and reinitializing the service",
inferenceEntityId
)
);
Expand Down Expand Up @@ -286,12 +294,14 @@ private static ActionListener<BulkResponse> getStoreModelListener(Model model, A
var inferenceEntityId = model.getConfigurations().getInferenceEntityId();

if (bulkItemResponses.getItems().length == 0) {
logger.warn(format("Storing model [%s] failed, no items were received from the bulk response", inferenceEntityId));
logger.warn(
format("Storing inference endpoint [%s] failed, no items were received from the bulk response", inferenceEntityId)
);

listener.onFailure(
new ElasticsearchStatusException(
format(
"Failed to store inference model [%s], invalid bulk response received. Try reinitializing the service",
"Failed to store inference endpoint [%s], invalid bulk response received. Try reinitializing the service",
inferenceEntityId
),
RestStatus.INTERNAL_SERVER_ERROR
Expand All @@ -310,19 +320,19 @@ private static ActionListener<BulkResponse> getStoreModelListener(Model model, A
logBulkFailures(model.getConfigurations().getInferenceEntityId(), bulkItemResponses);

if (ExceptionsHelper.unwrapCause(failure.getCause()) instanceof VersionConflictEngineException) {
listener.onFailure(new ResourceAlreadyExistsException("Inference model [{}] already exists", inferenceEntityId));
listener.onFailure(new ResourceAlreadyExistsException("Inference endpoint [{}] already exists", inferenceEntityId));
return;
}

listener.onFailure(
new ElasticsearchStatusException(
format("Failed to store inference model [%s]", inferenceEntityId),
format("Failed to store inference endpoint [%s]", inferenceEntityId),
RestStatus.INTERNAL_SERVER_ERROR,
failure.getCause()
)
);
}, e -> {
String errorMessage = format("Failed to store inference model [%s]", model.getConfigurations().getInferenceEntityId());
String errorMessage = format("Failed to store inference endpoint [%s]", model.getConfigurations().getInferenceEntityId());
logger.warn(errorMessage, e);
listener.onFailure(new ElasticsearchStatusException(errorMessage, RestStatus.INTERNAL_SERVER_ERROR, e));
});
Expand All @@ -333,7 +343,7 @@ private static void logBulkFailures(String inferenceEntityId, BulkResponse bulkR
if (item.isFailed()) {
logger.warn(
format(
"Failed to store inference model [%s] index: [%s] bulk failure message [%s]",
"Failed to store inference endpoint [%s] index: [%s] bulk failure message [%s]",
inferenceEntityId,
item.getIndex(),
item.getFailureMessage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void testGetUnparsedModelMap_ThrowsResourceNotFound_WhenNoHitsReturned()
registry.getModelWithSecrets("1", listener);

ResourceNotFoundException exception = expectThrows(ResourceNotFoundException.class, () -> listener.actionGet(TIMEOUT));
assertThat(exception.getMessage(), is("Model not found [1]"));
assertThat(exception.getMessage(), is("Inference endpoint not found [1]"));
}

public void testGetUnparsedModelMap_ThrowsIllegalArgumentException_WhenInvalidIndexReceived() {
Expand All @@ -88,7 +88,7 @@ public void testGetUnparsedModelMap_ThrowsIllegalArgumentException_WhenInvalidIn
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> listener.actionGet(TIMEOUT));
assertThat(
exception.getMessage(),
is("Invalid result while loading model [1] index: [unknown_index]. Try deleting and reinitializing the service")
is("Invalid result while loading inference endpoint [1] index: [unknown_index]. Try deleting and reinitializing the service")
);
}

Expand All @@ -105,7 +105,7 @@ public void testGetUnparsedModelMap_ThrowsIllegalStateException_WhenUnableToFind
IllegalStateException exception = expectThrows(IllegalStateException.class, () -> listener.actionGet(TIMEOUT));
assertThat(
exception.getMessage(),
is("Failed to load model, model [1] is in an invalid state. Try deleting and reinitializing the service")
is("Failed to load inference endpoint [1]. Enpoint is in an invalid state try deleting and reinitializing the service")
);
}

Expand All @@ -122,7 +122,7 @@ public void testGetUnparsedModelMap_ThrowsIllegalStateException_WhenUnableToFind
IllegalStateException exception = expectThrows(IllegalStateException.class, () -> listener.actionGet(TIMEOUT));
assertThat(
exception.getMessage(),
is("Failed to load model, model [1] is in an invalid state. Try deleting and reinitializing the service")
is("Failed to load inference endpoint [1]. Enpoint is in an invalid state try deleting and reinitializing the service")
);
}

Expand Down Expand Up @@ -229,7 +229,7 @@ public void testStoreModel_ThrowsException_WhenBulkResponseIsEmpty() {
exception.getMessage(),
is(
format(
"Failed to store inference model [%s], invalid bulk response received. Try reinitializing the service",
"Failed to store inference endpoint [%s], invalid bulk response received. Try reinitializing the service",
model.getConfigurations().getInferenceEntityId()
)
)
Expand Down Expand Up @@ -258,7 +258,7 @@ public void testStoreModel_ThrowsResourceAlreadyExistsException_WhenFailureIsAVe
ResourceAlreadyExistsException exception = expectThrows(ResourceAlreadyExistsException.class, () -> listener.actionGet(TIMEOUT));
assertThat(
exception.getMessage(),
is(format("Inference model [%s] already exists", model.getConfigurations().getInferenceEntityId()))
is(format("Inference endpoint [%s] already exists", model.getConfigurations().getInferenceEntityId()))
);
}

Expand All @@ -284,7 +284,7 @@ public void testStoreModel_ThrowsException_WhenFailureIsNotAVersionConflict() {
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class, () -> listener.actionGet(TIMEOUT));
assertThat(
exception.getMessage(),
is(format("Failed to store inference model [%s]", model.getConfigurations().getInferenceEntityId()))
is(format("Failed to store inference endpoint [%s]", model.getConfigurations().getInferenceEntityId()))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
"Test get missing model":
- do:
catch: missing
inference.get_model:
inference_id: model_to_get
inference.get:
inference_id: inference_to_get
- match: { error.type: "resource_not_found_exception" }
- match: { error.reason: "Model not found [model_to_get]" }
- match: { error.reason: "Inference endpoint not found [inference_to_get]" }

---
"Test put model with bad task type":
"Test put inference with bad task type":
- do:
catch: bad_request
inference.put_model:
inference.put:
inference_id: elser_model
body: >
{
Expand Down Expand Up @@ -42,17 +42,17 @@
---
"Test get all":
- do:
inference.get_model:
inference.get:
inference_id: "*"
- length: { models: 0}
- length: { endpoints: 0}

- do:
inference.get_model:
inference.get:
inference_id: _all
- length: { models: 0}
- length: { endpoints: 0}

- do:
inference.get_model:
inference.get:
inference_id: ""
- length: { models: 0}
- length: { endpoints: 0}