Skip to content

Commit d260dd6

Browse files
committed
Make dense_vector fields updatable to bbq_flat/bbq_hnsw (elastic#128291)
(cherry picked from commit 629a366)
1 parent 1251218 commit d260dd6

File tree

7 files changed

+873
-15
lines changed

7 files changed

+873
-15
lines changed

docs/changelog/128291.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 128291
2+
summary: Make `dense_vector` fields updatable to bbq_flat/bbq_hnsw
3+
area: Vector Search
4+
type: enhancement
5+
issues: []

docs/reference/mapping/types/dense-vector.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,10 @@ To better accommodate scaling and performance needs, updating the `type` setting
476476

477477
[source,txt]
478478
----
479-
flat --> int8_flat --> int4_flat --> hnsw --> int8_hnsw --> int4_hnsw
479+
flat --> int8_flat --> int4_flat --> bbq_flat --> hnsw --> int8_hnsw --> int4_hnsw --> bbq_hnsw
480480
----
481481

482-
For updating all HNSW types (`hnsw`, `int8_hnsw`, `int4_hnsw`) the number of connections `m` must either stay the same or increase. For scalar quantized formats (`int8_flat`, `int4_flat`, `int8_hnsw`, `int4_hnsw`) the `confidence_interval` must always be consistent (once defined, it cannot change).
482+
For updating all HNSW types (`hnsw`, `int8_hnsw`, `int4_hnsw`, `bbq_hnsw`) the number of connections `m` must either stay the same or increase. For the scalar quantized formats `int8_flat`, `int4_flat`, `int8_hnsw` and `int4_hnsw` the `confidence_interval` must always be consistent (once defined, it cannot change).
483483

484484
Updating `type` in `index_options` will fail in all other scenarios.
485485

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/DenseVectorMappingUpdateIT.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.client.Request;
1616
import org.elasticsearch.client.Response;
1717
import org.elasticsearch.common.Strings;
18+
import org.elasticsearch.index.mapper.SourceFieldMapper;
1819
import org.elasticsearch.xcontent.XContentBuilder;
1920
import org.elasticsearch.xcontent.XContentType;
2021

@@ -31,6 +32,8 @@
3132
*/
3233
public class DenseVectorMappingUpdateIT extends AbstractRollingUpgradeTestCase {
3334

35+
private static final String SYNTHETIC_SOURCE_FEATURE = "gte_v8.12.0";
36+
3437
private static final String BULK1 = """
3538
{"index": {"_id": "1"}}
3639
{"embedding": [1, 1, 1, 1]}
@@ -86,10 +89,22 @@ public void testDenseVectorMappingUpdateOnOldCluster() throws IOException {
8689
String indexName = "test_index";
8790
if (isOldCluster()) {
8891
Request createIndex = new Request("PUT", "/" + indexName);
89-
XContentBuilder mappings = XContentBuilder.builder(XContentType.JSON.xContent())
90-
.startObject()
91-
.startObject("mappings")
92-
.startObject("properties")
92+
boolean useSyntheticSource = randomBoolean() && oldClusterHasFeature(SYNTHETIC_SOURCE_FEATURE);
93+
94+
boolean useIndexSetting = SourceFieldMapper.onOrAfterDeprecateModeVersion(getOldClusterIndexVersion());
95+
XContentBuilder payload = XContentBuilder.builder(XContentType.JSON.xContent()).startObject();
96+
if (useSyntheticSource) {
97+
if (useIndexSetting) {
98+
payload.startObject("settings").field("index.mapping.source.mode", "synthetic").endObject();
99+
}
100+
}
101+
payload.startObject("mappings");
102+
if (useIndexSetting == false) {
103+
payload.startObject("_source");
104+
payload.field("mode", "synthetic");
105+
payload.endObject();
106+
}
107+
payload.startObject("properties")
93108
.startObject("embedding")
94109
.field("type", "dense_vector")
95110
.field("index", "true")
@@ -104,7 +119,7 @@ public void testDenseVectorMappingUpdateOnOldCluster() throws IOException {
104119
.endObject()
105120
.endObject()
106121
.endObject();
107-
createIndex.setJsonEntity(Strings.toString(mappings));
122+
createIndex.setJsonEntity(Strings.toString(payload));
108123
client().performRequest(createIndex);
109124
Request index = new Request("POST", "/" + indexName + "/_bulk/");
110125
index.addParameter("refresh", "true");

0 commit comments

Comments
 (0)