Skip to content

Add pagination / document limit logic for reranking - #32

Merged
macohen merged 7 commits into
opensearch-project:mainfrom
msfroh:pagination
Nov 23, 2022
Merged

Add pagination / document limit logic for reranking#32
macohen merged 7 commits into
opensearch-project:mainfrom
msfroh:pagination

Conversation

@msfroh

@msfroh msfroh commented Nov 23, 2022

Copy link
Copy Markdown
Collaborator

Description

This change augments opensearch-project/search-relevance#26 by adding unit tests.

  • Add preprocessRequest interface to ResultTransformer.
  • Override from and size parameters during preprocess, to fetch more than the default 10 hits from OpenSearch (improved accuracy if the ranker can access more documents)
  • Limit the number of documents sent to Kendra Ranking (Will make this number configurable in a follow up)
  • Populate response documents from re-ranked hits (upto Kendra limit) and OpenSearch hits beyond the limit

Issues Resolved

N/A

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed as per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Mahita Mahesh and others added 4 commits November 22, 2022 18:53
…than the default 10.

* Add preprocess request interface to ResultTransformer
* Override from and size parameters durig preprocess, to fetch more hits from OpenSearch
* Limit the number of documents sent to Kendra Ranking (Will make this number configurable in a follow up)
* Populate response documents from re-ranked hits (upto Kendra limit) and OpenSearch hits beyond the limit

Signed-off-by: Mahita Mahesh <mahitam@amazon.com>
Signed-off-by: Michael Froh <froh@amazon.com>
Signed-off-by: Mahita Mahesh <mahitam@amazon.com>
Signed-off-by: Mahita Mahesh <mahitam@amazon.com>
Signed-off-by: Michael Froh <froh@amazon.com>
Add unit tests for the pagination logic in SearchActionFilter as well
as the whole KendraIntelligentRanker class (including pagination).

Also, removed OriginalRequestFields in favor of cloning the
SearchSourceBuilder.

Signed-off-by: Michael Froh <froh@amazon.com>
@msfroh
msfroh requested a review from a team November 23, 2022 01:14
Updating integration test to match approach used by other recent
plugins, in the hope of fixing test runs on Windows.

Signed-off-by: Michael Froh <froh@amazon.com>
// Unknown query type or query does not reference body field
return hits;
}
if (hits.getHits().length == 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: If we check this right up front, we can avoid the query parser step too

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, thanks!


public void testShouldNotTransformWithoutQuery() {
KendraIntelligentRanker ranker = new KendraIntelligentRanker(buildMockHttpClient());
SearchRequest originalRequest = new SearchRequest();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should set the SearchSourceBuilder with query(null) here

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Oops! Thanks

I think I copy/pasted the test above, got distracted, then came back and started writing the next test. 😁

* Fix test case with non-null source but null query.
* Skip transform on empty results before doing any work.

Signed-off-by: Michael Froh <froh@amazon.com>
* Earlier test covered empty hits, so we should assume that Kendra
  ranking handles at least 1 hit.

Signed-off-by: Michael Froh <froh@amazon.com>
@msfroh

msfroh commented Nov 23, 2022

Copy link
Copy Markdown
Collaborator Author

Yay for randomized testing!

My earlier commit failed on the case where testTransformHits randomly selected zero as a docLimit and zero additional hits. That's already covered by the earlier testTransformHits test case so we can safely skip it.

Still, it's nice to know that we're considering many possibilities.

@macohen
macohen merged commit ae550aa into opensearch-project:main Nov 23, 2022
@mingshl mingshl added the enhancement change or upgrade that increases software capabilities beyond original client specifications label Jan 23, 2023
@msfroh
msfroh deleted the pagination branch February 7, 2023 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement change or upgrade that increases software capabilities beyond original client specifications

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants