Add validation to service settings update method#140082
Add validation to service settings update method#140082Jan-Kazlouski-elastic wants to merge 53 commits intoelastic:mainfrom
Conversation
…gs-update-method' into add-validation-to-service-settings-update-method
|
Pinging @elastic/search-inference-team (Team:Search - Inference) |
…vice-settings-update-method # Conflicts: # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/contextualai/rerank/ContextualAiRerankServiceSettings.java # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/jinaai/JinaAIServiceSettings.java # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/voyageai/VoyageAIServiceSettings.java
…atCompletionServiceSettings
…ttings in ServiceSettings
…p implementations
…gs-update-method' into add-validation-to-service-settings-update-method
…vice-settings-update-method # Conflicts: # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/TransportUpdateInferenceModelAction.java # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/deepseek/DeepSeekChatCompletionModel.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/ai21/completion/Ai21ChatCompletionServiceSettingsTests.java
…c and Amazon Bedrock services
…gs-update-method' into add-validation-to-service-settings-update-method
…ns and user-set flags
…vice-settings-update-method
…vice-settings-update-method
DonalEvans
left a comment
There was a problem hiding this comment.
I got a little way into reviewing this and realized that my comment about only allowing certain fields to be updated will require extensive changes, so I'm submitting this review before looking at all of the other files to allow you to make a start on the changes.
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/inference/ModelTests.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/inference/ModelTests.java
Outdated
Show resolved
Hide resolved
...lasticsearch/xpack/inference/services/ai21/completion/Ai21ChatCompletionServiceSettings.java
Show resolved
Hide resolved
| @@ -177,7 +177,7 @@ protected void masterOperation( | |||
| }) | |||
| .<ModelConfigurations>andThen((listener, didUpdate) -> { | |||
There was a problem hiding this comment.
I should have thought of this when reviewing the earlier PR, but do you think it would be worthwhile to put in a check after line 166 in this file that if the merged model is equal to the parsed model, then we return early? If the update is a no-op then we don't need to do the extra work of performing a validation call or updating the indices.
There was a problem hiding this comment.
Stakes of actually performing the validation and update on not updated model are higher than in case described in your previous comment and I agree that we should return early. Specially considering the fact it is so easy to implement.
...ticsearch/xpack/inference/services/alibabacloudsearch/AlibabaCloudSearchServiceSettings.java
Outdated
Show resolved
Hide resolved
...pack/inference/services/amazonbedrock/embeddings/AmazonBedrockEmbeddingsServiceSettings.java
Outdated
Show resolved
Hide resolved
...pack/inference/services/amazonbedrock/embeddings/AmazonBedrockEmbeddingsServiceSettings.java
Show resolved
Hide resolved
| var extractedModelId = extractOptionalString( | ||
| serviceSettings, | ||
| ServiceFields.MODEL_ID, | ||
| ModelConfigurations.SERVICE_SETTINGS, | ||
| validationException | ||
| ); |
There was a problem hiding this comment.
I don't think we want to allow modelId to be updated. I don't think there's really a valid use case for changing the model associated with an endpoint, since doing so will cause the behaviour of the endpoint to change, and the InferenceServiceConfiguration in Ai21Service lists it as not updatable:
configurationMap.put(
ServiceFields.MODEL_ID,
new SettingsConfiguration.Builder(SUPPORTED_TASK_TYPES).setDescription(
"Refer to the AI21 models documentation for the list of available inference models."
)
.setLabel("Model")
.setRequired(true)
.setSensitive(false)
.setUpdatable(false)
.setType(SettingsConfigurationFieldType.STRING)
.build()
);
This comment applies to many other service settings fields, in particular ones for similarity, dimensions and embedding type for dense embedding service settings. I think we need to consider each service setting field carefully when deciding whether to allow it to be updated. The InferenceServiceConfiguration for a given service may be incomplete or incorrect, so I'm not sure it's safe to just go by what those say.
There was a problem hiding this comment.
Good catch on the updatable flag. I completely missed that. You’re right that it needs to be set appropriately for any setting we intend to allow updates on.
Historically it was set to false across the board because updateServiceSettings effectively didn’t support updates for most services (it was returning this in the majority of cases). This PR changes that behavior and makes updates possible, which is why these flags now matter. InferenceServiceConfigurations are often incomplete and incorrect and I, as an author of Ai21 chat integration didn't mean that model must be immutable.
I don't think we want to allow modelId to be updated.
doing so will cause the behaviour of the endpoint to change
I respectfully disagree here. Changing the modelId will indeed change the behavior of the endpoint. That’s inherently true for any configuration change that points to a different underlying model. Conceptually, updating modelId would mean swapping the provider endpoint model within the same elastic endpoint, which seems like a reasonable and potentially useful operation for customers.
As long as the updated configuration results in a valid and functional underlying endpoint, I don’t think we should artificially restrict this capability on our side. The behavior change is explicit and intentional from the user’s perspective.
There was a problem hiding this comment.
The reason we don't want to allow all fields to be updatable is that users can easily break their system. For example if a user ingests some documents with model_id_a and then changes it to model_id_b and ingests more documents, the embeddings could be incompatible. For chat completion and other task types it's not quite as bad but I still think we should consider some fields as immutable. If the user wants to use a different one, then they can create a new endpoint to do that.
Generally most things within service_settings probably shouldn't be updatable. Like Donal mentioned, we shouldn't allow updates for these fields in particular but there are probably more:
similarity
dimensions
embedding type
model id
There was a problem hiding this comment.
Understood. Will make the changes making those fields immutable post-creation.
There was a problem hiding this comment.
Here's the PR where model ID is immutable:
#142597
…vice-settings-update-method
…vice-settings-update-method # Conflicts: # server/src/test/java/org/elasticsearch/inference/MinimalServiceSettingsTests.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elasticsearch/ElasticsearchInternalServiceSettingsTests.java
This PR is related to: #122356
Currently Service Settings
updateServiceSettingsmethod that is called during endpoint update operation is implemented only forGoogleVertexAiEmbeddingsServiceSettingsandElasticsearchInternalServiceSettings. This PR introduces implementations for some part ofServiceSettingsclasses while keeping default implementation inServiceSettingsinterface returning unchangedthisinstance. This is done to unlock update functionality the inference services.CustomServiceSettings require
taskTypeparameter so it was added to the method signature.updateServiceSettingsmethod kept the same for:MinimalServiceSettingsSageMakerStoredServiceSchema'sNO_OPimplementationI ask for reviewer's attention to this.
Some refactoring was also done both to
ServiceSettingsclasses and test classes.Issue with treating update operation as operation done only with PERSISTENT context is fixed by using REQUEST context in Service classes.
gradle check?