Skip to content

Commit 176e933

Browse files
authored
Adds new BWC version for 8.19 backport of (#124581) (#127647)
1 parent 6263f44 commit 176e933

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ private static Version parseUnchecked(String version) {
137137
public static final IndexVersion LOGSB_OPTIONAL_SORTING_ON_HOST_NAME_BACKPORT = def(8_525_0_00, parseUnchecked("9.12.1"));
138138
public static final IndexVersion USE_SYNTHETIC_SOURCE_FOR_RECOVERY_BY_DEFAULT_BACKPORT = def(8_526_0_00, parseUnchecked("9.12.1"));
139139
public static final IndexVersion SYNTHETIC_SOURCE_STORE_ARRAYS_NATIVELY_BACKPORT_8_X = def(8_527_0_00, Version.LUCENE_9_12_1);
140+
public static final IndexVersion ADD_RESCORE_PARAMS_TO_QUANTIZED_VECTORS_BACKPORT_8_X = def(8_528_0_00, Version.LUCENE_9_12_1);
140141
public static final IndexVersion UPGRADE_TO_LUCENE_10_0_0 = def(9_000_0_00, Version.LUCENE_10_0_0);
141142
public static final IndexVersion LOGSDB_DEFAULT_IGNORE_DYNAMIC_BEYOND_LIMIT = def(9_001_0_00, Version.LUCENE_10_0_0);
142143
public static final IndexVersion TIME_BASED_K_ORDERED_DOC_ID = def(9_002_0_00, Version.LUCENE_10_0_0);

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ public static boolean isNotUnitVector(float magnitude) {
109109
return Math.abs(magnitude - 1.0f) > EPS;
110110
}
111111

112+
private static boolean hasRescoreIndexVersion(IndexVersion version) {
113+
return version.onOrAfter(IndexVersions.ADD_RESCORE_PARAMS_TO_QUANTIZED_VECTORS)
114+
|| version.between(IndexVersions.ADD_RESCORE_PARAMS_TO_QUANTIZED_VECTORS_BACKPORT_8_X, IndexVersions.UPGRADE_TO_LUCENE_10_0_0);
115+
}
116+
112117
public static final IndexVersion MAGNITUDE_STORED_INDEX_VERSION = IndexVersions.V_7_5_0;
113118
public static final IndexVersion INDEXED_BY_DEFAULT_INDEX_VERSION = IndexVersions.FIRST_DETACHED_INDEX_VERSION;
114119
public static final IndexVersion NORMALIZE_COSINE = IndexVersions.NORMALIZED_VECTOR_COSINE;
@@ -1350,7 +1355,7 @@ public IndexOptions parseIndexOptions(String fieldName, Map<String, ?> indexOpti
13501355
confidenceInterval = (float) XContentMapValues.nodeDoubleValue(confidenceIntervalNode);
13511356
}
13521357
RescoreVector rescoreVector = null;
1353-
if (indexVersion.onOrAfter(ADD_RESCORE_PARAMS_TO_QUANTIZED_VECTORS)) {
1358+
if (hasRescoreIndexVersion(indexVersion)) {
13541359
rescoreVector = RescoreVector.fromIndexOptions(indexOptionsMap, indexVersion);
13551360
}
13561361
MappingParser.checkNoRemainingFields(fieldName, indexOptionsMap);
@@ -1385,7 +1390,7 @@ public IndexOptions parseIndexOptions(String fieldName, Map<String, ?> indexOpti
13851390
confidenceInterval = (float) XContentMapValues.nodeDoubleValue(confidenceIntervalNode);
13861391
}
13871392
RescoreVector rescoreVector = null;
1388-
if (indexVersion.onOrAfter(ADD_RESCORE_PARAMS_TO_QUANTIZED_VECTORS)) {
1393+
if (hasRescoreIndexVersion(indexVersion)) {
13891394
rescoreVector = RescoreVector.fromIndexOptions(indexOptionsMap, indexVersion);
13901395
}
13911396
MappingParser.checkNoRemainingFields(fieldName, indexOptionsMap);
@@ -1428,7 +1433,7 @@ public IndexOptions parseIndexOptions(String fieldName, Map<String, ?> indexOpti
14281433
confidenceInterval = (float) XContentMapValues.nodeDoubleValue(confidenceIntervalNode);
14291434
}
14301435
RescoreVector rescoreVector = null;
1431-
if (indexVersion.onOrAfter(ADD_RESCORE_PARAMS_TO_QUANTIZED_VECTORS)) {
1436+
if (hasRescoreIndexVersion(indexVersion)) {
14321437
rescoreVector = RescoreVector.fromIndexOptions(indexOptionsMap, indexVersion);
14331438
}
14341439
MappingParser.checkNoRemainingFields(fieldName, indexOptionsMap);
@@ -1454,7 +1459,7 @@ public IndexOptions parseIndexOptions(String fieldName, Map<String, ?> indexOpti
14541459
confidenceInterval = (float) XContentMapValues.nodeDoubleValue(confidenceIntervalNode);
14551460
}
14561461
RescoreVector rescoreVector = null;
1457-
if (indexVersion.onOrAfter(ADD_RESCORE_PARAMS_TO_QUANTIZED_VECTORS)) {
1462+
if (hasRescoreIndexVersion(indexVersion)) {
14581463
rescoreVector = RescoreVector.fromIndexOptions(indexOptionsMap, indexVersion);
14591464
}
14601465
MappingParser.checkNoRemainingFields(fieldName, indexOptionsMap);
@@ -1485,7 +1490,7 @@ public IndexOptions parseIndexOptions(String fieldName, Map<String, ?> indexOpti
14851490
int m = XContentMapValues.nodeIntegerValue(mNode);
14861491
int efConstruction = XContentMapValues.nodeIntegerValue(efConstructionNode);
14871492
RescoreVector rescoreVector = null;
1488-
if (indexVersion.onOrAfter(ADD_RESCORE_PARAMS_TO_QUANTIZED_VECTORS)) {
1493+
if (hasRescoreIndexVersion(indexVersion)) {
14891494
rescoreVector = RescoreVector.fromIndexOptions(indexOptionsMap, indexVersion);
14901495
if (rescoreVector == null && indexVersion.onOrAfter(DEFAULT_OVERSAMPLE_VALUE_FOR_BBQ)) {
14911496
rescoreVector = new RescoreVector(DEFAULT_OVERSAMPLE);
@@ -1509,7 +1514,7 @@ public boolean supportsDimension(int dims) {
15091514
@Override
15101515
public IndexOptions parseIndexOptions(String fieldName, Map<String, ?> indexOptionsMap, IndexVersion indexVersion) {
15111516
RescoreVector rescoreVector = null;
1512-
if (indexVersion.onOrAfter(ADD_RESCORE_PARAMS_TO_QUANTIZED_VECTORS)) {
1517+
if (hasRescoreIndexVersion(indexVersion)) {
15131518
rescoreVector = RescoreVector.fromIndexOptions(indexOptionsMap, indexVersion);
15141519
if (rescoreVector == null && indexVersion.onOrAfter(DEFAULT_OVERSAMPLE_VALUE_FOR_BBQ)) {
15151520
rescoreVector = new RescoreVector(DEFAULT_OVERSAMPLE);

server/src/test/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldMapperTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,12 @@ public void testRescoreVectorForNonQuantized() {
906906
public void testRescoreVectorOldIndexVersion() {
907907
IndexVersion incompatibleVersion = IndexVersionUtils.randomVersionBetween(
908908
random(),
909-
IndexVersionUtils.getLowestReadCompatibleVersion(),
910-
IndexVersionUtils.getPreviousVersion(DenseVectorFieldMapper.ADD_RESCORE_PARAMS_TO_QUANTIZED_VECTORS)
909+
IndexVersionUtils.randomVersionBetween(
910+
random(),
911+
IndexVersionUtils.getLowestReadCompatibleVersion(),
912+
IndexVersionUtils.getPreviousVersion(IndexVersions.ADD_RESCORE_PARAMS_TO_QUANTIZED_VECTORS_BACKPORT_8_X)
913+
),
914+
IndexVersionUtils.getPreviousVersion(IndexVersions.ADD_RESCORE_PARAMS_TO_QUANTIZED_VECTORS)
911915
);
912916
for (String indexType : List.of("int8_hnsw", "int8_flat", "int4_hnsw", "int4_flat", "bbq_hnsw", "bbq_flat")) {
913917
expectThrows(

0 commit comments

Comments
 (0)