Skip to content

Conversation

@jonathan-buttner
Copy link
Contributor

@jonathan-buttner jonathan-buttner commented Oct 27, 2025

Fixes an issue where if a request did not include the task type in the URL, and the query field was not included in the request, a null pointer would be thrown.

This PR will have a validation exception be thrown indicating that the query field must be defined for the rerank task type.

Testing

Create inference endpoint

PUT _inference/rerank/jinaai-rerank
{
  "service": "jinaai",
  "service_settings": {
    "model_id": "jina-colbert-v1-en",
    "api_key": "api key"
  }
}

Issue request without task type in URL

POST _inference/jinaai-rerank
{
    "input": [
        "Carson City is the capital city of the American state of Nevada.",
        "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
        "Washington, D.C. (also known as simply Washington or D.C., and officially as the District of Columbia) is the capital of the United States. It is a federal district.",
        "Capitalization or capitalisation in English grammar is the use of a capital letter at the start of a word. English usage varies from capitalization in other languages."
    ],
    "return_documents": true
}

That should return with a validation error.

@elasticsearchmachine
Copy link
Collaborator

Hi @jonathan-buttner, I've created a changelog YAML for you.

@jonathan-buttner jonathan-buttner marked this pull request as ready for review October 27, 2025 21:19
@elasticsearchmachine
Copy link
Collaborator

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

Copy link
Contributor

@DonalEvans DonalEvans left a comment

Choose a reason for hiding this comment

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

Just a couple of minor points, not mandatory

Comment on lines 897 to 912
String responseJson = """
{
"index": "d0760819-5a73-4d58-b163-3956d3648b62",
"results": [
],
"meta": {
"api_version": {
"version": "1"
},
"billed_units": {
"search_units": 1
}
}
}
""";
webServer.enqueue(new MockResponse().setResponseCode(200).setBody(responseJson));
Copy link
Contributor

Choose a reason for hiding this comment

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

This is unnecessary, since the test never actually tries to get a response, as it fails in validation before sending the request.

Comment on lines 994 to 995
MatcherAssert.assertThat(result.asMap(), Matchers.is(buildExpectationRerank(List.of())));
MatcherAssert.assertThat(webServer.requests(), hasSize(1));
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick, but this class uses MatcherAssert.assertThat() in a lot of places instead of using ESTestCase.assertThat() (even though they're the same under the hood). Would it improve consistency to do a quick find/replace to remove the MatcherAssert. and have all assertions using the same assertThat() method?

@jonathan-buttner jonathan-buttner merged commit 34145ed into elastic:main Oct 28, 2025
34 checks passed
jonathan-buttner added a commit to jonathan-buttner/elasticsearch that referenced this pull request Oct 28, 2025
)

* Validating that query is defined for rerank task

* Validation for completion works without query field

* Update docs/changelog/137219.yaml

* Addressing feedback

* [CI] Auto commit changes from spotless

---------

Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
(cherry picked from commit 34145ed)

# Conflicts:
#	x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/SenderServiceTests.java
#	x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/cohere/CohereServiceTests.java
@jonathan-buttner
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
9.2
9.1
8.19

Questions ?

Please refer to the Backport tool documentation

elasticsearchmachine pushed a commit that referenced this pull request Oct 28, 2025
elasticsearchmachine pushed a commit that referenced this pull request Oct 28, 2025
…) (#137293)

* [ML] Perform query field validation for rerank task type (#137219)

* Validating that query is defined for rerank task

* Validation for completion works without query field

* Update docs/changelog/137219.yaml

* Addressing feedback

* [CI] Auto commit changes from spotless

---------

Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
(cherry picked from commit 34145ed)

# Conflicts:
#	x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/SenderServiceTests.java
#	x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/cohere/CohereServiceTests.java

* Fixing tests
elasticsearchmachine pushed a commit that referenced this pull request Oct 29, 2025
) (#137294)

* [ML] Perform query field validation for rerank task type (#137219)

* Validating that query is defined for rerank task

* Validation for completion works without query field

* Update docs/changelog/137219.yaml

* Addressing feedback

* [CI] Auto commit changes from spotless

---------

Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
(cherry picked from commit 34145ed)

# Conflicts:
#	x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/SenderServiceTests.java
#	x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/cohere/CohereServiceTests.java

* Fixing merge error

* fixing test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>bug :ml Machine learning Team:ML Meta label for the ML team v8.19.7 v9.1.7 v9.2.1 v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants