Skip to content

Commit 7c0d2eb

Browse files
Adjust default params for Cagra Index build (#136650)
Before: m=16, efConstruction=128 Now: m=10, efConstruction=16 This gives equivalent recall/precision to CPU default params
1 parent 63c5063 commit 7c0d2eb

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
lines changed

docs/changelog/136650.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 136650
2+
summary: Adjust default params for Cagra Index build
3+
area: Vector Search
4+
type: enhancement
5+
issues: []

x-pack/plugin/gpu/src/main/java/org/elasticsearch/xpack/gpu/GPUPlugin.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,21 @@ private static KnnVectorsFormat getVectorsFormat(DenseVectorFieldMapper.DenseVec
9494
if (indexOptions.getType() == DenseVectorFieldMapper.VectorIndexType.HNSW) {
9595
DenseVectorFieldMapper.HnswIndexOptions hnswIndexOptions = (DenseVectorFieldMapper.HnswIndexOptions) indexOptions;
9696
int efConstruction = hnswIndexOptions.efConstruction();
97+
int m = hnswIndexOptions.m();
9798
if (efConstruction == HnswGraphBuilder.DEFAULT_BEAM_WIDTH) {
98-
efConstruction = ES92GpuHnswVectorsFormat.DEFAULT_BEAM_WIDTH; // default value for GPU graph construction is 128
99+
m = ES92GpuHnswVectorsFormat.DEFAULT_MAX_CONN;
100+
efConstruction = ES92GpuHnswVectorsFormat.DEFAULT_BEAM_WIDTH; // default value for GPU graph construction
99101
}
100-
return new ES92GpuHnswVectorsFormat(hnswIndexOptions.m(), efConstruction);
102+
return new ES92GpuHnswVectorsFormat(m, efConstruction);
101103
} else if (indexOptions.getType() == DenseVectorFieldMapper.VectorIndexType.INT8_HNSW) {
102104
DenseVectorFieldMapper.Int8HnswIndexOptions int8HnswIndexOptions = (DenseVectorFieldMapper.Int8HnswIndexOptions) indexOptions;
103105
int efConstruction = int8HnswIndexOptions.efConstruction();
106+
int m = int8HnswIndexOptions.m();
104107
if (efConstruction == HnswGraphBuilder.DEFAULT_BEAM_WIDTH) {
105-
efConstruction = ES92GpuHnswVectorsFormat.DEFAULT_BEAM_WIDTH; // default value for GPU graph construction is 128
108+
m = ES92GpuHnswVectorsFormat.DEFAULT_MAX_CONN;
109+
efConstruction = ES92GpuHnswVectorsFormat.DEFAULT_BEAM_WIDTH; // default value for GPU graph construction
106110
}
107-
return new ES92GpuHnswSQVectorsFormat(
108-
int8HnswIndexOptions.m(),
109-
efConstruction,
110-
int8HnswIndexOptions.confidenceInterval(),
111-
7,
112-
false
113-
);
111+
return new ES92GpuHnswSQVectorsFormat(m, efConstruction, int8HnswIndexOptions.confidenceInterval(), 7, false);
114112
} else {
115113
throw new IllegalArgumentException(
116114
"GPU vector indexing is not supported on this vector type: [" + indexOptions.getType() + "]"

x-pack/plugin/gpu/src/main/java/org/elasticsearch/xpack/gpu/codec/ES92GpuHnswVectorsFormat.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public class ES92GpuHnswVectorsFormat extends KnnVectorsFormat {
3636
static final String LUCENE99_HNSW_VECTOR_INDEX_EXTENSION = "vex";
3737
static final int LUCENE99_VERSION_CURRENT = VERSION_GROUPVARINT;
3838

39-
static final int DEFAULT_MAX_CONN = 16; // graph degree
40-
public static final int DEFAULT_BEAM_WIDTH = 128; // intermediate graph degree
39+
public static final int DEFAULT_MAX_CONN = 10; // graph degree
40+
public static final int DEFAULT_BEAM_WIDTH = 16; // intermediate graph degree
4141
static final int MIN_NUM_VECTORS_FOR_GPU_BUILD = 2;
4242

4343
private static final FlatVectorsFormat flatVectorsFormat = new Lucene99FlatVectorsFormat(

x-pack/plugin/gpu/src/main/java/org/elasticsearch/xpack/gpu/codec/ES92GpuHnswVectorsWriter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ private CagraIndex buildGPUIndex(
323323
.withCagraGraphBuildAlgo(CagraIndexParams.CagraGraphBuildAlgo.NN_DESCENT)
324324
.withGraphDegree(M)
325325
.withIntermediateGraphDegree(beamWidth)
326+
.withNNDescentNumIterations(5)
326327
.withMetric(distanceType)
327328
.build();
328329

x-pack/plugin/gpu/src/test/java/org/elasticsearch/xpack/gpu/codec/GPUDenseVectorFieldMapperTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void testKnnVectorsFormat() throws IOException {
4444
// TODO improve test with custom parameters
4545
KnnVectorsFormat knnVectorsFormat = getKnnVectorsFormat("hnsw");
4646
String expectedStr = "Lucene99HnswVectorsFormat(name=Lucene99HnswVectorsFormat, "
47-
+ "maxConn=16, beamWidth=128, flatVectorFormat=Lucene99FlatVectorsFormat)";
47+
+ "maxConn=10, beamWidth=16, flatVectorFormat=Lucene99FlatVectorsFormat)";
4848
assertEquals(expectedStr, knnVectorsFormat.toString());
4949
}
5050

@@ -53,7 +53,7 @@ public void testKnnQuantizedHNSWVectorsFormat() throws IOException {
5353
// TOD improve the test with custom parameters
5454
KnnVectorsFormat knnVectorsFormat = getKnnVectorsFormat("int8_hnsw");
5555
String expectedStr = "Lucene99HnswVectorsFormat(name=Lucene99HnswVectorsFormat, "
56-
+ "maxConn=16, beamWidth=128, flatVectorFormat=ES814ScalarQuantizedVectorsFormat";
56+
+ "maxConn=10, beamWidth=16, flatVectorFormat=ES814ScalarQuantizedVectorsFormat";
5757
assertTrue(knnVectorsFormat.toString().startsWith(expectedStr));
5858
}
5959

0 commit comments

Comments
 (0)