Skip to content

Commit eb20ffa

Browse files
authored
[DiskBBQ] do not build empty priority queue (#138434)
I noticed in some of our internal benchmarks that this cal fail with error: ``` 'search_phase_execution_exception', 'maxSize must be > 0 and < 2147483630; got: 0', maxSize must be > 0 and < 2147483630; got: 0) ``` In order to prevent that let's add a fail safe. We should later investigate how we ended up in this situation as I would expect we should bail out earlier.
1 parent 790810e commit eb20ffa

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

server/src/main/java/org/elasticsearch/index/codec/vectors/diskbbq/next/ESNextDiskBBQVectorsReader.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,20 @@ private static CentroidIterator getCentroidIteratorWithParents(
324324
final NeighborQueue currentParentQueue = new NeighborQueue(maxChildrenSize, true);
325325
final int bufferSize = (int) Math.min(Math.max(centroidRatio * numCentroids, 1), numCentroids);
326326
final int numCentroidsFiltered = acceptCentroids == null ? numCentroids : acceptCentroids.cardinality();
327+
if (numCentroidsFiltered == 0) {
328+
// TODO maybe this makes CentroidIterator polymorphic?
329+
return new CentroidIterator() {
330+
@Override
331+
public boolean hasNext() {
332+
return false;
333+
}
334+
335+
@Override
336+
public CentroidOffsetAndLength nextPostingListOffsetAndLength() {
337+
return null;
338+
}
339+
};
340+
}
327341
final float[] scores = new float[ES92Int7VectorsScorer.BULK_SIZE];
328342
final NeighborQueue neighborQueue;
329343
if (acceptCentroids != null && numCentroidsFiltered <= bufferSize) {

server/src/test/java/org/elasticsearch/index/codec/vectors/diskbbq/next/ESNextDiskBBQVectorsFormatTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.lucene.index.VectorEncoding;
3030
import org.apache.lucene.index.VectorSimilarityFunction;
3131
import org.apache.lucene.search.AcceptDocs;
32+
import org.apache.lucene.search.DocIdSetIterator;
3233
import org.apache.lucene.search.KnnCollector;
3334
import org.apache.lucene.search.TopDocs;
3435
import org.apache.lucene.search.TopKnnCollector;
@@ -382,6 +383,13 @@ private void doRestrictiveFilter(boolean dense) throws IOException {
382383
uniqueDocIds.add(topDocs.scoreDocs[i].doc);
383384
}
384385
assertEquals(matchingDocs, uniqueDocIds.size());
386+
// match no docs
387+
leafReader.searchNearestVectors(
388+
"f",
389+
vector,
390+
new TopKnnCollector(2, Integer.MAX_VALUE),
391+
AcceptDocs.fromIteratorSupplier(DocIdSetIterator::empty, leafReader.getLiveDocs(), leafReader.maxDoc())
392+
);
385393
}
386394
}
387395
}

0 commit comments

Comments
 (0)