-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Add implementation to update service settings method for Alibaba Cloud Search service #142738
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
Changes from 3 commits
f8a936f
811808c
63e6195
1bf97b5
eb5f90a
7f4e317
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| pr: 142738 | ||
| summary: Added service settings update logic for Alibaba Cloud Search provider in the Inference Plugin | ||
| area: Inference | ||
| type: enhancement | ||
| issues: | ||
| - 122356 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,6 @@ | |
| package org.elasticsearch.xpack.inference.services.alibabacloudsearch.completion; | ||
|
|
||
| import org.elasticsearch.TransportVersion; | ||
| import org.elasticsearch.common.ValidationException; | ||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.inference.ServiceSettings; | ||
|
|
@@ -25,13 +24,7 @@ public class AlibabaCloudSearchCompletionServiceSettings implements ServiceSetti | |
| public static final String NAME = "alibabacloud_search_completion_service_settings"; | ||
|
|
||
| public static AlibabaCloudSearchCompletionServiceSettings fromMap(Map<String, Object> map, ConfigurationParseContext context) { | ||
| ValidationException validationException = new ValidationException(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| var commonServiceSettings = AlibabaCloudSearchServiceSettings.fromMap(map, context); | ||
| if (validationException.validationErrors().isEmpty() == false) { | ||
| throw validationException; | ||
| } | ||
|
|
||
| return new AlibabaCloudSearchCompletionServiceSettings(commonServiceSettings); | ||
| return new AlibabaCloudSearchCompletionServiceSettings(AlibabaCloudSearchServiceSettings.fromMap(map, context)); | ||
| } | ||
|
|
||
| private final AlibabaCloudSearchServiceSettings commonSettings; | ||
|
|
@@ -41,7 +34,7 @@ public AlibabaCloudSearchCompletionServiceSettings(AlibabaCloudSearchServiceSett | |
| } | ||
|
|
||
| public AlibabaCloudSearchCompletionServiceSettings(StreamInput in) throws IOException { | ||
| commonSettings = new AlibabaCloudSearchServiceSettings(in); | ||
| this.commonSettings = new AlibabaCloudSearchServiceSettings(in); | ||
| } | ||
|
|
||
| public AlibabaCloudSearchServiceSettings getCommonSettings() { | ||
|
|
@@ -53,6 +46,11 @@ public String modelId() { | |
| return commonSettings.modelId(); | ||
| } | ||
|
|
||
| @Override | ||
| public AlibabaCloudSearchCompletionServiceSettings updateServiceSettings(Map<String, Object> serviceSettings) { | ||
| return new AlibabaCloudSearchCompletionServiceSettings(commonSettings.updateServiceSettings(serviceSettings)); | ||
| } | ||
|
|
||
| @Override | ||
| public String getWriteableName() { | ||
| return NAME; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,25 +28,28 @@ | |
| import static org.elasticsearch.xpack.inference.services.ServiceFields.DIMENSIONS; | ||
| import static org.elasticsearch.xpack.inference.services.ServiceFields.MAX_INPUT_TOKENS; | ||
| import static org.elasticsearch.xpack.inference.services.ServiceFields.SIMILARITY; | ||
| import static org.elasticsearch.xpack.inference.services.ServiceUtils.extractOptionalPositiveInteger; | ||
| import static org.elasticsearch.xpack.inference.services.ServiceUtils.extractSimilarity; | ||
| import static org.elasticsearch.xpack.inference.services.ServiceUtils.removeAsType; | ||
|
|
||
| public class AlibabaCloudSearchEmbeddingsServiceSettings implements ServiceSettings { | ||
| public static final String NAME = "alibabacloud_search_embeddings_service_settings"; | ||
|
|
||
| public static AlibabaCloudSearchEmbeddingsServiceSettings fromMap(Map<String, Object> map, ConfigurationParseContext context) { | ||
| ValidationException validationException = new ValidationException(); | ||
| var validationException = new ValidationException(); | ||
| var commonServiceSettings = AlibabaCloudSearchServiceSettings.fromMap(map, context); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you may see, the validation is happening in 2 steps here. If CC @DonalEvans
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the idea of passing the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
|
|
||
| SimilarityMeasure similarity = extractSimilarity(map, ModelConfigurations.SERVICE_SETTINGS, validationException); | ||
| Integer dims = removeAsType(map, DIMENSIONS, Integer.class); | ||
| Integer maxInputTokens = removeAsType(map, MAX_INPUT_TOKENS, Integer.class); | ||
| var similarity = extractSimilarity(map, ModelConfigurations.SERVICE_SETTINGS, validationException); | ||
| var dimensions = extractOptionalPositiveInteger(map, DIMENSIONS, ModelConfigurations.SERVICE_SETTINGS, validationException); | ||
| var maxInputTokens = extractOptionalPositiveInteger( | ||
| map, | ||
| MAX_INPUT_TOKENS, | ||
| ModelConfigurations.SERVICE_SETTINGS, | ||
| validationException | ||
| ); | ||
|
|
||
| if (validationException.validationErrors().isEmpty() == false) { | ||
| throw validationException; | ||
| } | ||
| validationException.throwIfValidationErrorsExist(); | ||
|
|
||
| return new AlibabaCloudSearchEmbeddingsServiceSettings(commonServiceSettings, similarity, dims, maxInputTokens); | ||
| return new AlibabaCloudSearchEmbeddingsServiceSettings(commonServiceSettings, similarity, dimensions, maxInputTokens); | ||
| } | ||
|
|
||
| private final AlibabaCloudSearchServiceSettings commonSettings; | ||
|
|
@@ -67,10 +70,10 @@ public AlibabaCloudSearchEmbeddingsServiceSettings( | |
| } | ||
|
|
||
| public AlibabaCloudSearchEmbeddingsServiceSettings(StreamInput in) throws IOException { | ||
| commonSettings = new AlibabaCloudSearchServiceSettings(in); | ||
| similarity = in.readOptionalEnum(SimilarityMeasure.class); | ||
| dimensions = in.readOptionalVInt(); | ||
| maxInputTokens = in.readOptionalVInt(); | ||
| this.commonSettings = new AlibabaCloudSearchServiceSettings(in); | ||
| this.similarity = in.readOptionalEnum(SimilarityMeasure.class); | ||
| this.dimensions = in.readOptionalVInt(); | ||
| this.maxInputTokens = in.readOptionalVInt(); | ||
| } | ||
|
|
||
| public AlibabaCloudSearchServiceSettings getCommonSettings() { | ||
|
|
@@ -105,6 +108,28 @@ public String modelId() { | |
| return commonSettings.modelId(); | ||
| } | ||
|
|
||
| @Override | ||
| public AlibabaCloudSearchEmbeddingsServiceSettings updateServiceSettings(Map<String, Object> serviceSettings) { | ||
| var validationException = new ValidationException(); | ||
| var commonServiceSettings = commonSettings.updateServiceSettings(serviceSettings); | ||
|
|
||
| var extractedMaxInputTokens = extractOptionalPositiveInteger( | ||
| serviceSettings, | ||
| MAX_INPUT_TOKENS, | ||
| ModelConfigurations.SERVICE_SETTINGS, | ||
| validationException | ||
| ); | ||
|
|
||
| validationException.throwIfValidationErrorsExist(); | ||
|
|
||
| return new AlibabaCloudSearchEmbeddingsServiceSettings( | ||
| commonServiceSettings, | ||
| this.similarity, | ||
| this.dimensions, | ||
| extractedMaxInputTokens != null ? extractedMaxInputTokens : this.maxInputTokens | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public String getWriteableName() { | ||
| return NAME; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.