Skip to content

Commit ee46e00

Browse files
committed
Add a feature flag for the new formats
1 parent cc414b0 commit ee46e00

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.apache.lucene.codecs.hnsw.FlatVectorsWriter;
1616
import org.apache.lucene.index.SegmentReadState;
1717
import org.apache.lucene.index.SegmentWriteState;
18+
import org.elasticsearch.common.util.FeatureFlag;
1819
import org.elasticsearch.index.codec.vectors.AbstractFlatVectorsFormat;
1920
import org.elasticsearch.index.codec.vectors.DirectIOCapableFlatVectorsFormat;
2021
import org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper;
@@ -24,6 +25,8 @@
2425

2526
public class ES93GenericFlatVectorsFormat extends AbstractFlatVectorsFormat {
2627

28+
public static final FeatureFlag ES93_VECTOR_FORMATS = new FeatureFlag("es93_vector_formats");
29+
2730
static final String NAME = "ES93GenericFlatVectorsFormat";
2831
static final String VECTOR_FORMAT_INFO_EXTENSION = "vfi";
2932
static final String META_CODEC_NAME = "ES93GenericFlatVectorsFormatMeta";

server/src/main/java/org/elasticsearch/index/mapper/MapperFeatures.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
import org.elasticsearch.features.FeatureSpecification;
1313
import org.elasticsearch.features.NodeFeature;
14+
import org.elasticsearch.index.codec.vectors.es93.ES93GenericFlatVectorsFormat;
1415

16+
import java.util.HashSet;
1517
import java.util.Set;
1618

1719
import static org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper.RESCORE_VECTOR_QUANTIZED_VECTOR_MAPPING;
@@ -63,7 +65,7 @@ public class MapperFeatures implements FeatureSpecification {
6365

6466
@Override
6567
public Set<NodeFeature> getTestFeatures() {
66-
return Set.of(
68+
var features = Set.of(
6769
RangeFieldMapper.DATE_RANGE_INDEXING_FIX,
6870
IgnoredSourceFieldMapper.DONT_EXPAND_DOTS_IN_IGNORED_SOURCE,
6971
SourceFieldMapper.REMOVE_SYNTHETIC_SOURCE_ONLY_VALIDATION,
@@ -102,8 +104,12 @@ public Set<NodeFeature> getTestFeatures() {
102104
PROVIDE_INDEX_SORT_SETTING_DEFAULTS,
103105
INDEX_MAPPING_IGNORE_DYNAMIC_BEYOND_FIELD_NAME_LIMIT,
104106
EXCLUDE_VECTORS_DOCVALUE_BUGFIX,
105-
BASE64_DENSE_VECTORS,
106-
HNSW_BFLOAT16_ON_DISK_RESCORING
107+
BASE64_DENSE_VECTORS
107108
);
109+
if (ES93GenericFlatVectorsFormat.ES93_VECTOR_FORMATS.isEnabled()) {
110+
features = new HashSet<>(features);
111+
features.add(HNSW_BFLOAT16_ON_DISK_RESCORING);
112+
}
113+
return features;
108114
}
109115
}

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@
5454
import org.elasticsearch.index.codec.vectors.ES815BitFlatVectorFormat;
5555
import org.elasticsearch.index.codec.vectors.ES815HnswBitVectorsFormat;
5656
import org.elasticsearch.index.codec.vectors.diskbbq.ES920DiskBBQVectorsFormat;
57+
import org.elasticsearch.index.codec.vectors.es818.ES818BinaryQuantizedVectorsFormat;
58+
import org.elasticsearch.index.codec.vectors.es818.ES818HnswBinaryQuantizedVectorsFormat;
5759
import org.elasticsearch.index.codec.vectors.es93.ES93BinaryQuantizedVectorsFormat;
60+
import org.elasticsearch.index.codec.vectors.es93.ES93GenericFlatVectorsFormat;
5861
import org.elasticsearch.index.codec.vectors.es93.ES93HnswBinaryQuantizedVectorsFormat;
5962
import org.elasticsearch.index.codec.vectors.es93.ES93HnswVectorsFormat;
6063
import org.elasticsearch.index.fielddata.FieldDataContext;
@@ -238,7 +241,8 @@ public static class Builder extends FieldMapper.Builder {
238241

239242
private final Parameter<ElementType> elementType = new Parameter<>("element_type", false, () -> ElementType.FLOAT, (n, c, o) -> {
240243
ElementType elementType = namesToElementType.get((String) o);
241-
if (elementType == null) {
244+
if (elementType == null
245+
|| (elementType == ElementType.BFLOAT16 && ES93GenericFlatVectorsFormat.ES93_VECTOR_FORMATS.isEnabled() == false)) {
242246
throw new MapperParsingException("invalid element_type [" + o + "]; available types are " + namesToElementType.keySet());
243247
}
244248
return elementType;
@@ -2145,7 +2149,14 @@ public static class HnswIndexOptions extends DenseVectorIndexOptions {
21452149

21462150
@Override
21472151
public KnnVectorsFormat getVectorsFormat(ElementType elementType) {
2148-
return new ES93HnswVectorsFormat(m, efConstruction, elementType);
2152+
if (ES93GenericFlatVectorsFormat.ES93_VECTOR_FORMATS.isEnabled()) {
2153+
return new ES93HnswVectorsFormat(m, efConstruction, elementType);
2154+
} else {
2155+
if (elementType == ElementType.BIT) {
2156+
return new ES815HnswBitVectorsFormat(m, efConstruction);
2157+
}
2158+
return new Lucene99HnswVectorsFormat(m, efConstruction, 1, null);
2159+
}
21492160
}
21502161

21512162
@Override
@@ -2220,7 +2231,9 @@ public BBQHnswIndexOptions(int m, int efConstruction, boolean onDiskRescore, Res
22202231
@Override
22212232
KnnVectorsFormat getVectorsFormat(ElementType elementType) {
22222233
assert elementType == ElementType.FLOAT || elementType == ElementType.BFLOAT16;
2223-
return new ES93HnswBinaryQuantizedVectorsFormat(m, efConstruction, elementType, onDiskRescore);
2234+
return ES93GenericFlatVectorsFormat.ES93_VECTOR_FORMATS.isEnabled()
2235+
? new ES93HnswBinaryQuantizedVectorsFormat(m, efConstruction, elementType, onDiskRescore)
2236+
: new ES818HnswBinaryQuantizedVectorsFormat(m, efConstruction);
22242237
}
22252238

22262239
@Override
@@ -2286,7 +2299,9 @@ static class BBQFlatIndexOptions extends QuantizedIndexOptions {
22862299
@Override
22872300
KnnVectorsFormat getVectorsFormat(ElementType elementType) {
22882301
assert elementType == ElementType.FLOAT || elementType == ElementType.BFLOAT16;
2289-
return new ES93BinaryQuantizedVectorsFormat(elementType, false);
2302+
return ES93GenericFlatVectorsFormat.ES93_VECTOR_FORMATS.isEnabled()
2303+
? new ES93BinaryQuantizedVectorsFormat(elementType, false)
2304+
: new ES818BinaryQuantizedVectorsFormat();
22902305
}
22912306

22922307
@Override

0 commit comments

Comments
 (0)