Skip to content

Commit e993671

Browse files
committed
Fix validation error
1 parent c94955e commit e993671

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,8 +1195,7 @@ static DenseVectorFieldMapper.DenseVectorIndexOptions defaultDenseVectorIndexOpt
11951195

11961196
// As embedding models for text perform better with BBQ, we aggressively default semantic_text fields to use optimized index
11971197
// options
1198-
if (indexVersionCreated.onOrAfter(SEMANTIC_TEXT_DEFAULTS_TO_BBQ)
1199-
|| indexVersionCreated.between(SEMANTIC_TEXT_DEFAULTS_TO_BBQ_BACKPORT_8_X, IndexVersions.UPGRADE_TO_LUCENE_10_0_0)) {
1198+
if (indexVersionDefaultsToBbqHnsw(indexVersionCreated)) {
12001199

12011200
DenseVectorFieldMapper.DenseVectorIndexOptions defaultBbqHnswIndexOptions = defaultBbqHnswDenseVectorIndexOptions();
12021201
return defaultBbqHnswIndexOptions.validate(modelSettings.elementType(), modelSettings.dimensions(), false)
@@ -1207,13 +1206,26 @@ static DenseVectorFieldMapper.DenseVectorIndexOptions defaultDenseVectorIndexOpt
12071206
return null;
12081207
}
12091208

1209+
static boolean indexVersionDefaultsToBbqHnsw(IndexVersion indexVersion) {
1210+
return indexVersion.onOrAfter(SEMANTIC_TEXT_DEFAULTS_TO_BBQ)
1211+
|| indexVersion.between(SEMANTIC_TEXT_DEFAULTS_TO_BBQ_BACKPORT_8_X, IndexVersions.UPGRADE_TO_LUCENE_10_0_0);
1212+
}
1213+
12101214
static DenseVectorFieldMapper.DenseVectorIndexOptions defaultBbqHnswDenseVectorIndexOptions() {
12111215
int m = Lucene99HnswVectorsFormat.DEFAULT_MAX_CONN;
12121216
int efConstruction = Lucene99HnswVectorsFormat.DEFAULT_BEAM_WIDTH;
12131217
DenseVectorFieldMapper.RescoreVector rescoreVector = new DenseVectorFieldMapper.RescoreVector(DEFAULT_RESCORE_OVERSAMPLE);
12141218
return new DenseVectorFieldMapper.BBQHnswIndexOptions(m, efConstruction, rescoreVector);
12151219
}
12161220

1221+
static SemanticTextIndexOptions defaultBbqHnswSemanticTextIndexOptions(IndexVersion indexVersion) {
1222+
return new SemanticTextIndexOptions(
1223+
SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR,
1224+
defaultBbqHnswDenseVectorIndexOptions(),
1225+
indexVersion
1226+
);
1227+
}
1228+
12171229
private static boolean canMergeModelSettings(MinimalServiceSettings previous, MinimalServiceSettings current, Conflicts conflicts) {
12181230
if (previous != null && current != null && previous.canMergeWith(current)) {
12191231
return true;
@@ -1230,9 +1242,15 @@ private static boolean canMergeIndexOptions(SemanticTextIndexOptions previous, S
12301242
return true;
12311243
}
12321244

1233-
if (previous == null || current == null) {
1234-
return true;
1235-
}
1245+
if (previous == null
1246+
&& current.type() == SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR
1247+
&& indexVersionDefaultsToBbqHnsw(current.indexVersion())) {
1248+
return canMergeIndexOptions(defaultBbqHnswSemanticTextIndexOptions(current.indexVersion()), current, conflicts);
1249+
} else if (current == null
1250+
&& previous.type() == SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR
1251+
&& indexVersionDefaultsToBbqHnsw(previous.indexVersion())) {
1252+
return canMergeIndexOptions(previous, defaultBbqHnswSemanticTextIndexOptions(previous.indexVersion()), conflicts);
1253+
}
12361254

12371255
if (previous.type() == SemanticTextIndexOptions.SupportedIndexOptions.DENSE_VECTOR) {
12381256
DenseVectorFieldMapper.DenseVectorIndexOptions previousDenseOptions = (DenseVectorFieldMapper.DenseVectorIndexOptions) previous
@@ -1265,6 +1283,10 @@ private static SemanticTextIndexOptions parseIndexOptionsFromMap(String fieldNam
12651283
);
12661284
@SuppressWarnings("unchecked")
12671285
Map<String, Object> indexOptionsMap = (Map<String, Object>) entry.getValue();
1268-
return new SemanticTextIndexOptions(indexOptions, indexOptions.parseIndexOptions(fieldName, indexOptionsMap, indexVersion));
1286+
return new SemanticTextIndexOptions(
1287+
indexOptions,
1288+
indexOptions.parseIndexOptions(fieldName, indexOptionsMap, indexVersion),
1289+
indexVersion
1290+
);
12691291
}
12701292
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ public class SemanticTextIndexOptions implements ToXContent {
3636

3737
private final SupportedIndexOptions type;
3838
private final IndexOptions indexOptions;
39+
private final IndexVersion indexVersion;
3940

40-
public SemanticTextIndexOptions(SupportedIndexOptions type, IndexOptions indexOptions) {
41+
public SemanticTextIndexOptions(SupportedIndexOptions type, IndexOptions indexOptions, IndexVersion indexVersion) {
4142
this.type = type;
4243
this.indexOptions = indexOptions;
44+
this.indexVersion = indexVersion;
4345
}
4446

4547
public SupportedIndexOptions type() {
@@ -50,6 +52,10 @@ public IndexOptions indexOptions() {
5052
return indexOptions;
5153
}
5254

55+
public IndexVersion indexVersion() {
56+
return indexVersion;
57+
}
58+
5359
public enum SupportedIndexOptions {
5460
DENSE_VECTOR("dense_vector") {
5561
@Override

0 commit comments

Comments
 (0)