Skip to content

Commit b5b4e1f

Browse files
committed
Revert "Default new semantic_text fields to use BBQ when models are compatible (elastic#126629)"
This reverts commit a72883e.
1 parent 72b4ed2 commit b5b4e1f

File tree

7 files changed

+37
-218
lines changed

7 files changed

+37
-218
lines changed

docs/changelog/126629.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

server/src/main/java/org/elasticsearch/index/IndexVersions.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ private static Version parseUnchecked(String version) {
160160
public static final IndexVersion SYNTHETIC_SOURCE_STORE_ARRAYS_NATIVELY_SCALED_FLOAT = def(9_020_0_00, Version.LUCENE_10_1_0);
161161
public static final IndexVersion USE_LUCENE101_POSTINGS_FORMAT = def(9_021_0_00, Version.LUCENE_10_1_0);
162162
public static final IndexVersion UPGRADE_TO_LUCENE_10_2_0 = def(9_022_00_0, Version.LUCENE_10_2_0);
163-
public static final IndexVersion SEMANTIC_TEXT_DEFAULTS_TO_BBQ = def(9_023_0_00, Version.LUCENE_10_2_0);
164163
/*
165164
* STOP! READ THIS FIRST! No, really,
166165
* ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _

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

Lines changed: 20 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,6 @@ public Builder elementType(ElementType elementType) {
290290
return this;
291291
}
292292

293-
public Builder indexOptions(IndexOptions indexOptions) {
294-
this.indexOptions.setValue(indexOptions);
295-
return this;
296-
}
297-
298293
@Override
299294
public DenseVectorFieldMapper build(MapperBuilderContext context) {
300295
// Validate again here because the dimensions or element type could have been set programmatically,
@@ -1226,7 +1221,7 @@ public final String toString() {
12261221
public abstract VectorSimilarityFunction vectorSimilarityFunction(IndexVersion indexVersion, ElementType elementType);
12271222
}
12281223

1229-
public abstract static class IndexOptions implements ToXContent {
1224+
abstract static class IndexOptions implements ToXContent {
12301225
final VectorIndexType type;
12311226

12321227
IndexOptions(VectorIndexType type) {
@@ -1235,36 +1230,21 @@ public abstract static class IndexOptions implements ToXContent {
12351230

12361231
abstract KnnVectorsFormat getVectorsFormat(ElementType elementType);
12371232

1238-
public boolean validate(ElementType elementType, int dim, boolean throwOnError) {
1239-
return validateElementType(elementType, throwOnError) && validateDimension(dim, throwOnError);
1240-
}
1241-
1242-
public boolean validateElementType(ElementType elementType) {
1243-
return validateElementType(elementType, true);
1244-
}
1245-
1246-
final boolean validateElementType(ElementType elementType, boolean throwOnError) {
1247-
boolean validElementType = type.supportsElementType(elementType);
1248-
if (throwOnError && validElementType == false) {
1233+
final void validateElementType(ElementType elementType) {
1234+
if (type.supportsElementType(elementType) == false) {
12491235
throw new IllegalArgumentException(
12501236
"[element_type] cannot be [" + elementType.toString() + "] when using index type [" + type + "]"
12511237
);
12521238
}
1253-
return validElementType;
12541239
}
12551240

12561241
abstract boolean updatableTo(IndexOptions update);
12571242

1258-
public boolean validateDimension(int dim) {
1259-
return validateDimension(dim, true);
1260-
}
1261-
1262-
public boolean validateDimension(int dim, boolean throwOnError) {
1263-
boolean supportsDimension = type.supportsDimension(dim);
1264-
if (throwOnError && supportsDimension == false) {
1265-
throw new IllegalArgumentException(type.name + " only supports even dimensions; provided=" + dim);
1243+
public void validateDimension(int dim) {
1244+
if (type.supportsDimension(dim)) {
1245+
return;
12661246
}
1267-
return supportsDimension;
1247+
throw new IllegalArgumentException(type.name + " only supports even dimensions; provided=" + dim);
12681248
}
12691249

12701250
abstract boolean doEquals(IndexOptions other);
@@ -1767,12 +1747,12 @@ boolean updatableTo(IndexOptions update) {
17671747

17681748
}
17691749

1770-
public static class Int8HnswIndexOptions extends QuantizedIndexOptions {
1750+
static class Int8HnswIndexOptions extends QuantizedIndexOptions {
17711751
private final int m;
17721752
private final int efConstruction;
17731753
private final Float confidenceInterval;
17741754

1775-
public Int8HnswIndexOptions(int m, int efConstruction, Float confidenceInterval, RescoreVector rescoreVector) {
1755+
Int8HnswIndexOptions(int m, int efConstruction, Float confidenceInterval, RescoreVector rescoreVector) {
17761756
super(VectorIndexType.INT8_HNSW, rescoreVector);
17771757
this.m = m;
17781758
this.efConstruction = efConstruction;
@@ -1910,11 +1890,11 @@ public String toString() {
19101890
}
19111891
}
19121892

1913-
public static class BBQHnswIndexOptions extends QuantizedIndexOptions {
1893+
static class BBQHnswIndexOptions extends QuantizedIndexOptions {
19141894
private final int m;
19151895
private final int efConstruction;
19161896

1917-
public BBQHnswIndexOptions(int m, int efConstruction, RescoreVector rescoreVector) {
1897+
BBQHnswIndexOptions(int m, int efConstruction, RescoreVector rescoreVector) {
19181898
super(VectorIndexType.BBQ_HNSW, rescoreVector);
19191899
this.m = m;
19201900
this.efConstruction = efConstruction;
@@ -1956,14 +1936,11 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
19561936
}
19571937

19581938
@Override
1959-
public boolean validateDimension(int dim, boolean throwOnError) {
1960-
boolean supportsDimension = type.supportsDimension(dim);
1961-
if (throwOnError && supportsDimension == false) {
1962-
throw new IllegalArgumentException(
1963-
type.name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim
1964-
);
1939+
public void validateDimension(int dim) {
1940+
if (type.supportsDimension(dim)) {
1941+
return;
19651942
}
1966-
return supportsDimension;
1943+
throw new IllegalArgumentException(type.name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim);
19671944
}
19681945
}
19691946

@@ -2007,19 +1984,15 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
20071984
}
20081985

20091986
@Override
2010-
public boolean validateDimension(int dim, boolean throwOnError) {
2011-
boolean supportsDimension = type.supportsDimension(dim);
2012-
if (throwOnError && supportsDimension == false) {
2013-
throw new IllegalArgumentException(
2014-
type.name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim
2015-
);
1987+
public void validateDimension(int dim) {
1988+
if (type.supportsDimension(dim)) {
1989+
return;
20161990
}
2017-
return supportsDimension;
1991+
throw new IllegalArgumentException(type.name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim);
20181992
}
2019-
20201993
}
20211994

2022-
public record RescoreVector(float oversample) implements ToXContentObject {
1995+
record RescoreVector(float oversample) implements ToXContentObject {
20231996
static final String NAME = "rescore_vector";
20241997
static final String OVERSAMPLE = "oversample";
20251998

@@ -2338,10 +2311,6 @@ int getVectorDimensions() {
23382311
ElementType getElementType() {
23392312
return elementType;
23402313
}
2341-
2342-
public IndexOptions getIndexOptions() {
2343-
return indexOptions;
2344-
}
23452314
}
23462315

23472316
private final IndexOptions indexOptions;

test/framework/src/main/java/org/elasticsearch/index/mapper/MapperServiceTestCase.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,6 @@ protected final MapperService createMapperService(Settings settings, String mapp
207207
return mapperService;
208208
}
209209

210-
protected final MapperService createMapperService(IndexVersion indexVersion, Settings settings, XContentBuilder mappings)
211-
throws IOException {
212-
MapperService mapperService = createMapperService(indexVersion, settings, () -> true, mappings);
213-
merge(mapperService, mappings);
214-
return mapperService;
215-
}
216-
217210
protected final MapperService createMapperService(IndexVersion version, XContentBuilder mapping) throws IOException {
218211
return createMapperService(version, getIndexSettings(), () -> true, mapping);
219212
}

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapper.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import org.apache.logging.log4j.LogManager;
1111
import org.apache.logging.log4j.Logger;
12-
import org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat;
1312
import org.apache.lucene.index.FieldInfos;
1413
import org.apache.lucene.index.LeafReaderContext;
1514
import org.apache.lucene.search.DocIdSetIterator;
@@ -96,7 +95,6 @@
9695
import java.util.function.Function;
9796
import java.util.function.Supplier;
9897

99-
import static org.elasticsearch.index.IndexVersions.SEMANTIC_TEXT_DEFAULTS_TO_BBQ;
10098
import static org.elasticsearch.inference.TaskType.SPARSE_EMBEDDING;
10199
import static org.elasticsearch.inference.TaskType.TEXT_EMBEDDING;
102100
import static org.elasticsearch.search.SearchService.DEFAULT_SIZE;
@@ -135,8 +133,6 @@ public class SemanticTextFieldMapper extends FieldMapper implements InferenceFie
135133
public static final String CONTENT_TYPE = "semantic_text";
136134
public static final String DEFAULT_ELSER_2_INFERENCE_ID = DEFAULT_ELSER_ID;
137135

138-
public static final float DEFAULT_RESCORE_OVERSAMPLE = 3.0f;
139-
140136
public static final TypeParser parser(Supplier<ModelRegistry> modelRegistry) {
141137
return new TypeParser(
142138
(n, c) -> new Builder(n, c::bitSetProducer, c.getIndexSettings(), modelRegistry.get()),
@@ -1058,30 +1054,12 @@ private static Mapper.Builder createEmbeddingsField(
10581054
denseVectorMapperBuilder.dimensions(modelSettings.dimensions());
10591055
denseVectorMapperBuilder.elementType(modelSettings.elementType());
10601056

1061-
DenseVectorFieldMapper.IndexOptions defaultIndexOptions = null;
1062-
if (indexVersionCreated.onOrAfter(SEMANTIC_TEXT_DEFAULTS_TO_BBQ)) {
1063-
defaultIndexOptions = defaultSemanticDenseIndexOptions();
1064-
}
1065-
if (defaultIndexOptions != null
1066-
&& defaultIndexOptions.validate(modelSettings.elementType(), modelSettings.dimensions(), false)) {
1067-
denseVectorMapperBuilder.indexOptions(defaultIndexOptions);
1068-
}
1069-
10701057
yield denseVectorMapperBuilder;
10711058
}
10721059
default -> throw new IllegalArgumentException("Invalid task_type in model_settings [" + modelSettings.taskType().name() + "]");
10731060
};
10741061
}
10751062

1076-
static DenseVectorFieldMapper.IndexOptions defaultSemanticDenseIndexOptions() {
1077-
// As embedding models for text perform better with BBQ, we aggressively default semantic_text fields to use optimized index
1078-
// options outside of dense_vector defaults
1079-
int m = Lucene99HnswVectorsFormat.DEFAULT_MAX_CONN;
1080-
int efConstruction = Lucene99HnswVectorsFormat.DEFAULT_BEAM_WIDTH;
1081-
DenseVectorFieldMapper.RescoreVector rescoreVector = new DenseVectorFieldMapper.RescoreVector(DEFAULT_RESCORE_OVERSAMPLE);
1082-
return new DenseVectorFieldMapper.BBQHnswIndexOptions(m, efConstruction, rescoreVector);
1083-
}
1084-
10851063
private static boolean canMergeModelSettings(MinimalServiceSettings previous, MinimalServiceSettings current, Conflicts conflicts) {
10861064
if (previous != null && current != null && previous.canMergeWith(current)) {
10871065
return true;

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticInferenceMetadataFieldsMapperTests.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ public void testIsEnabled() {
3737
assertFalse(InferenceMetadataFieldsMapper.isEnabled(settings));
3838

3939
settings = Settings.builder()
40-
.put(
41-
IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(),
42-
getRandomCompatibleIndexVersion(true, IndexVersionUtils.getPreviousVersion(IndexVersions.INFERENCE_METADATA_FIELDS))
43-
)
40+
.put(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(), getRandomCompatibleIndexVersion(true))
4441
.put(InferenceMetadataFieldsMapper.USE_LEGACY_SEMANTIC_TEXT_FORMAT.getKey(), false)
4542
.build();
4643
assertFalse(InferenceMetadataFieldsMapper.isEnabled(settings));
@@ -117,18 +114,18 @@ public MappedFieldType getMappedFieldType() {
117114
}
118115

119116
static IndexVersion getRandomCompatibleIndexVersion(boolean useLegacyFormat) {
120-
return getRandomCompatibleIndexVersion(useLegacyFormat, IndexVersion.current());
121-
}
122-
123-
static IndexVersion getRandomCompatibleIndexVersion(boolean useLegacyFormat, IndexVersion maxVersion) {
124117
if (useLegacyFormat) {
125118
if (randomBoolean()) {
126-
return IndexVersionUtils.randomVersionBetween(random(), IndexVersions.UPGRADE_TO_LUCENE_10_0_0, maxVersion);
119+
return IndexVersionUtils.randomVersionBetween(
120+
random(),
121+
IndexVersions.UPGRADE_TO_LUCENE_10_0_0,
122+
IndexVersionUtils.getPreviousVersion(IndexVersions.INFERENCE_METADATA_FIELDS)
123+
);
127124
}
128125
return IndexVersionUtils.randomPreviousCompatibleVersion(random(), IndexVersions.INFERENCE_METADATA_FIELDS_BACKPORT);
129126
} else {
130127
if (randomBoolean()) {
131-
return IndexVersionUtils.randomVersionBetween(random(), IndexVersions.INFERENCE_METADATA_FIELDS, maxVersion);
128+
return IndexVersionUtils.randomVersionBetween(random(), IndexVersions.INFERENCE_METADATA_FIELDS, IndexVersion.current());
132129
}
133130
return IndexVersionUtils.randomVersionBetween(
134131
random(),
@@ -137,5 +134,4 @@ static IndexVersion getRandomCompatibleIndexVersion(boolean useLegacyFormat, Ind
137134
);
138135
}
139136
}
140-
141137
}

0 commit comments

Comments
 (0)