Skip to content

Commit a314a6c

Browse files
authored
Adding versions for bwc for #125599 (#127663)
blocks: #127662 This adds bwc versions for #125599
1 parent 79ee234 commit a314a6c

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ static TransportVersion def(int id) {
168168
public static final TransportVersion ESQL_AGGREGATE_METRIC_DOUBLE_BLOCK_8_19 = def(8_841_0_24);
169169
public static final TransportVersion INTRODUCE_FAILURES_LIFECYCLE_BACKPORT_8_19 = def(8_841_0_25);
170170
public static final TransportVersion INTRODUCE_FAILURES_DEFAULT_RETENTION_BACKPORT_8_19 = def(8_841_0_26);
171+
public static final TransportVersion RESCORE_VECTOR_ALLOW_ZERO_BACKPORT_8_19 = def(8_841_0_27);
171172
public static final TransportVersion V_9_0_0 = def(9_000_0_09);
172173
public static final TransportVersion INITIAL_ELASTICSEARCH_9_0_1 = def(9_000_0_10);
173174
public static final TransportVersion COHERE_BIT_EMBEDDING_TYPE_SUPPORT_ADDED = def(9_001_0_00);

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

+1
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

+10-4
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) == false) {
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

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
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;
2728

2829
public class RescoreVectorBuilder implements Writeable, ToXContentObject {
2930

@@ -57,7 +58,9 @@ public RescoreVectorBuilder(StreamInput in) throws IOException {
5758
@Override
5859
public void writeTo(StreamOutput out) throws IOException {
5960
// 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)) {
61+
if (oversample == NO_OVERSAMPLE
62+
&& out.getTransportVersion().before(RESCORE_VECTOR_ALLOW_ZERO)
63+
&& out.getTransportVersion().isPatchFrom(RESCORE_VECTOR_ALLOW_ZERO_BACKPORT_8_19) == false) {
6164
throw new ElasticsearchStatusException(
6265
"[rescore_vector] does not support a 0 for ["
6366
+ OVERSAMPLE_FIELD.getPreferredName()

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

+11-4
Original file line numberDiff line numberDiff line change
@@ -932,10 +932,17 @@ public void testRescoreVectorOldIndexVersion() {
932932
}
933933

934934
public void testRescoreZeroVectorOldIndexVersion() {
935-
IndexVersion incompatibleVersion = IndexVersionUtils.randomVersionBetween(
936-
random(),
937-
IndexVersionUtils.getLowestReadCompatibleVersion(),
938-
IndexVersionUtils.getPreviousVersion(DenseVectorFieldMapper.RESCORE_PARAMS_ALLOW_ZERO_TO_QUANTIZED_VECTORS)
935+
IndexVersion incompatibleVersion = randomFrom(
936+
IndexVersionUtils.randomVersionBetween(
937+
random(),
938+
IndexVersionUtils.getLowestReadCompatibleVersion(),
939+
IndexVersionUtils.getPreviousVersion(IndexVersions.RESCORE_PARAMS_ALLOW_ZERO_TO_QUANTIZED_VECTORS_BACKPORT_8_X)
940+
),
941+
IndexVersionUtils.randomVersionBetween(
942+
random(),
943+
IndexVersions.UPGRADE_TO_LUCENE_10_0_0,
944+
IndexVersionUtils.getPreviousVersion(IndexVersions.RESCORE_PARAMS_ALLOW_ZERO_TO_QUANTIZED_VECTORS)
945+
)
939946
);
940947
for (String indexType : List.of("int8_hnsw", "int8_flat", "int4_hnsw", "int4_flat", "bbq_hnsw", "bbq_flat")) {
941948
expectThrows(

0 commit comments

Comments
 (0)