Skip to content

Add optional query bit size hint to KnnSearchStrategy.Hnsw#15708

Open
arup-chauhan wants to merge 2 commits intoapache:mainfrom
arup-chauhan:query-bit-hint-strategy
Open

Add optional query bit size hint to KnnSearchStrategy.Hnsw#15708
arup-chauhan wants to merge 2 commits intoapache:mainfrom
arup-chauhan:query-bit-hint-strategy

Conversation

@arup-chauhan
Copy link

This PR introduces an optional query bit-size hint for KnnSearchStrategy.Hnsw as a first incremental step toward #15614.

I intentionally limited the scope to search-strategy API plumbing and tests to keep risk low.
Default behavior remains unchanged: the new hint is metadata-only in this PR and does not alter scoring yet.

Changes

  • Added optional queryBitSizeHint to KnnSearchStrategy.Hnsw.
  • Kept backward compatibility by preserving the existing constructor and adding an overload:
    • Hnsw(int filteredSearchThreshold)
    • Hnsw(int filteredSearchThreshold, Integer queryBitSizeHint)
  • Added validation for the hint (> 0 when non-null).
  • Added getter: queryBitSizeHint().
  • Updated equals / hashCode for Hnsw to include the new hint.
  • Updated KnnSearchStrategy.Patience constructors to support hint passthrough.
  • Updated HnswQueueSaturationCollector#getSearchStrategy() to preserve and forward the hint when wrapping strategies.
  • Added new tests in TestKnnSearchStrategy to cover:
    • default/no-hint behavior
    • constructor with hint
    • hint validation
    • equals/hashCode behavior
    • hint preservation across seeded/patience wrapping paths

Validation

  • ./gradlew -p lucene/core compileJava
  • ./gradlew -p lucene/core test --tests TestKnnSearchStrategy
  • ./gradlew -p lucene/core check

Only tweak I made: removed “(after formatting fix)” since it passes now.

Signed-off-by: Arup Chauhan <arupchauhan.connect@gmail.com>
@arup-chauhan
Copy link
Author

Hey @benwtrent

Implemented the first incremental step by adding an optional queryBitSizeHint to KnnSearchStrategy.Hnsw.

I’ve preserved backward compatibility, forwarded the hint through Patience / seeded wrapping paths, and added focused strategy tests. This PR intentionally does not change scoring behavior.

Next, I plan to wire the hint into the vector reader/scorer plumbing, and then follow up with a small PR that uses the hint for query-bit-aware behavior in the scalar-quantized scoring path.

Looking forward to your feedback!

Signed-off-by: Arup Chauhan <arupchauhan.connect@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant