Skip to content

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

Merged
merged 49 commits into from
Mar 17, 2025

Conversation

ymao1
Copy link
Contributor

@ymao1 ymao1 commented Feb 14, 2025

Resolves #117856

Summary

Exposes the input_type parameter as a root level field in the Perform Inference API for text-embedding task types. Previously, this setting was available for certain services as a task setting. There are several services that do not accept an input_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 an input_type on the services that don't accept input_type parameters do not throw exceptions when used internally. Toward this end, this PR adds a InputType.INTERNAL_SEARCH and InputType.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 and InputType.INGEST are supported so InputType.CLASSIFICATION and InputType.CLUSTERING will throw validation exceptions

Cohere - docs
Google Vertex AI - docs
Jina AI - docs
Voyage AI - docs
Only InputType.SEARCH and InputType.INGEST are supported so InputType.CLASSIFICATION and InputType.CLUSTERING will throw validation exceptions


The following services were updated to pass an input type parameter:

Amazon Bedrock - docs

  • cohere provider updated to pass input_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 for input_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


@@ -19,7 +21,9 @@ public enum InputType {
SEARCH,
UNSPECIFIED,
CLASSIFICATION,
CLUSTERING;
CLUSTERING,
INTERNAL_SEARCH,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ymao1 ymao1 changed the title wip Expose input_type option at root level for text_embedding task type in Perform Inference API Mar 6, 2025
@ymao1
Copy link
Contributor Author

ymao1 commented Mar 11, 2025

run elasticsearch-ci/part-1

@ymao1 ymao1 added >enhancement :ml Machine learning Team:ML Meta label for the ML team v8.19.0 labels Mar 11, 2025
@ymao1 ymao1 self-assigned this Mar 11, 2025
@@ -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);
Copy link
Contributor Author

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
Copy link
Contributor Author

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(
Copy link
Contributor Author

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.

@elasticsearchmachine
Copy link
Collaborator

Hi @ymao1, I've created a changelog YAML for you.

@ymao1 ymao1 marked this pull request as ready for review March 11, 2025 23:16
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/ml-core (Team:ML)

Copy link
Member

@davidkyle davidkyle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ymao1 ymao1 merged commit 0b6a3cd into elastic:main Mar 17, 2025
17 checks passed
@ymao1
Copy link
Contributor Author

ymao1 commented Mar 17, 2025

💚 All backports created successfully

Status Branch Result
8.x

Questions ?

Please refer to the Backport tool documentation

ymao1 added a commit to ymao1/elasticsearch that referenced this pull request Mar 17, 2025
…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
elasticsearchmachine pushed a commit that referenced this pull request Mar 18, 2025
…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
omricohenn pushed a commit to omricohenn/elasticsearch that referenced this pull request Mar 28, 2025
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :ml Machine learning Team:ML Meta label for the ML team v8.19.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ML] Expose the Input Type option for the text_embedding task in the Inference API
3 participants