Skip to content

Commit 26a4374

Browse files
committed
Correct bug with seeded vector queries with incorrect entrypoint ids
1 parent e432161 commit 26a4374

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lucene/core/src/java/org/apache/lucene/search/SeededKnnVectorQuery.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,11 @@ private static class TopDocsDISI extends DocIdSetIterator {
229229
private final int[] sortedDocIds;
230230
private int idx = -1;
231231

232-
private TopDocsDISI(TopDocs topDocs) {
232+
private TopDocsDISI(TopDocs topDocs, LeafReaderContext ctx) {
233233
sortedDocIds = new int[topDocs.scoreDocs.length];
234234
for (int i = 0; i < topDocs.scoreDocs.length; i++) {
235-
sortedDocIds[i] = topDocs.scoreDocs[i].doc;
235+
// Remove the doc base as added by the collector
236+
sortedDocIds[i] = topDocs.scoreDocs[i].doc - ctx.docBase;
236237
}
237238
Arrays.sort(sortedDocIds);
238239
}
@@ -311,7 +312,8 @@ public KnnCollector newCollector(
311312
}
312313
// Most underlying iterators are indexed, so we can map the seed docs to the vector docs
313314
if (vectorIterator instanceof KnnVectorValues.DocIndexIterator indexIterator) {
314-
DocIdSetIterator seedDocs = new MappedDISI(indexIterator, new TopDocsDISI(seedTopDocs));
315+
DocIdSetIterator seedDocs =
316+
new MappedDISI(indexIterator, new TopDocsDISI(seedTopDocs, ctx));
315317
return knnCollectorManager.newCollector(
316318
visitLimit, new KnnSearchStrategy.Seeded(seedDocs, seedTopDocs.scoreDocs.length), ctx);
317319
}

0 commit comments

Comments
 (0)