-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Expose input_type
option at root level for text_embedding
task type in Perform Inference API
#122638
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
Conversation
@@ -19,7 +21,9 @@ public enum InputType { | |||
SEARCH, | |||
UNSPECIFIED, | |||
CLASSIFICATION, | |||
CLUSTERING; | |||
CLUSTERING, | |||
INTERNAL_SEARCH, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
input_type
option at root level for text_embedding
task type in Perform Inference API
run elasticsearch-ci/part-1 |
@@ -29,4 +35,20 @@ public String toString() { | |||
public static InputType fromString(String name) { | |||
return valueOf(name.trim().toUpperCase(Locale.ROOT)); | |||
} | |||
|
|||
public static InputType fromRestString(String name) { | |||
var inputType = InputType.fromString(name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check that the values passed from the REST API do not include the internal values
@@ -199,6 +199,14 @@ public ActionRequestValidationException validate() { | |||
} | |||
} | |||
|
|||
if (taskType.equals(TaskType.TEXT_EMBEDDING) == false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throws validation exception if input_type
is used with task types other than text-embedding
or if task type is not specified
@@ -88,30 +83,26 @@ public static CohereEmbeddingsTaskSettings fromMap(Map<String, Object> map) { | |||
* originalSettings. | |||
* @param originalSettings the settings stored as part of the inference entity configuration | |||
* @param requestTaskSettings the settings passed in within the task_settings field of the request | |||
* @param requestInputType the input type passed in the request parameters | |||
* @return a constructed {@link CohereEmbeddingsTaskSettings} | |||
*/ | |||
public static CohereEmbeddingsTaskSettings of( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, if a requestInputType
was passed in (only used internally), it would take precedence over request task settings input type, which would take precedence over persisted task settings input type, and the task settings input type would be set to the "winner".
This caused some issues when trying to do this across services, some of which do not allow input type in task settings and some of which don't allow task settings at all.
For this reason, this PR refactored to set and validate the request input type at the service level, which is then passed directly to the service's request manager.
Hi @ymao1, I've created a changelog YAML for you. |
Pinging @elastic/ml-core (Team:ML) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
...src/main/java/org/elasticsearch/xpack/inference/services/azureopenai/AzureOpenAiService.java
Outdated
Show resolved
Hide resolved
.../plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/ServiceUtils.java
Outdated
Show resolved
Hide resolved
…inference/services/azureopenai/AzureOpenAiService.java Co-authored-by: David Kyle <[email protected]>
…inference/services/ServiceUtils.java Co-authored-by: David Kyle <[email protected]>
💚 All backports created successfully
Questions ?Please refer to the Backport tool documentation |
…pe in Perform Inference API (elastic#122638) * wip * wip * [CI] Auto commit changes from spotless * Adding internal input types * [CI] Auto commit changes from spotless * Throwing validation exception for services that don't support input type * linting * hugging face * voyage ai * google ai studio * bedrock updates * Fixing tests * Fixing tests * Fixing tests * bedrock updates * elasticsearch * azure openai * [CI] Auto commit changes from spotless * Refactoring all the things * [CI] Auto commit changes from spotless * Everything compiles * spotless * external actions tests * external request tests * service tests * Fixing integration tests * Cleanup * Update docs/changelog/122638.yaml * Cleanup * Update x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureopenai/AzureOpenAiService.java Co-authored-by: David Kyle <[email protected]> * Update x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/ServiceUtils.java Co-authored-by: David Kyle <[email protected]> * PR feedback --------- Co-authored-by: elasticsearchmachine <[email protected]> Co-authored-by: David Kyle <[email protected]> (cherry picked from commit 0b6a3cd) # Conflicts: # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/external/request/alibabacloudsearch/AlibabaCloudSearchEmbeddingsRequestEntity.java # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/external/request/alibabacloudsearch/AlibabaCloudSearchSparseRequestEntity.java # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/external/request/cohere/CohereEmbeddingsRequestEntity.java # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/external/request/voyageai/VoyageAIEmbeddingsRequestEntity.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/external/action/cohere/CohereEmbeddingsActionTests.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/external/action/googleaistudio/GoogleAiStudioEmbeddingsActionTests.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/external/action/huggingface/HuggingFaceActionCreatorTests.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/external/action/voyageai/VoyageAIActionCreatorTests.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/external/action/voyageai/VoyageAIEmbeddingsActionTests.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/external/request/alibabacloudsearch/AlibabaCloudSearchEmbeddingsRequestEntityTests.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/googleaistudio/GoogleAiStudioServiceTests.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/voyageai/VoyageAIServiceTests.java
…pe in Perform Inference API (#122638) (#125049) * wip * wip * [CI] Auto commit changes from spotless * Adding internal input types * [CI] Auto commit changes from spotless * Throwing validation exception for services that don't support input type * linting * hugging face * voyage ai * google ai studio * bedrock updates * Fixing tests * Fixing tests * Fixing tests * bedrock updates * elasticsearch * azure openai * [CI] Auto commit changes from spotless * Refactoring all the things * [CI] Auto commit changes from spotless * Everything compiles * spotless * external actions tests * external request tests * service tests * Fixing integration tests * Cleanup * Update docs/changelog/122638.yaml * Cleanup * Update x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureopenai/AzureOpenAiService.java Co-authored-by: David Kyle <[email protected]> * Update x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/ServiceUtils.java Co-authored-by: David Kyle <[email protected]> * PR feedback --------- Co-authored-by: elasticsearchmachine <[email protected]> Co-authored-by: David Kyle <[email protected]> (cherry picked from commit 0b6a3cd) # Conflicts: # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/external/request/alibabacloudsearch/AlibabaCloudSearchEmbeddingsRequestEntity.java # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/external/request/alibabacloudsearch/AlibabaCloudSearchSparseRequestEntity.java # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/external/request/cohere/CohereEmbeddingsRequestEntity.java # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/external/request/voyageai/VoyageAIEmbeddingsRequestEntity.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/external/action/cohere/CohereEmbeddingsActionTests.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/external/action/googleaistudio/GoogleAiStudioEmbeddingsActionTests.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/external/action/huggingface/HuggingFaceActionCreatorTests.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/external/action/voyageai/VoyageAIActionCreatorTests.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/external/action/voyageai/VoyageAIEmbeddingsActionTests.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/external/request/alibabacloudsearch/AlibabaCloudSearchEmbeddingsRequestEntityTests.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/googleaistudio/GoogleAiStudioServiceTests.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/voyageai/VoyageAIServiceTests.java
…pe in Perform Inference API (elastic#122638) * wip * wip * [CI] Auto commit changes from spotless * Adding internal input types * [CI] Auto commit changes from spotless * Throwing validation exception for services that don't support input type * linting * hugging face * voyage ai * google ai studio * bedrock updates * Fixing tests * Fixing tests * Fixing tests * bedrock updates * elasticsearch * azure openai * [CI] Auto commit changes from spotless * Refactoring all the things * [CI] Auto commit changes from spotless * Everything compiles * spotless * external actions tests * external request tests * service tests * Fixing integration tests * Cleanup * Update docs/changelog/122638.yaml * Cleanup * Update x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/azureopenai/AzureOpenAiService.java Co-authored-by: David Kyle <[email protected]> * Update x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/ServiceUtils.java Co-authored-by: David Kyle <[email protected]> * PR feedback --------- Co-authored-by: elasticsearchmachine <[email protected]> Co-authored-by: David Kyle <[email protected]>
Resolves #117856
Summary
Exposes the
input_type
parameter as a root level field in the Perform Inference API fortext-embedding
task types. Previously, this setting was available for certain services as a task setting. There are several services that do not accept aninput_type
specification or only a subset of values. Invalid inputs for these services will throw a validation exception.Because we use the
InferenceAction
internally in several places, we want to ensure that calling perform inference with aninput_type
on the services that don't acceptinput_type
parameters do not throw exceptions when used internally. Toward this end, this PR adds aInputType.INTERNAL_SEARCH
andInputType.INTERNAL_INGEST
that will bypass validation.Verification
✅ - manually verified with credentials
🛑 - have not been able to manually verify
The following services already passed the
input_type
parameter:✅ AlibabaCloud AI Search - docs
Only
InputType.SEARCH
andInputType.INGEST
are supported soInputType.CLASSIFICATION
andInputType.CLUSTERING
will throw validation exceptions✅ Cohere - docs
✅ Google Vertex AI - docs
✅ Jina AI - docs
✅ Voyage AI - docs
Only
InputType.SEARCH
andInputType.INGEST
are supported soInputType.CLASSIFICATION
andInputType.CLUSTERING
will throw validation exceptionsThe following services were updated to pass an input type parameter:
✅ Amazon Bedrock - docs
cohere
provider updated to passinput_type
to text embedding task.amazontitan
provider does not accept an input type parameter so updated to throw validation exception when specified.✅ Azure OpenAI - docs
The docs say that
input_type
is an accepted string parameter but does not list the allowed values. Upon testing, it seems that this API accepts any arbitrary value forinput_type
without throwing any errors or changing the embedding results.🛑 Azure AI Studio - docs
✅ Google AI Studio - docs
Updated to pass
taskType
parameter when modelId=embedding-001. Throws validation exception otherwise.The following services do not support an input type parameter and have been updated to throw a validation exception if
input_type
is specified.✅ Hugging Face - docs
✅ Mistral - docs
✅ OpenAI - docs
✅ IBM Watsonx - docs