Skip to content

Commit 1583fa4

Browse files
committed
two fixes
1 parent da21795 commit 1583fa4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

server/src/main/java/org/elasticsearch/search/vectors/AbstractIVFKnnVectorQuery.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public Query rewrite(IndexSearcher indexSearcher) throws IOException {
120120
// we need to ensure we are getting at least 2*k results to ensure we cover overspill duplicates
121121
// TODO move the logic for automatically adjusting percentages to the query, so we can only pass
122122
// 2k to the collector.
123-
KnnCollectorManager knnCollectorManager = getKnnCollectorManager(Math.max(Math.round(2f * k), numCands), indexSearcher);
123+
KnnCollectorManager knnCollectorManager = getKnnCollectorManager(Math.round(2f * k), indexSearcher);
124124
TaskExecutor taskExecutor = indexSearcher.getTaskExecutor();
125125
List<LeafReaderContext> leafReaderContexts = reader.leaves();
126126

@@ -136,7 +136,9 @@ public Query rewrite(IndexSearcher indexSearcher) throws IOException {
136136
final float visitRatio;
137137
if (providedVisitRatio == 0.0f) {
138138
// dynamically set the percentage
139-
float expected = (float) Math.round(Math.log10(totalVectors) * Math.log10(totalVectors) * (numCands));
139+
float expected = (float) Math.round(
140+
Math.log10(totalVectors) * Math.log10(totalVectors) * (Math.min(10_000, Math.max(numCands, 5 * k)))
141+
);
140142
visitRatio = expected / totalVectors;
141143
} else {
142144
visitRatio = providedVisitRatio;

0 commit comments

Comments
 (0)