Skip to content

Conversation

@eliaporciani
Copy link
Contributor

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:

  • I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • 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)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.
  • I have added tests for my changes.
  • I have added documentation for the Reference Guide
  • I have added a changelog entry for my change

@github-actions github-actions bot added documentation Improvements or additions to documentation tests cat:search cat:schema labels Dec 10, 2025
chatman pushed a commit that referenced this pull request Dec 11, 2025
chatman pushed a commit that referenced this pull request Dec 11, 2025
chatman pushed a commit that referenced this pull request Dec 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cat:schema cat:search documentation Improvements or additions to documentation tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants