Skip to content

Conversation

dan-rubinstein
Copy link
Member

@dan-rubinstein dan-rubinstein commented Oct 6, 2025

This change removes the feature flag for the elastic reranker chunking configuration settings. This will enable it in serverless and will remove the unnecessary code from the 9.2 branch in a backport as well.

This change also adds functionality to allow users to set return_documents to false in the task settings to not return document data. There is an existing bug in the ElasticsearchInternalService which still returns documents if the user sets return_documents to false when creating the inference endpoint instead of when calling the perform inference API. I've created an issue to address this to minimize the size of this PR and to look into it a bit more and make sure nothing breaks if we change this behavior.

@dan-rubinstein dan-rubinstein added >non-issue :ml Machine learning backport Team:ML Meta label for the ML team v9.2.0 v9.3.0 labels Oct 6, 2025
@dan-rubinstein dan-rubinstein changed the title Removing elastic reranker chunking feature flag Removing elastic reranker chunking feature flag and allow return_documents to be false Oct 7, 2025
@dan-rubinstein dan-rubinstein added auto-backport Automatically create backport pull requests when merged and removed backport labels Oct 7, 2025
@elasticsearchmachine
Copy link
Collaborator

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

assertEquals(1, rankedDocResults.getRankedDocs().size());
}, e -> fail("Expected successful parsing but got failure: " + e)));
if (returnDocuments) {
assertNotNull(rankedDocResults.getRankedDocs().get(0).text());
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than just asserting that the text is non-null in this case, would it be better to assert that it matches the expected text:

assertThat(rankedDocResults.getRankedDocs().get(0).text(), is(inputs.getFirst()));

Copy link
Member Author

Choose a reason for hiding this comment

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

This is related to the comment below. We can discuss it in the comments there.

Comment on lines 166 to 170
if (returnDocuments) {
assertNotNull(rankedDocResults.getRankedDocs().get(0).text());
} else {
assertNull(rankedDocResults.getRankedDocs().get(0).text());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

These asserts are redundant, since we already assert that the actual results match the expected results on line 165.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll remove these assertions.

Copy link
Contributor

Choose a reason for hiding this comment

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

When constructing the expected RankedDoc on line 163, we're setting the text to be the expected value (either the first input or null) based on whether returnDocuments is true, so we would be able to tell if the document string was returned when doing the comparison:

new RankedDocsResults.RankedDoc(0, max(relevanceScore1, relevanceScore2), returnDocuments ? inputs.get(0) : null)

Comment on lines 193 to 197
if (returnDocuments) {
rankedDocResults.getRankedDocs().forEach(r -> { assertNotNull(r.text()); });
} else {
rankedDocResults.getRankedDocs().forEach(r -> { assertNull(r.text()); });
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it might be possible to assert on the actual value of the text in these tests instead of just whether or not it's null. If we used fixed values for the relevance scores in the ranked docs instead of random ones, then the order of the results would be deterministic and we could know which doc was expected to have which text.

It would also be good to have the inputs list elements not be identical, since if they're the same, then we have no way of making sure that the text is correct when comparing between the two documents. With the test as it is, if there was some weird bug which caused the text from one result to be copied to another result, we would have no way of spotting that.

Copy link
Member Author

@dan-rubinstein dan-rubinstein Oct 8, 2025

Choose a reason for hiding this comment

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

The purpose of randomizing the values of the relevance score is to make sure we always properly sort the values at the end and that we always take the highest chunk score per document. The underlying unit being tested shouldn't care whether the scores are in a specific order so I figured randomizing the values would help us test this.

As for the input strings I think we can make 2 changes to make the tests more robust.

  1. Make the input strings different per document to avoid accidentally generating 2 identical ones when passing in 2 documents.
  2. Modify the assertions to specifically check that the correct document string was returned.

Let me know if this makes sense to you.

Copy link
Contributor

Choose a reason for hiding this comment

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

As long as we can assert that the results contain the correct string, then using random relevance scores is fine, I think.

Ideally, I think that a unit test should test one thing at a time, since that helps pinpoint the specific area that has a bug in the event of a test failure. For example, a test that the list returned by rankedDocResults.getRankedDocs() is sorted by relevance score regardless of the returnDocuments value would use non-random relevance scores for the inputs so that the expected output is fixed, so we don't have to effectively reimplement the sorting logic in the test in order to validate the output. This is just my personal philosophy when it comes to unit testing though, so not something that needs to be changed in this PR.

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 if @DonalEvans suggestions can be incorporated

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

@dan-rubinstein
Copy link
Member Author

@elasticmachine merge upstream

@dan-rubinstein
Copy link
Member Author

@elasticmachine merge upstream

@dan-rubinstein dan-rubinstein merged commit abb7c29 into elastic:main Oct 8, 2025
34 checks passed
dan-rubinstein added a commit to dan-rubinstein/elasticsearch that referenced this pull request Oct 8, 2025
…ments to be false (elastic#136045)

* Removing elastic reranker chunking feature flag

* Allow return_documents to be set to false

* Updating unit tests to verify returned document strings

---------

Co-authored-by: Elastic Machine <[email protected]>
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
9.2

elasticsearchmachine pushed a commit that referenced this pull request Oct 8, 2025
…ments to be false (#136045) (#136222)

* Removing elastic reranker chunking feature flag

* Allow return_documents to be set to false

* Updating unit tests to verify returned document strings

---------

Co-authored-by: Elastic Machine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged :ml Machine learning >non-issue Team:ML Meta label for the ML team v9.2.0 v9.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants