Skip to content

Commit 6dd5e59

Browse files
committed
Revert "Revert semantic_text model registry changes (#127075)"
This reverts commit e280aa5.
1 parent 987e9f7 commit 6dd5e59

File tree

14 files changed

+600
-128
lines changed

14 files changed

+600
-128
lines changed

docs/changelog/126629.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 126629
2+
summary: Default new `semantic_text` fields to use BBQ when models are compatible
3+
area: Relevance
4+
type: enhancement
5+
issues: []

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ private static Version parseUnchecked(String version) {
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);
163163
public static final IndexVersion UPGRADE_TO_LUCENE_10_2_1 = def(9_023_00_0, Version.LUCENE_10_2_1);
164+
public static final IndexVersion SEMANTIC_TEXT_DEFAULTS_TO_BBQ = def(9_024_0_00, Version.LUCENE_10_2_1);
165+
164166
/*
165167
* STOP! READ THIS FIRST! No, really,
166168
* ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _

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

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ 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+
293298
@Override
294299
public DenseVectorFieldMapper build(MapperBuilderContext context) {
295300
// Validate again here because the dimensions or element type could have been set programmatically,
@@ -1221,7 +1226,7 @@ public final String toString() {
12211226
public abstract VectorSimilarityFunction vectorSimilarityFunction(IndexVersion indexVersion, ElementType elementType);
12221227
}
12231228

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

12271232
IndexOptions(VectorIndexType type) {
@@ -1230,21 +1235,36 @@ abstract static class IndexOptions implements ToXContent {
12301235

12311236
abstract KnnVectorsFormat getVectorsFormat(ElementType elementType);
12321237

1233-
final void validateElementType(ElementType elementType) {
1234-
if (type.supportsElementType(elementType) == false) {
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) {
12351249
throw new IllegalArgumentException(
12361250
"[element_type] cannot be [" + elementType.toString() + "] when using index type [" + type + "]"
12371251
);
12381252
}
1253+
return validElementType;
12391254
}
12401255

12411256
abstract boolean updatableTo(IndexOptions update);
12421257

1243-
public void validateDimension(int dim) {
1244-
if (type.supportsDimension(dim)) {
1245-
return;
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);
12461266
}
1247-
throw new IllegalArgumentException(type.name + " only supports even dimensions; provided=" + dim);
1267+
return supportsDimension;
12481268
}
12491269

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

17481768
}
17491769

1750-
static class Int8HnswIndexOptions extends QuantizedIndexOptions {
1770+
public static class Int8HnswIndexOptions extends QuantizedIndexOptions {
17511771
private final int m;
17521772
private final int efConstruction;
17531773
private final Float confidenceInterval;
17541774

1755-
Int8HnswIndexOptions(int m, int efConstruction, Float confidenceInterval, RescoreVector rescoreVector) {
1775+
public Int8HnswIndexOptions(int m, int efConstruction, Float confidenceInterval, RescoreVector rescoreVector) {
17561776
super(VectorIndexType.INT8_HNSW, rescoreVector);
17571777
this.m = m;
17581778
this.efConstruction = efConstruction;
@@ -1890,11 +1910,11 @@ public String toString() {
18901910
}
18911911
}
18921912

1893-
static class BBQHnswIndexOptions extends QuantizedIndexOptions {
1913+
public static class BBQHnswIndexOptions extends QuantizedIndexOptions {
18941914
private final int m;
18951915
private final int efConstruction;
18961916

1897-
BBQHnswIndexOptions(int m, int efConstruction, RescoreVector rescoreVector) {
1917+
public BBQHnswIndexOptions(int m, int efConstruction, RescoreVector rescoreVector) {
18981918
super(VectorIndexType.BBQ_HNSW, rescoreVector);
18991919
this.m = m;
19001920
this.efConstruction = efConstruction;
@@ -1936,11 +1956,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
19361956
}
19371957

19381958
@Override
1939-
public void validateDimension(int dim) {
1940-
if (type.supportsDimension(dim)) {
1941-
return;
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+
);
19421965
}
1943-
throw new IllegalArgumentException(type.name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim);
1966+
return supportsDimension;
19441967
}
19451968
}
19461969

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

19862009
@Override
1987-
public void validateDimension(int dim) {
1988-
if (type.supportsDimension(dim)) {
1989-
return;
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+
);
19902016
}
1991-
throw new IllegalArgumentException(type.name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim);
2017+
return supportsDimension;
19922018
}
2019+
19932020
}
19942021

1995-
record RescoreVector(float oversample) implements ToXContentObject {
2022+
public record RescoreVector(float oversample) implements ToXContentObject {
19962023
static final String NAME = "rescore_vector";
19972024
static final String OVERSAMPLE = "oversample";
19982025

@@ -2311,6 +2338,10 @@ int getVectorDimensions() {
23112338
ElementType getElementType() {
23122339
return elementType;
23132340
}
2341+
2342+
public IndexOptions getIndexOptions() {
2343+
return indexOptions;
2344+
}
23142345
}
23152346

23162347
private final IndexOptions indexOptions;

server/src/main/java/org/elasticsearch/inference/MinimalServiceSettings.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,18 +249,13 @@ private static void validateFieldNotPresent(String field, Object fieldValue, Tas
249249
}
250250
}
251251

252-
public ModelConfigurations toModelConfigurations(String inferenceEntityId) {
253-
return new ModelConfigurations(inferenceEntityId, taskType, service == null ? UNKNOWN_SERVICE : service, this);
254-
}
255-
256252
/**
257253
* Checks if the given {@link MinimalServiceSettings} is equivalent to the current definition.
258254
*/
259255
public boolean canMergeWith(MinimalServiceSettings other) {
260256
return taskType == other.taskType
261257
&& Objects.equals(dimensions, other.dimensions)
262258
&& similarity == other.similarity
263-
&& elementType == other.elementType
264-
&& (service == null || service.equals(other.service));
259+
&& elementType == other.elementType;
265260
}
266261
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ 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+
210217
protected final MapperService createMapperService(IndexVersion version, XContentBuilder mapping) throws IOException {
211218
return createMapperService(version, getIndexSettings(), () -> true, mapping);
212219
}

0 commit comments

Comments
 (0)