Skip to content

Commit 3d1c6b6

Browse files
committed
account for numVectors for segment size variance being high, more decrease rather than increase
1 parent 571534c commit 3d1c6b6

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ abstract class AbstractIVFKnnVectorQuery extends Query implements QueryProfilerP
6363

6464
static final TopDocs NO_RESULTS = TopDocsCollector.EMPTY_TOPDOCS;
6565
public static final float MIN_VISIT_RATIO_FOR_AFFINITY_ADJUSTMENT = 0.004f;
66-
public static final float MAX_AFFINITY_MULTIPLIER_ADJUSTMENT = 1.5f;
66+
public static final float MAX_AFFINITY_MULTIPLIER_ADJUSTMENT = 1.1f;
6767
public static final float MIN_AFFINITY_MULTIPLIER_ADJUSTMENT = 0.5f;
6868
public static final float MIN_AFFINITY = 0.001f;
69+
public static final float MAX_AFFINITY = 1f;
6970

7071
protected final String field;
7172
protected final float providedVisitRatio;
@@ -209,7 +210,7 @@ public Query rewrite(IndexSearcher indexSearcher) throws IOException {
209210

210211
float adjustedVisitRatio = adjustVisitRatioForSegment(
211212
normalizedAffinityScore,
212-
normalizedAffinityScores[normalizedAffinityScores.length / 2],
213+
normalizedAffinityScores[normalizedAffinityScores.length / 10],
213214
visitRatio
214215
);
215216

@@ -239,10 +240,8 @@ public Query rewrite(IndexSearcher indexSearcher) throws IOException {
239240

240241
private float adjustVisitRatioForSegment(double affinityScore, double affinityThreshold, float visitRatio) {
241242
// for high affinity scores, increase visited ratio
242-
float maxAdjustment = visitRatio * MAX_AFFINITY_MULTIPLIER_ADJUSTMENT;
243243
if (affinityScore > affinityThreshold) {
244-
int adjustment = (int) Math.ceil((affinityScore - affinityThreshold) * maxAdjustment);
245-
return Math.min(visitRatio * adjustment, visitRatio * MAX_AFFINITY_MULTIPLIER_ADJUSTMENT);
244+
return Math.min(visitRatio * MAX_AFFINITY_MULTIPLIER_ADJUSTMENT, MAX_AFFINITY);
246245
}
247246

248247
// for low affinity scores, decrease visited ratio
@@ -308,7 +307,7 @@ private List<SegmentAffinity> calculateSegmentAffinities(List<LeafReaderContext>
308307
double centroidDensity = (double) numCentroids / numVectors;
309308

310309
// TODO : we may want to include some actual centroids' scores for higher quality estimate
311-
double affinityScore = centroidsScore * (1 + centroidDensity);
310+
double affinityScore = centroidsScore * Math.log10(numVectors) * (1 + centroidDensity);
312311
segmentAffinities.add(new SegmentAffinity(context, affinityScore, numVectors));
313312
} else {
314313
segmentAffinities.add(new SegmentAffinity(context, Float.NaN, 0));

0 commit comments

Comments
 (0)