Skip to content

Commit 391e2b7

Browse files
committed
Use in disk_bbq
1 parent e6a2649 commit 391e2b7

12 files changed

+38
-715
lines changed

server/src/main/java/org/elasticsearch/index/codec/vectors/diskbbq/ES920DiskBBQVectorsFormat.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.index.codec.vectors.DirectIOCapableFlatVectorsFormat;
1919
import org.elasticsearch.index.codec.vectors.OptimizedScalarQuantizer;
2020
import org.elasticsearch.index.codec.vectors.es93.DirectIOCapableLucene99FlatVectorsFormat;
21+
import org.elasticsearch.index.codec.vectors.es93.ES93BFloat16FlatVectorsFormat;
2122

2223
import java.io.IOException;
2324
import java.util.Map;
@@ -58,12 +59,17 @@ public class ES920DiskBBQVectorsFormat extends KnnVectorsFormat {
5859
public static final int VERSION_DIRECT_IO = 1;
5960
public static final int VERSION_CURRENT = VERSION_DIRECT_IO;
6061

61-
private static final DirectIOCapableFlatVectorsFormat rawVectorFormat = new DirectIOCapableLucene99FlatVectorsFormat(
62+
private static final DirectIOCapableFlatVectorsFormat float32VectorFormat = new DirectIOCapableLucene99FlatVectorsFormat(
63+
FlatVectorScorerUtil.getLucene99FlatVectorsScorer()
64+
);
65+
private static final DirectIOCapableFlatVectorsFormat bfloat16VectorFormat = new ES93BFloat16FlatVectorsFormat(
6266
FlatVectorScorerUtil.getLucene99FlatVectorsScorer()
6367
);
6468
private static final Map<String, DirectIOCapableFlatVectorsFormat> supportedFormats = Map.of(
65-
rawVectorFormat.getName(),
66-
rawVectorFormat
69+
float32VectorFormat.getName(),
70+
float32VectorFormat,
71+
bfloat16VectorFormat.getName(),
72+
bfloat16VectorFormat
6773
);
6874

6975
// This dynamically sets the cluster probe based on the `k` requested and the number of clusters.
@@ -79,12 +85,13 @@ public class ES920DiskBBQVectorsFormat extends KnnVectorsFormat {
7985
private final int vectorPerCluster;
8086
private final int centroidsPerParentCluster;
8187
private final boolean useDirectIO;
88+
private final DirectIOCapableFlatVectorsFormat rawVectorFormat;
8289

8390
public ES920DiskBBQVectorsFormat(int vectorPerCluster, int centroidsPerParentCluster) {
84-
this(vectorPerCluster, centroidsPerParentCluster, false);
91+
this(vectorPerCluster, centroidsPerParentCluster, false, false);
8592
}
8693

87-
public ES920DiskBBQVectorsFormat(int vectorPerCluster, int centroidsPerParentCluster, boolean useDirectIO) {
94+
public ES920DiskBBQVectorsFormat(int vectorPerCluster, int centroidsPerParentCluster, boolean useDirectIO, boolean useBFloat16) {
8895
super(NAME);
8996
if (vectorPerCluster < MIN_VECTORS_PER_CLUSTER || vectorPerCluster > MAX_VECTORS_PER_CLUSTER) {
9097
throw new IllegalArgumentException(
@@ -109,6 +116,7 @@ public ES920DiskBBQVectorsFormat(int vectorPerCluster, int centroidsPerParentClu
109116
this.vectorPerCluster = vectorPerCluster;
110117
this.centroidsPerParentCluster = centroidsPerParentCluster;
111118
this.useDirectIO = useDirectIO;
119+
this.rawVectorFormat = useBFloat16 ? bfloat16VectorFormat : float32VectorFormat;
112120
}
113121

114122
/** Constructs a format using the given graph construction parameters and scalar quantization. */

server/src/main/java/org/elasticsearch/index/codec/vectors/es93/ES93BFloat16FlatVectorsFormat.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
/*
2-
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3-
* or more contributor license agreements. Licensed under the "Elastic License
4-
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5-
* Public License v 1"; you may not use this file except in compliance with, at
6-
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7-
* License v3.0 only", or the "Server Side Public License, v 1".
8-
*/
9-
101
/*
112
* @notice
123
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -24,7 +15,7 @@
2415
* See the License for the specific language governing permissions and
2516
* limitations under the License.
2617
*
27-
* Modifications copyright (C) 2024 Elasticsearch B.V.
18+
* Modifications copyright (C) 2025 Elasticsearch B.V.
2819
*/
2920
package org.elasticsearch.index.codec.vectors.es93;
3021

server/src/main/java/org/elasticsearch/index/codec/vectors/es93/ES93BFloat16FlatVectorsReader.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
/*
2-
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3-
* or more contributor license agreements. Licensed under the "Elastic License
4-
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5-
* Public License v 1"; you may not use this file except in compliance with, at
6-
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7-
* License v3.0 only", or the "Server Side Public License, v 1".
8-
*/
9-
101
/*
112
* @notice
123
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -24,7 +15,7 @@
2415
* See the License for the specific language governing permissions and
2516
* limitations under the License.
2617
*
27-
* Modifications copyright (C) 2024 Elasticsearch B.V.
18+
* Modifications copyright (C) 2025 Elasticsearch B.V.
2819
*/
2920
package org.elasticsearch.index.codec.vectors.es93;
3021

server/src/main/java/org/elasticsearch/index/codec/vectors/es93/ES93BFloat16FlatVectorsWriter.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
/*
2-
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3-
* or more contributor license agreements. Licensed under the "Elastic License
4-
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5-
* Public License v 1"; you may not use this file except in compliance with, at
6-
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7-
* License v3.0 only", or the "Server Side Public License, v 1".
8-
*/
9-
101
/*
112
* @notice
123
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -24,7 +15,7 @@
2415
* See the License for the specific language governing permissions and
2516
* limitations under the License.
2617
*
27-
* Modifications copyright (C) 2024 Elasticsearch B.V.
18+
* Modifications copyright (C) 2025 Elasticsearch B.V.
2819
*/
2920
package org.elasticsearch.index.codec.vectors.es93;
3021

server/src/main/java/org/elasticsearch/index/codec/vectors/es93/ES93BinaryQuantizedVectorsFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*
18-
* Modifications copyright (C) 2024 Elasticsearch B.V.
18+
* Modifications copyright (C) 2025 Elasticsearch B.V.
1919
*/
2020
package org.elasticsearch.index.codec.vectors.es93;
2121

server/src/main/java/org/elasticsearch/index/codec/vectors/es93/ES93HnswBinaryQuantizedVectorsFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*
18-
* Modifications copyright (C) 2024 Elasticsearch B.V.
18+
* Modifications copyright (C) 2025 Elasticsearch B.V.
1919
*/
2020
package org.elasticsearch.index.codec.vectors.es93;
2121

server/src/main/java/org/elasticsearch/index/codec/vectors/es93/OffHeapBFloat16VectorValues.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
/*
2-
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3-
* or more contributor license agreements. Licensed under the "Elastic License
4-
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5-
* Public License v 1"; you may not use this file except in compliance with, at
6-
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7-
* License v3.0 only", or the "Server Side Public License, v 1".
8-
*/
9-
101
/*
112
* @notice
123
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -24,7 +15,7 @@
2415
* See the License for the specific language governing permissions and
2516
* limitations under the License.
2617
*
27-
* Modifications copyright (C) 2024 Elasticsearch B.V.
18+
* Modifications copyright (C) 2025 Elasticsearch B.V.
2819
*/
2920
package org.elasticsearch.index.codec.vectors.es93;
3021

server/src/main/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2199,7 +2199,8 @@ KnnVectorsFormat getVectorsFormat(ElementType elementType) {
21992199
return new ES920DiskBBQVectorsFormat(
22002200
clusterSize,
22012201
ES920DiskBBQVectorsFormat.DEFAULT_CENTROIDS_PER_PARENT_CLUSTER,
2202-
onDiskRescore
2202+
onDiskRescore,
2203+
false
22032204
);
22042205
}
22052206

server/src/main/resources/META-INF/services/org.apache.lucene.codecs.KnnVectorsFormat

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ org.elasticsearch.index.codec.vectors.es816.ES816BinaryQuantizedVectorsFormat
77
org.elasticsearch.index.codec.vectors.es816.ES816HnswBinaryQuantizedVectorsFormat
88
org.elasticsearch.index.codec.vectors.es818.ES818BinaryQuantizedVectorsFormat
99
org.elasticsearch.index.codec.vectors.es818.ES818HnswBinaryQuantizedVectorsFormat
10-
org.elasticsearch.index.codec.vectors.es93.ES92BinaryQuantizedBFloat16VectorsFormat
11-
org.elasticsearch.index.codec.vectors.es93.ES92HnswBinaryQuantizedBFloat16VectorsFormat
1210
org.elasticsearch.index.codec.vectors.diskbbq.ES920DiskBBQVectorsFormat
1311
org.elasticsearch.index.codec.vectors.diskbbq.next.ESNextDiskBBQVectorsFormat
1412
org.elasticsearch.index.codec.vectors.es93.ES93BinaryQuantizedVectorsFormat

server/src/test/java/org/elasticsearch/index/codec/vectors/diskbbq/ES920DiskBBQVectorsFormatTests.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
*/
99
package org.elasticsearch.index.codec.vectors.diskbbq;
1010

11+
import com.carrotsearch.randomizedtesting.annotations.Name;
12+
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
1113
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
1214

1315
import org.apache.lucene.codecs.Codec;
@@ -62,21 +64,34 @@ public class ES920DiskBBQVectorsFormatTests extends BaseKnnVectorsFormatTestCase
6264
}
6365
KnnVectorsFormat format;
6466

67+
private boolean useBFloat16;
68+
69+
@ParametersFactory
70+
public static Iterable<Object[]> params() {
71+
return List.of(new Object[] { false }, new Object[] { true });
72+
}
73+
74+
public ES920DiskBBQVectorsFormatTests(@Name("useBFloat16") boolean useBFloat16) {
75+
this.useBFloat16 = useBFloat16;
76+
}
77+
6578
@Before
6679
@Override
6780
public void setUp() throws Exception {
6881
if (rarely()) {
6982
format = new ES920DiskBBQVectorsFormat(
7083
random().nextInt(2 * MIN_VECTORS_PER_CLUSTER, ES920DiskBBQVectorsFormat.MAX_VECTORS_PER_CLUSTER),
7184
random().nextInt(8, ES920DiskBBQVectorsFormat.MAX_CENTROIDS_PER_PARENT_CLUSTER),
72-
random().nextBoolean()
85+
random().nextBoolean(),
86+
useBFloat16
7387
);
7488
} else {
7589
// run with low numbers to force many clusters with parents
7690
format = new ES920DiskBBQVectorsFormat(
7791
random().nextInt(MIN_VECTORS_PER_CLUSTER, 2 * MIN_VECTORS_PER_CLUSTER),
7892
random().nextInt(MIN_CENTROIDS_PER_PARENT_CLUSTER, 8),
79-
random().nextBoolean()
93+
random().nextBoolean(),
94+
useBFloat16
8095
);
8196
}
8297
super.setUp();

0 commit comments

Comments
 (0)