95
95
96
96
import static org .elasticsearch .common .Strings .format ;
97
97
import static org .elasticsearch .common .xcontent .XContentParserUtils .ensureExpectedToken ;
98
- import static org .elasticsearch .index .IndexVersions .DEFAULT_DENSE_VECTOR_TO_INT8_HNSW ;
99
- import static org .elasticsearch .index .IndexVersions .RESCORE_PARAMS_ALLOW_ZERO_TO_QUANTIZED_VECTORS ;
100
98
101
99
/**
102
100
* A {@link FieldMapper} for indexing a dense vector of floats.
@@ -116,19 +114,23 @@ private static boolean hasRescoreIndexVersion(IndexVersion version) {
116
114
}
117
115
118
116
private static boolean allowsZeroRescore (IndexVersion version ) {
119
- return version .onOrAfter (RESCORE_PARAMS_ALLOW_ZERO_TO_QUANTIZED_VECTORS )
117
+ return version .onOrAfter (IndexVersions . RESCORE_PARAMS_ALLOW_ZERO_TO_QUANTIZED_VECTORS )
120
118
|| version .between (
121
119
IndexVersions .RESCORE_PARAMS_ALLOW_ZERO_TO_QUANTIZED_VECTORS_BACKPORT_8_X ,
122
120
IndexVersions .UPGRADE_TO_LUCENE_10_0_0
123
121
);
124
122
}
125
123
124
+ private static boolean defaultOversampleForBBQ (IndexVersion version ) {
125
+ return version .onOrAfter (IndexVersions .DEFAULT_OVERSAMPLE_VALUE_FOR_BBQ )
126
+ || version .between (IndexVersions .DEFAULT_OVERSAMPLE_VALUE_FOR_BBQ_BACKPORT_8_X , IndexVersions .UPGRADE_TO_LUCENE_10_0_0 );
127
+ }
128
+
126
129
public static final IndexVersion MAGNITUDE_STORED_INDEX_VERSION = IndexVersions .V_7_5_0 ;
127
130
public static final IndexVersion INDEXED_BY_DEFAULT_INDEX_VERSION = IndexVersions .FIRST_DETACHED_INDEX_VERSION ;
128
131
public static final IndexVersion NORMALIZE_COSINE = IndexVersions .NORMALIZED_VECTOR_COSINE ;
129
- public static final IndexVersion DEFAULT_TO_INT8 = DEFAULT_DENSE_VECTOR_TO_INT8_HNSW ;
132
+ public static final IndexVersion DEFAULT_TO_INT8 = IndexVersions . DEFAULT_DENSE_VECTOR_TO_INT8_HNSW ;
130
133
public static final IndexVersion LITTLE_ENDIAN_FLOAT_STORED_INDEX_VERSION = IndexVersions .V_8_9_0 ;
131
- public static final IndexVersion DEFAULT_OVERSAMPLE_VALUE_FOR_BBQ = IndexVersions .DEFAULT_OVERSAMPLE_VALUE_FOR_BBQ ;
132
134
133
135
public static final NodeFeature RESCORE_VECTOR_QUANTIZED_VECTOR_MAPPING = new NodeFeature ("mapper.dense_vector.rescore_vector" );
134
136
public static final NodeFeature RESCORE_ZERO_VECTOR_QUANTIZED_VECTOR_MAPPING = new NodeFeature (
@@ -202,7 +204,7 @@ public Builder(String name, IndexVersion indexVersionCreated) {
202
204
super (name );
203
205
this .indexVersionCreated = indexVersionCreated ;
204
206
final boolean indexedByDefault = indexVersionCreated .onOrAfter (INDEXED_BY_DEFAULT_INDEX_VERSION );
205
- final boolean defaultInt8Hnsw = indexVersionCreated .onOrAfter (DEFAULT_DENSE_VECTOR_TO_INT8_HNSW );
207
+ final boolean defaultInt8Hnsw = indexVersionCreated .onOrAfter (IndexVersions . DEFAULT_DENSE_VECTOR_TO_INT8_HNSW );
206
208
this .indexed = Parameter .indexParam (m -> toType (m ).fieldType ().indexed , indexedByDefault );
207
209
if (indexedByDefault ) {
208
210
// Only serialize on newer index versions to prevent breaking existing indices when upgrading
@@ -1498,7 +1500,7 @@ public IndexOptions parseIndexOptions(String fieldName, Map<String, ?> indexOpti
1498
1500
RescoreVector rescoreVector = null ;
1499
1501
if (hasRescoreIndexVersion (indexVersion )) {
1500
1502
rescoreVector = RescoreVector .fromIndexOptions (indexOptionsMap , indexVersion );
1501
- if (rescoreVector == null && indexVersion . onOrAfter ( DEFAULT_OVERSAMPLE_VALUE_FOR_BBQ )) {
1503
+ if (rescoreVector == null && defaultOversampleForBBQ ( indexVersion )) {
1502
1504
rescoreVector = new RescoreVector (DEFAULT_OVERSAMPLE );
1503
1505
}
1504
1506
}
@@ -1522,7 +1524,7 @@ public IndexOptions parseIndexOptions(String fieldName, Map<String, ?> indexOpti
1522
1524
RescoreVector rescoreVector = null ;
1523
1525
if (hasRescoreIndexVersion (indexVersion )) {
1524
1526
rescoreVector = RescoreVector .fromIndexOptions (indexOptionsMap , indexVersion );
1525
- if (rescoreVector == null && indexVersion . onOrAfter ( DEFAULT_OVERSAMPLE_VALUE_FOR_BBQ )) {
1527
+ if (rescoreVector == null && defaultOversampleForBBQ ( indexVersion )) {
1526
1528
rescoreVector = new RescoreVector (DEFAULT_OVERSAMPLE );
1527
1529
}
1528
1530
}
0 commit comments