Skip to content

Commit c557fb3

Browse files
committed
Adding versions for bwc for elastic#125599
1 parent 0df0873 commit c557fb3

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ static TransportVersion def(int id) {
165165
public static final TransportVersion ML_INFERENCE_SAGEMAKER_8_19 = def(8_841_0_21);
166166
public static final TransportVersion ESQL_REPORT_ORIGINAL_TYPES_BACKPORT_8_19 = def(8_841_0_22);
167167
public static final TransportVersion INTRODUCE_FAILURES_LIFECYCLE_BACKPORT_8_19 = def(8_841_0_23);
168+
public static final TransportVersion RESCORE_VECTOR_ALLOW_ZERO_BACKPORT_8_19 = def(8_841_0_25);
168169
public static final TransportVersion V_9_0_0 = def(9_000_0_09);
169170
public static final TransportVersion INITIAL_ELASTICSEARCH_9_0_1 = def(9_000_0_10);
170171
public static final TransportVersion COHERE_BIT_EMBEDDING_TYPE_SUPPORT_ADDED = def(9_001_0_00);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ private static Version parseUnchecked(String version) {
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);
140140
public static final IndexVersion ADD_RESCORE_PARAMS_TO_QUANTIZED_VECTORS_BACKPORT_8_X = def(8_528_0_00, Version.LUCENE_9_12_1);
141+
public static final IndexVersion RESCORE_PARAMS_ALLOW_ZERO_TO_QUANTIZED_VECTORS_BACKPORT_8_X = def(8_529_0_00, Version.LUCENE_9_12_1);
141142
public static final IndexVersion UPGRADE_TO_LUCENE_10_0_0 = def(9_000_0_00, Version.LUCENE_10_0_0);
142143
public static final IndexVersion LOGSDB_DEFAULT_IGNORE_DYNAMIC_BEYOND_LIMIT = def(9_001_0_00, Version.LUCENE_10_0_0);
143144
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: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
import static org.elasticsearch.common.Strings.format;
9797
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
9898
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;
99100

100101
/**
101102
* A {@link FieldMapper} for indexing a dense vector of floats.
@@ -114,14 +115,19 @@ private static boolean hasRescoreIndexVersion(IndexVersion version) {
114115
|| version.between(IndexVersions.ADD_RESCORE_PARAMS_TO_QUANTIZED_VECTORS_BACKPORT_8_X, IndexVersions.UPGRADE_TO_LUCENE_10_0_0);
115116
}
116117

118+
private static boolean allowsZeroRescore(IndexVersion version) {
119+
return version.onOrAfter(RESCORE_PARAMS_ALLOW_ZERO_TO_QUANTIZED_VECTORS)
120+
|| version.between(
121+
IndexVersions.RESCORE_PARAMS_ALLOW_ZERO_TO_QUANTIZED_VECTORS_BACKPORT_8_X,
122+
IndexVersions.UPGRADE_TO_LUCENE_10_0_0
123+
);
124+
}
125+
117126
public static final IndexVersion MAGNITUDE_STORED_INDEX_VERSION = IndexVersions.V_7_5_0;
118127
public static final IndexVersion INDEXED_BY_DEFAULT_INDEX_VERSION = IndexVersions.FIRST_DETACHED_INDEX_VERSION;
119128
public static final IndexVersion NORMALIZE_COSINE = IndexVersions.NORMALIZED_VECTOR_COSINE;
120129
public static final IndexVersion DEFAULT_TO_INT8 = DEFAULT_DENSE_VECTOR_TO_INT8_HNSW;
121130
public static final IndexVersion LITTLE_ENDIAN_FLOAT_STORED_INDEX_VERSION = IndexVersions.V_8_9_0;
122-
public static final IndexVersion ADD_RESCORE_PARAMS_TO_QUANTIZED_VECTORS = IndexVersions.ADD_RESCORE_PARAMS_TO_QUANTIZED_VECTORS;
123-
public static final IndexVersion RESCORE_PARAMS_ALLOW_ZERO_TO_QUANTIZED_VECTORS =
124-
IndexVersions.RESCORE_PARAMS_ALLOW_ZERO_TO_QUANTIZED_VECTORS;
125131
public static final IndexVersion DEFAULT_OVERSAMPLE_VALUE_FOR_BBQ = IndexVersions.DEFAULT_OVERSAMPLE_VALUE_FOR_BBQ;
126132

127133
public static final NodeFeature RESCORE_VECTOR_QUANTIZED_VECTOR_MAPPING = new NodeFeature("mapper.dense_vector.rescore_vector");
@@ -2050,7 +2056,7 @@ static RescoreVector fromIndexOptions(Map<String, ?> indexOptionsMap, IndexVersi
20502056
throw new IllegalArgumentException("Invalid rescore_vector value. Missing required field " + OVERSAMPLE);
20512057
}
20522058
float oversampleValue = (float) XContentMapValues.nodeDoubleValue(oversampleNode);
2053-
if (oversampleValue == 0 && indexVersion.before(RESCORE_PARAMS_ALLOW_ZERO_TO_QUANTIZED_VECTORS)) {
2059+
if (oversampleValue == 0 && allowsZeroRescore(indexVersion)) {
20542060
throw new IllegalArgumentException("oversample must be greater than 1");
20552061
}
20562062
if (oversampleValue < 1 && oversampleValue != 0) {

server/src/main/java/org/elasticsearch/search/vectors/RescoreVectorBuilder.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.util.Objects;
2525

2626
import static org.elasticsearch.TransportVersions.RESCORE_VECTOR_ALLOW_ZERO;
27+
import static org.elasticsearch.TransportVersions.RESCORE_VECTOR_ALLOW_ZERO_BACKPORT_8_19;
28+
import static org.elasticsearch.TransportVersions.V_9_0_0;
2729

2830
public class RescoreVectorBuilder implements Writeable, ToXContentObject {
2931

@@ -57,7 +59,9 @@ public RescoreVectorBuilder(StreamInput in) throws IOException {
5759
@Override
5860
public void writeTo(StreamOutput out) throws IOException {
5961
// We don't want to serialize a `0` oversample to a node that doesn't know what to do with it.
60-
if (oversample == NO_OVERSAMPLE && out.getTransportVersion().before(RESCORE_VECTOR_ALLOW_ZERO)) {
62+
if (oversample == NO_OVERSAMPLE
63+
&& out.getTransportVersion().before(RESCORE_VECTOR_ALLOW_ZERO)
64+
&& (out.getTransportVersion().between(RESCORE_VECTOR_ALLOW_ZERO_BACKPORT_8_19, V_9_0_0) == false)) {
6165
throw new ElasticsearchStatusException(
6266
"[rescore_vector] does not support a 0 for ["
6367
+ OVERSAMPLE_FIELD.getPreferredName()

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
@@ -934,8 +934,12 @@ public void testRescoreVectorOldIndexVersion() {
934934
public void testRescoreZeroVectorOldIndexVersion() {
935935
IndexVersion incompatibleVersion = IndexVersionUtils.randomVersionBetween(
936936
random(),
937-
IndexVersionUtils.getLowestReadCompatibleVersion(),
938-
IndexVersionUtils.getPreviousVersion(DenseVectorFieldMapper.RESCORE_PARAMS_ALLOW_ZERO_TO_QUANTIZED_VECTORS)
937+
IndexVersionUtils.randomVersionBetween(
938+
random(),
939+
IndexVersionUtils.getLowestReadCompatibleVersion(),
940+
IndexVersionUtils.getPreviousVersion(IndexVersions.RESCORE_PARAMS_ALLOW_ZERO_TO_QUANTIZED_VECTORS_BACKPORT_8_X)
941+
),
942+
IndexVersionUtils.getPreviousVersion(IndexVersions.RESCORE_PARAMS_ALLOW_ZERO_TO_QUANTIZED_VECTORS)
939943
);
940944
for (String indexType : List.of("int8_hnsw", "int8_flat", "int4_hnsw", "int4_flat", "bbq_hnsw", "bbq_flat")) {
941945
expectThrows(

0 commit comments

Comments
 (0)