Skip to content

SOLR-17814: Add support for PatienceKnnVectorQuery#3644

Merged
alessandrobenedetti merged 6 commits intoapache:mainfrom
SeaseLtd:feature/SOLR-17814
Sep 23, 2025
Merged

SOLR-17814: Add support for PatienceKnnVectorQuery#3644
alessandrobenedetti merged 6 commits intoapache:mainfrom
SeaseLtd:feature/SOLR-17814

Conversation

@ilariapet
Copy link
Copy Markdown
Contributor

@ilariapet ilariapet commented Sep 10, 2025

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

Description

Apache Lucene implements an early termination approach for knn queries:
org.apache.lucene.search.PatienceKnnVectorQuery

This is a version of knn vector query that exits early when HNSW queue saturates over a saturationThreshold for more than patience times.

Solution

A new query type, PatienceKnnVectorQuery, was introduced, exposed through the KnnQParser with three additional parameters:

  • earlyTermination (boolean, default: false) – enables early termination during the search.
  • saturationThreshold (double) – controls the saturation level for early termination.
  • patience (int) – configures the patience factor for the termination strategy.

This allows users to decide whether or not to run the vector query with early termination. They can either rely on the default values provided by Lucene or override both of them with custom values.

Since the TextToVectorQParser extends the same base class, these parameters are also automatically available there, allowing the same early termination functionality without additional changes.

Tests

  • Test to verify that when no early termination parameters are provided, the default behaviour is applied (i.e. early termination is disabled), and no special logic is triggered.
  • Test to verify that when early termination is explicitly set to false, no special logic is triggered.
  • Test to verify that when early termination is explicitly set to true, but no other parameters are provided, the PatienceKnnVectorQuery is executed using the default values for saturationThreshold and patience.
  • Test to verify that when early termination is explicitly set to true, and both saturationThreshold and patience parameters are provided, the PatienceKnnVectorQuery is executed using the specified custom values (both float and byte query).
  • Test to verify that when early termination is NOT explicitly passed, but both saturationThreshold and patience parameters are provided, the PatienceKnnVectorQuery is executed using the specified input values.
  • Test to verify that when an invalid saturationThreshold value is provided in the query, Solr throws an exception.
  • Test to verify that when an invalid patience value is provided in the query, Solr throws an exception.
  • Test to verify that when only one input parameter is provided in the query, Solr throws a BAD_REQUEST exception with the expected message (both are required).

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

@github-actions github-actions bot added documentation Improvements or additions to documentation tests cat:search labels Sep 10, 2025
@ilariapet ilariapet force-pushed the feature/SOLR-17814 branch 2 times, most recently from d4afa1b to f22e59b Compare September 12, 2025 09:54
@ilariapet ilariapet changed the title SOLR-17814: Added support for PatienceKnnVectorQuery SOLR-17814: Add support for PatienceKnnVectorQuery Sep 23, 2025
Copy link
Copy Markdown
Contributor

@alessandrobenedetti alessandrobenedetti left a comment

Choose a reason for hiding this comment

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

Various iterations of reviews completed, ready to merge

@alessandrobenedetti alessandrobenedetti merged commit 4f02148 into apache:main Sep 23, 2025
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants