Skip to content

Commit cf2b5c6

Browse files
committed
make centroid oversampling dependent on centroidsPerParentcluster
1 parent e931788 commit cf2b5c6

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@
4141
public class DefaultIVFVectorsReader extends IVFVectorsReader implements OffHeapStats {
4242

4343
// How many extra centroids we need to collect for each visited centroid for hierarchical centroids.
44-
public static final float CENTROID_OVERSAMPLING = 8.0f;
44+
public final float centroidOversampling;
4545

46-
public DefaultIVFVectorsReader(SegmentReadState state, FlatVectorsReader rawVectorsReader) throws IOException {
46+
public DefaultIVFVectorsReader(SegmentReadState state, FlatVectorsReader rawVectorsReader, int centroidsPerParentCluster)
47+
throws IOException {
4748
super(state, rawVectorsReader);
49+
centroidOversampling = (float) centroidsPerParentCluster / 2;
4850
}
4951

5052
CentroidIterator getPostingListPrefetchIterator(CentroidIterator centroidIterator, IndexInput postingListSlice) throws IOException {
@@ -124,7 +126,7 @@ CentroidIterator getCentroidIterator(
124126
quantized,
125127
queryParams,
126128
globalCentroidDp,
127-
visitRatio
129+
visitRatio * centroidOversampling
128130
);
129131
} else {
130132
centroidIterator = getCentroidIteratorNoParent(
@@ -188,13 +190,13 @@ private static CentroidIterator getCentroidIteratorWithParents(
188190
byte[] quantizeQuery,
189191
OptimizedScalarQuantizer.QuantizationResult queryParams,
190192
float globalCentroidDp,
191-
float visitRatio
193+
float centroidRatio
192194
) throws IOException {
193195
// build the three queues we are going to use
194196
final NeighborQueue parentsQueue = new NeighborQueue(numParents, true);
195197
final int maxChildrenSize = centroids.readVInt();
196198
final NeighborQueue currentParentQueue = new NeighborQueue(maxChildrenSize, true);
197-
final int bufferSize = (int) Math.min(Math.max(visitRatio * numCentroids * CENTROID_OVERSAMPLING, 1), numCentroids);
199+
final int bufferSize = (int) Math.min(Math.max(centroidRatio * numCentroids, 1), numCentroids);
198200
final NeighborQueue neighborQueue = new NeighborQueue(bufferSize, true);
199201
// score the parents
200202
final float[] scores = new float[ES92Int7VectorsScorer.BULK_SIZE];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public KnnVectorsWriter fieldsWriter(SegmentWriteState state) throws IOException
110110

111111
@Override
112112
public KnnVectorsReader fieldsReader(SegmentReadState state) throws IOException {
113-
return new DefaultIVFVectorsReader(state, rawVectorFormat.fieldsReader(state));
113+
return new DefaultIVFVectorsReader(state, rawVectorFormat.fieldsReader(state), centroidsPerParentCluster);
114114
}
115115

116116
@Override

0 commit comments

Comments
 (0)