-
Notifications
You must be signed in to change notification settings - Fork 25.6k
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
Expose input_type option at root level for text_embedding task type in Perform Inference API
#122638
Changes from 43 commits
3b418ae
5d020a7
cceb308
b515e84
625a5a2
c064e26
f6dbf51
6a25d08
b7c2481
2d2b6db
3dc38f7
356d546
a143af1
7f20d32
d6c2464
f63e852
f9962ce
2905643
f47538c
5b4ee68
be17339
bba8ac5
bf32efd
3dbeaff
c3c9cef
cc96e9a
fbc8791
e6e877e
215b4b7
de1f8fc
4838727
1946d49
f1bbcc6
ea4ad64
3a3e946
20c28b0
84bc649
4ad3214
9f744db
4564680
aef7da8
6cbd41e
f364ad3
113cf3d
cb8d337
ef6074b
61c8d7b
61091c3
588c6fb
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,7 @@ | ||
| pr: 122638 | ||
| summary: Expose `input_type` option at root level for `text_embedding` task type in | ||
| Perform Inference API | ||
| area: Machine Learning | ||
| type: enhancement | ||
| issues: | ||
| - 117856 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,8 @@ | |
|
|
||
| import java.util.Locale; | ||
|
|
||
| import static org.elasticsearch.core.Strings.format; | ||
|
|
||
| /** | ||
| * Defines the type of request, whether the request is to ingest a document or search for a document. | ||
| */ | ||
|
|
@@ -19,7 +21,11 @@ public enum InputType { | |
| SEARCH, | ||
| UNSPECIFIED, | ||
| CLASSIFICATION, | ||
| CLUSTERING; | ||
| CLUSTERING, | ||
|
|
||
| // Use the following enums when calling the inference API internally | ||
| INTERNAL_SEARCH, | ||
| INTERNAL_INGEST; | ||
|
|
||
| @Override | ||
| public String toString() { | ||
|
|
@@ -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); | ||
|
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. Check that the values passed from the REST API do not include the internal values |
||
| if (inputType == InputType.INTERNAL_INGEST || inputType == InputType.INTERNAL_SEARCH) { | ||
| throw new IllegalArgumentException(format("Unrecognized input_type [%s]", inputType)); | ||
| } | ||
| return inputType; | ||
| } | ||
|
|
||
| public static boolean isInternalTypeOrUnspecified(InputType inputType) { | ||
| return inputType == InputType.INTERNAL_INGEST || inputType == InputType.INTERNAL_SEARCH || inputType == InputType.UNSPECIFIED; | ||
| } | ||
|
|
||
| public static boolean isSpecified(InputType inputType) { | ||
| return inputType != null && inputType != InputType.UNSPECIFIED; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,13 +57,15 @@ public static class Request extends BaseInferenceActionRequest { | |
|
|
||
| public static final TimeValue DEFAULT_TIMEOUT = TimeValue.timeValueSeconds(30); | ||
| public static final ParseField INPUT = new ParseField("input"); | ||
| public static final ParseField INPUT_TYPE = new ParseField("input_type"); | ||
| public static final ParseField TASK_SETTINGS = new ParseField("task_settings"); | ||
| public static final ParseField QUERY = new ParseField("query"); | ||
| public static final ParseField TIMEOUT = new ParseField("timeout"); | ||
|
|
||
| static final ObjectParser<Request.Builder, Void> PARSER = new ObjectParser<>(NAME, Request.Builder::new); | ||
| static { | ||
| PARSER.declareStringArray(Request.Builder::setInput, INPUT); | ||
| PARSER.declareString(Request.Builder::setInputType, INPUT_TYPE); | ||
| PARSER.declareObject(Request.Builder::setTaskSettings, (p, c) -> p.mapOrdered(), TASK_SETTINGS); | ||
| PARSER.declareString(Request.Builder::setQuery, QUERY); | ||
| PARSER.declareString(Builder::setInferenceTimeout, TIMEOUT); | ||
|
|
@@ -80,8 +82,6 @@ public static Builder parseRequest(String inferenceEntityId, TaskType taskType, | |
| Request.Builder builder = PARSER.apply(parser, null); | ||
| builder.setInferenceEntityId(inferenceEntityId); | ||
| builder.setTaskType(taskType); | ||
| // For rest requests we won't know what the input type is | ||
| builder.setInputType(InputType.UNSPECIFIED); | ||
| builder.setContext(context); | ||
| return builder; | ||
| } | ||
|
|
@@ -227,6 +227,14 @@ public ActionRequestValidationException validate() { | |
| } | ||
| } | ||
|
|
||
| if (taskType.equals(TaskType.TEXT_EMBEDDING) == false | ||
|
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. Throws validation exception if |
||
| && taskType.equals(TaskType.ANY) == false | ||
| && (inputType != null && InputType.isInternalTypeOrUnspecified(inputType) == false)) { | ||
| var e = new ActionRequestValidationException(); | ||
| e.addValidationError(format("Field [input_type] cannot be specified for task type [%s]", taskType)); | ||
| return e; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
|
|
@@ -335,6 +343,11 @@ public Builder setInputType(InputType inputType) { | |
| return this; | ||
| } | ||
|
|
||
| public Builder setInputType(String inputType) { | ||
| this.inputType = InputType.fromRestString(inputType); | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setTaskSettings(Map<String, Object> taskSettings) { | ||
| this.taskSettings = taskSettings; | ||
| return this; | ||
|
|
||
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.
π