@@ -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}
0 commit comments