Skip to content
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

Adding MinScore support to Linear Retriever #124182

Closed
wants to merge 21 commits into from
Closed

Conversation

mridula-s109
Copy link
Contributor

@mridula-s109 mridula-s109 commented Mar 6, 2025

This PR introduces support for the min_score parameter in the linear retriever. The min_score filter ensures that only documents with a relevance score above a specified threshold are retrieved, improving result quality and filtering out low-relevance matches.

  • Added min_score support in the linear retriever.
  • Updated the retrieval logic to apply the min_score threshold.
  • Based on an example from the Elasticsearch Guide (8.18), extended it to demonstrate min_score usage.

@mridula-s109
Copy link
Contributor Author

WIP - The testcases are failing, i have been trying to fix it. Also need to write yaml tests.

@mridula-s109 mridula-s109 requested a review from kderusso March 6, 2025 06:37
Copy link
Member

@kderusso kderusso left a comment

Choose a reason for hiding this comment

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

Nice start @mridula-s109

I left some comments. Additionally, it looks like you have some test compilation errors. I'd also love to see some yaml tests here, and we'll want to update our documentation to reflect the min score (I'm unsure of the state of our markdown documentation, but if we could do it in the same PR it would be ideal).

@@ -45,9 +47,11 @@ public RankDocsQueryBuilder(StreamInput in) throws IOException {
if (in.getTransportVersion().onOrAfter(TransportVersions.V_8_16_0)) {
this.queryBuilders = in.readOptionalArray(c -> c.readNamedWriteable(QueryBuilder.class), QueryBuilder[]::new);
this.onlyRankDocs = in.readBoolean();
this.minScore = in.readFloat();
Copy link
Member

Choose a reason for hiding this comment

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

As this is written, it will break transport serialization.

What you want to do, is register a new TransportVersion for your change in TransportVersions.java. You'll then reference this new transport version to serialize the min score - older transport versions will always just use a default value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If i want to include min_score without transport versioning changes, then is the way it is currently written fine?

@@ -88,6 +92,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_16_0)) {
out.writeOptionalArray(StreamOutput::writeNamedWriteable, queryBuilders);
out.writeBoolean(onlyRankDocs);
out.writeFloat(minScore);
Copy link
Member

Choose a reason for hiding this comment

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

You'll need to reference the new transport version you create here as well, to ensure that serialization is consistent.

@mridula-s109 mridula-s109 added auto-backport Automatically create backport pull requests when merged :Search Relevance/Search Catch all for Search Relevance labels Mar 13, 2025
@mridula-s109 mridula-s109 marked this pull request as ready for review March 13, 2025 18:48
@elasticsearchmachine elasticsearchmachine added the Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch label Mar 13, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)

@elasticsearchmachine
Copy link
Collaborator

Hi @mridula-s109, I've created a changelog YAML for you.

@mridula-s109 mridula-s109 requested a review from a team March 13, 2025 18:52
Copy link
Contributor

@Samiul-TheSoccerFan Samiul-TheSoccerFan left a comment

Choose a reason for hiding this comment

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

Nice work, LGTM. Left some comments

@Samiul-TheSoccerFan Samiul-TheSoccerFan added the :SearchOrg/Relevance Label for the Search (solution/org) Relevance team label Mar 14, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/search-eng (Team:SearchOrg)

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/search-relevance (Team:Search - Relevance)

@mridula-s109 mridula-s109 marked this pull request as draft March 26, 2025 18:35
@mridula-s109 mridula-s109 marked this pull request as ready for review March 27, 2025 12:57
@mridula-s109 mridula-s109 marked this pull request as draft March 27, 2025 13:13
@mridula-s109
Copy link
Contributor Author

Closing this PR in favor of a fresh one: #126238 — will be published shortly.

All feedback and comments from this PR will be carried forward into the new, cleaner version. Thanks for all the input so far!

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 >enhancement :Search Relevance/Search Catch all for Search Relevance :SearchOrg/Relevance Label for the Search (solution/org) Relevance team Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants