solr icon indicating copy to clipboard operation
solr copied to clipboard

Feature/solr 17928 finalize pr

Open eliaporciani opened this issue 1 month ago • 0 comments

https://issues.apache.org/jira/browse/SOLR-17928

Description

This PR is based on #3711, which appears inactive. I fetched the original commits, merged them with the latest main, resolved conflicts, and pushed this updated branch to help move the contribution forward. All original commits are preserved, and full credit goes to the original author, who has been added as a contributor to this PR.

The previous version introduced an efSearch parameter. After review, this has been replaced with efSearchScaleFactor parameter. This parameter controls how much the KNN query should overfetch. If not set, it defaults to 1, meaning no overfetching beyond topK × 1.

Solution

The KNN execution now derives the internal efSearch value by multiplying topK with the user-provided efSearchScaleFactor. This allows controlled overfetching without exposing efSearch directly.

To apply this logic cleanly, new wrapper query classes (SolrKnnFloatVectorQuery and SolrKnnByteVectorQuery) were introduced. These delegate to Lucene’s KNN queries while injecting the scaled efSearch value before execution.

During this update, I also:

  • added handling to reject invalid NaN values for the parameter
  • introduced a more appropriate exception type when the parameter is malformed.

Tests

Tests were updated to reflect the new behavior, ensuring that:

  • Queries with efSearch parameters work correctly
  • Invalid efSearchScaleFactor inputs (e.g., NaN) produce the expected exception.

Checklist

Please review the following and check all that apply:

  • [x] I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • [x] I have created a Jira issue and added the issue ID to my pull request title.
  • [ ] I have given Solr maintainers access to contribute to my PR branch. (optional but recommended, not available for branches on forks living under an organisation)
  • [x] I have developed this patch against the main branch.
  • [x] I have run ./gradlew check.
  • [x] I have added tests for my changes.
  • [x] I have added documentation for the Reference Guide
  • [x] I have added a changelog entry for my change

eliaporciani avatar Dec 10 '25 17:12 eliaporciani