Skip to content

Commit 85d375c

Browse files
authored
Restore model registry validation for the semantic text field (#127285)
This reverts commit e280aa5.
1 parent e222e5c commit 85d375c

File tree

16 files changed

+657
-129
lines changed

16 files changed

+657
-129
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: []

docs/changelog/127285.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 127285
2+
summary: Restore model registry validation for the semantic text field
3+
area: Search
4+
type: enhancement
5+
issues: []

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ private static Version parseUnchecked(String version) {
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);
164164
public static final IndexVersion DEFAULT_OVERSAMPLE_VALUE_FOR_BBQ = def(9_024_0_00, Version.LUCENE_10_2_1);
165+
public static final IndexVersion SEMANTIC_TEXT_DEFAULTS_TO_BBQ = def(9_025_0_00, Version.LUCENE_10_2_1);
165166
/*
166167
* STOP! READ THIS FIRST! No, really,
167168
* ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _

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

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,11 @@ public Builder elementType(ElementType elementType) {
295295
return this;
296296
}
297297

298+
public Builder indexOptions(IndexOptions indexOptions) {
299+
this.indexOptions.setValue(indexOptions);
300+
return this;
301+
}
302+
298303
@Override
299304
public DenseVectorFieldMapper build(MapperBuilderContext context) {
300305
// Validate again here because the dimensions or element type could have been set programmatically,
@@ -1226,7 +1231,7 @@ public final String toString() {
12261231
public abstract VectorSimilarityFunction vectorSimilarityFunction(IndexVersion indexVersion, ElementType elementType);
12271232
}
12281233

1229-
abstract static class IndexOptions implements ToXContent {
1234+
public abstract static class IndexOptions implements ToXContent {
12301235
final VectorIndexType type;
12311236

12321237
IndexOptions(VectorIndexType type) {
@@ -1235,21 +1240,36 @@ abstract static class IndexOptions implements ToXContent {
12351240

12361241
abstract KnnVectorsFormat getVectorsFormat(ElementType elementType);
12371242

1238-
final void validateElementType(ElementType elementType) {
1239-
if (type.supportsElementType(elementType) == false) {
1243+
public boolean validate(ElementType elementType, int dim, boolean throwOnError) {
1244+
return validateElementType(elementType, throwOnError) && validateDimension(dim, throwOnError);
1245+
}
1246+
1247+
public boolean validateElementType(ElementType elementType) {
1248+
return validateElementType(elementType, true);
1249+
}
1250+
1251+
final boolean validateElementType(ElementType elementType, boolean throwOnError) {
1252+
boolean validElementType = type.supportsElementType(elementType);
1253+
if (throwOnError && validElementType == false) {
12401254
throw new IllegalArgumentException(
12411255
"[element_type] cannot be [" + elementType.toString() + "] when using index type [" + type + "]"
12421256
);
12431257
}
1258+
return validElementType;
12441259
}
12451260

12461261
abstract boolean updatableTo(IndexOptions update);
12471262

1248-
public void validateDimension(int dim) {
1249-
if (type.supportsDimension(dim)) {
1250-
return;
1263+
public boolean validateDimension(int dim) {
1264+
return validateDimension(dim, true);
1265+
}
1266+
1267+
public boolean validateDimension(int dim, boolean throwOnError) {
1268+
boolean supportsDimension = type.supportsDimension(dim);
1269+
if (throwOnError && supportsDimension == false) {
1270+
throw new IllegalArgumentException(type.name + " only supports even dimensions; provided=" + dim);
12511271
}
1252-
throw new IllegalArgumentException(type.name + " only supports even dimensions; provided=" + dim);
1272+
return supportsDimension;
12531273
}
12541274

12551275
abstract boolean doEquals(IndexOptions other);
@@ -1758,12 +1778,12 @@ boolean updatableTo(IndexOptions update) {
17581778

17591779
}
17601780

1761-
static class Int8HnswIndexOptions extends QuantizedIndexOptions {
1781+
public static class Int8HnswIndexOptions extends QuantizedIndexOptions {
17621782
private final int m;
17631783
private final int efConstruction;
17641784
private final Float confidenceInterval;
17651785

1766-
Int8HnswIndexOptions(int m, int efConstruction, Float confidenceInterval, RescoreVector rescoreVector) {
1786+
public Int8HnswIndexOptions(int m, int efConstruction, Float confidenceInterval, RescoreVector rescoreVector) {
17671787
super(VectorIndexType.INT8_HNSW, rescoreVector);
17681788
this.m = m;
17691789
this.efConstruction = efConstruction;
@@ -1901,11 +1921,11 @@ public String toString() {
19011921
}
19021922
}
19031923

1904-
static class BBQHnswIndexOptions extends QuantizedIndexOptions {
1924+
public static class BBQHnswIndexOptions extends QuantizedIndexOptions {
19051925
private final int m;
19061926
private final int efConstruction;
19071927

1908-
BBQHnswIndexOptions(int m, int efConstruction, RescoreVector rescoreVector) {
1928+
public BBQHnswIndexOptions(int m, int efConstruction, RescoreVector rescoreVector) {
19091929
super(VectorIndexType.BBQ_HNSW, rescoreVector);
19101930
this.m = m;
19111931
this.efConstruction = efConstruction;
@@ -1947,11 +1967,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
19471967
}
19481968

19491969
@Override
1950-
public void validateDimension(int dim) {
1951-
if (type.supportsDimension(dim)) {
1952-
return;
1970+
public boolean validateDimension(int dim, boolean throwOnError) {
1971+
boolean supportsDimension = type.supportsDimension(dim);
1972+
if (throwOnError && supportsDimension == false) {
1973+
throw new IllegalArgumentException(
1974+
type.name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim
1975+
);
19531976
}
1954-
throw new IllegalArgumentException(type.name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim);
1977+
return supportsDimension;
19551978
}
19561979
}
19571980

@@ -1995,15 +2018,19 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
19952018
}
19962019

19972020
@Override
1998-
public void validateDimension(int dim) {
1999-
if (type.supportsDimension(dim)) {
2000-
return;
2021+
public boolean validateDimension(int dim, boolean throwOnError) {
2022+
boolean supportsDimension = type.supportsDimension(dim);
2023+
if (throwOnError && supportsDimension == false) {
2024+
throw new IllegalArgumentException(
2025+
type.name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim
2026+
);
20012027
}
2002-
throw new IllegalArgumentException(type.name + " does not support dimensions fewer than " + BBQ_MIN_DIMS + "; provided=" + dim);
2028+
return supportsDimension;
20032029
}
2030+
20042031
}
20052032

2006-
record RescoreVector(float oversample) implements ToXContentObject {
2033+
public record RescoreVector(float oversample) implements ToXContentObject {
20072034
static final String NAME = "rescore_vector";
20082035
static final String OVERSAMPLE = "oversample";
20092036

@@ -2323,7 +2350,7 @@ ElementType getElementType() {
23232350
return elementType;
23242351
}
23252352

2326-
IndexOptions getIndexOptions() {
2353+
public IndexOptions getIndexOptions() {
23272354
return indexOptions;
23282355
}
23292356
}

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)