mirror of https://github.com/apache/lucene.git
Make the HitQueue size more appropriate for KNN exact search (#13184)
Currently, when performing KNN exact search, we consistently set the HitQueue size to k. However, there may be instances where the number of candidates is actually lower than k.
This commit is contained in:
parent
d393b9d039
commit
7a08eeab47
|
@ -222,6 +222,7 @@ Optimizations
|
||||||
|
|
||||||
* GITHUB#13121: Speedup multi-segment HNSW graph search for diversifying child kNN queries. Builds on GITHUB#12962.
|
* GITHUB#13121: Speedup multi-segment HNSW graph search for diversifying child kNN queries. Builds on GITHUB#12962.
|
||||||
(Ben Trent)
|
(Ben Trent)
|
||||||
|
* GITHUB#13184: Make the HitQueue size more appropriate for KNN exact search (Pan Guixin)
|
||||||
|
|
||||||
Bug Fixes
|
Bug Fixes
|
||||||
---------------------
|
---------------------
|
||||||
|
|
|
@ -190,7 +190,8 @@ abstract class AbstractKnnVectorQuery extends Query {
|
||||||
if (vectorScorer == null) {
|
if (vectorScorer == null) {
|
||||||
return NO_RESULTS;
|
return NO_RESULTS;
|
||||||
}
|
}
|
||||||
HitQueue queue = new HitQueue(k, true);
|
final int queueSize = Math.min(k, Math.toIntExact(acceptIterator.cost()));
|
||||||
|
HitQueue queue = new HitQueue(queueSize, true);
|
||||||
ScoreDoc topDoc = queue.top();
|
ScoreDoc topDoc = queue.top();
|
||||||
int doc;
|
int doc;
|
||||||
while ((doc = acceptIterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
|
while ((doc = acceptIterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
|
||||||
|
|
|
@ -98,7 +98,8 @@ public class DiversifyingChildrenByteKnnVectorQuery extends KnnByteVectorQuery {
|
||||||
parentBitSet,
|
parentBitSet,
|
||||||
query,
|
query,
|
||||||
fi.getVectorSimilarityFunction());
|
fi.getVectorSimilarityFunction());
|
||||||
HitQueue queue = new HitQueue(k, true);
|
final int queueSize = Math.min(k, Math.toIntExact(acceptIterator.cost()));
|
||||||
|
HitQueue queue = new HitQueue(queueSize, true);
|
||||||
ScoreDoc topDoc = queue.top();
|
ScoreDoc topDoc = queue.top();
|
||||||
while (vectorScorer.nextParent() != DocIdSetIterator.NO_MORE_DOCS) {
|
while (vectorScorer.nextParent() != DocIdSetIterator.NO_MORE_DOCS) {
|
||||||
float score = vectorScorer.score();
|
float score = vectorScorer.score();
|
||||||
|
|
|
@ -98,7 +98,8 @@ public class DiversifyingChildrenFloatKnnVectorQuery extends KnnFloatVectorQuery
|
||||||
parentBitSet,
|
parentBitSet,
|
||||||
query,
|
query,
|
||||||
fi.getVectorSimilarityFunction());
|
fi.getVectorSimilarityFunction());
|
||||||
HitQueue queue = new HitQueue(k, true);
|
final int queueSize = Math.min(k, Math.toIntExact(acceptIterator.cost()));
|
||||||
|
HitQueue queue = new HitQueue(queueSize, true);
|
||||||
ScoreDoc topDoc = queue.top();
|
ScoreDoc topDoc = queue.top();
|
||||||
while (vectorScorer.nextParent() != DocIdSetIterator.NO_MORE_DOCS) {
|
while (vectorScorer.nextParent() != DocIdSetIterator.NO_MORE_DOCS) {
|
||||||
float score = vectorScorer.score();
|
float score = vectorScorer.score();
|
||||||
|
|
Loading…
Reference in New Issue