Skip to content

Add exception for perform embedding inference requests with query provided #131641

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/131641.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 131641
summary: Add exception for perform embedding inference requests with query provided
area: Machine Learning
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ public ActionRequestValidationException validate() {
}
}

if (taskType.equals(TaskType.TEXT_EMBEDDING) || taskType.equals(TaskType.SPARSE_EMBEDDING)) {
if (query != null) {
var e = new ActionRequestValidationException();
e.addValidationError(format("Field [query] cannot be specified for task type [%s]", taskType));
return e;
}
}

if (taskType.equals(TaskType.TEXT_EMBEDDING) == false
&& taskType.equals(TaskType.ANY) == false
&& (inputType != null && InputType.isInternalTypeOrUnspecified(inputType) == false)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,24 @@ public void testValidation_TextEmbedding_WithTopN() {
assertThat(inputError.getMessage(), is("Validation Failed: 1: Field [top_n] cannot be specified for task type [text_embedding];"));
}

public void testValidation_TextEmbedding_WithQuery() {
InferenceAction.Request queryRequest = new InferenceAction.Request(
TaskType.TEXT_EMBEDDING,
"model",
"query",
null,
null,
List.of("input"),
null,
null,
null,
false
);
ActionRequestValidationException queryError = queryRequest.validate();
assertNotNull(queryError);
assertThat(queryError.getMessage(), is("Validation Failed: 1: Field [query] cannot be specified for task type [text_embedding];"));
}

public void testValidation_Rerank_Null() {
InferenceAction.Request queryNullRequest = new InferenceAction.Request(
TaskType.RERANK,
Expand Down Expand Up @@ -249,7 +267,7 @@ public void testValidation_SparseEmbedding_WithInputType() {
InferenceAction.Request queryRequest = new InferenceAction.Request(
TaskType.SPARSE_EMBEDDING,
"model",
"",
null,
null,
null,
List.of("input"),
Expand Down Expand Up @@ -309,6 +327,27 @@ public void testValidation_SparseEmbedding_WithTopN() {
);
}

public void testValidation_SparseEmbedding_WithQuery() {
InferenceAction.Request queryRequest = new InferenceAction.Request(
TaskType.SPARSE_EMBEDDING,
"model",
"query",
null,
null,
List.of("input"),
null,
null,
null,
false
);
ActionRequestValidationException queryError = queryRequest.validate();
assertNotNull(queryError);
assertThat(
queryError.getMessage(),
is("Validation Failed: 1: Field [query] cannot be specified for task type [sparse_embedding];")
);
}

public void testValidation_Completion_WithInputType() {
InferenceAction.Request queryRequest = new InferenceAction.Request(
TaskType.COMPLETION,
Expand Down
Loading