Skip to content

Commit da21795

Browse files
committed
make expected depend on numVectors
1 parent 5b8443c commit da21795

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

server/src/main/java/org/elasticsearch/index/codec/vectors/IVFVectorsReader.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,20 +229,18 @@ public final void search(String field, float[] target, KnnCollector knnCollector
229229
}
230230

231231
FieldEntry entry = fields.get(fieldInfo.number);
232-
long maxVectorVisited;
233232
if (visitRatio == DYNAMIC_VISIT_RATIO) {
234233
// empirically based, and a good dynamic to get decent recall while scaling a la "efSearch"
235234
// scaling by the number of vectors vs. the nearest neighbors requested
236235
// not perfect, but a comparative heuristic.
237236
// TODO: we might want to consider the density of the centroids as experiments shows that for fewer vectors per centroid,
238237
// the least vectors we need to score to get a good recall.
239-
maxVectorVisited = Math.round(1.75f * Math.log10(knnCollector.k()) * Math.log10(knnCollector.k()) * (knnCollector.k()));
238+
float estimated = Math.round(Math.log10(numVectors) * Math.log10(numVectors) * (knnCollector.k()));
240239
// clip so we visit at least one vector
241-
maxVectorVisited = Math.max(maxVectorVisited, 1L);
242-
} else {
243-
// we account for soar vectors here. We can potentially visit a vector twice so we multiply by 2 here.
244-
maxVectorVisited = (long) (2.0 * visitRatio * numVectors);
240+
visitRatio = estimated / numVectors;
245241
}
242+
// we account for soar vectors here. We can potentially visit a vector twice so we multiply by 2 here.
243+
long maxVectorVisited = (long) (2.0 * visitRatio * numVectors);
246244
CentroidIterator centroidIterator = getCentroidIterator(fieldInfo, entry.numCentroids, entry.centroidSlice(ivfCentroids), target);
247245
PostingVisitor scorer = getPostingVisitor(fieldInfo, entry.postingListSlice(ivfClusters), target, acceptDocs);
248246

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ 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(1.75f * Math.log10(numCands) * Math.log10(numCands) * (numCands));
139+
float expected = (float) Math.round(Math.log10(totalVectors) * Math.log10(totalVectors) * (numCands));
140140
visitRatio = expected / totalVectors;
141141
} else {
142142
visitRatio = providedVisitRatio;

0 commit comments

Comments
 (0)