Skip to content

Commit 36701b5

Browse files
committed
addressing PR comments - ensuring dimensions are set for dynamic mapping & adding tests
1 parent 61c86d3 commit 36701b5

File tree

5 files changed

+46
-6
lines changed

5 files changed

+46
-6
lines changed

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.vectors/70_dense_vector_telemetry.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
setup:
22
- requires:
3-
cluster_features: [ "gte_v8.4.0" ]
4-
reason: "Cluster mappings stats for indexed dense vector was added in 8.4"
3+
cluster_features: [ "search.vectors.mappers.default_bbq_hnsw" ]
4+
reason: "Test cluster feature 'search.vectors.mappers.default_bbq_hnsw' is required for using bbq as default
5+
indexing for vector fields."
56
- skip:
67
features: headers
78

server/src/internalClusterTest/java/org/elasticsearch/index/mapper/DynamicMappingIT.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import static org.elasticsearch.index.mapper.MapperService.INDEX_MAPPING_IGNORE_DYNAMIC_BEYOND_LIMIT_SETTING;
5454
import static org.elasticsearch.index.mapper.MapperService.INDEX_MAPPING_NESTED_FIELDS_LIMIT_SETTING;
5555
import static org.elasticsearch.index.mapper.MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING;
56+
import static org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper.BBQ_DIMS_DEFAULT_THRESHOLD;
5657
import static org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper.MIN_DIMS_FOR_DYNAMIC_FLOAT_MAPPING;
5758
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
5859
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
@@ -908,6 +909,29 @@ public void testKnnSubObject() throws Exception {
908909
client().index(
909910
new IndexRequest("test").source("obj.vector", Randomness.get().doubles(MIN_DIMS_FOR_DYNAMIC_FLOAT_MAPPING, 0.0, 5.0).toArray())
910911
).get();
912+
}
913+
914+
public void testDenseVectorDynamicMapping() throws Exception {
915+
assertAcked(indicesAdmin().prepareCreate("test").setMapping("""
916+
{
917+
"dynamic": "true"
918+
}""").get());
919+
920+
client().index(
921+
new IndexRequest("test").source("vector_int8", Randomness.get().doubles(BBQ_DIMS_DEFAULT_THRESHOLD - 1, 0.0, 5.0).toArray())
922+
).get();
923+
client().index(
924+
new IndexRequest("test").source("vector_bbq", Randomness.get().doubles(BBQ_DIMS_DEFAULT_THRESHOLD, 0.0, 5.0).toArray())
925+
).get();
926+
Map<String, Object> mappings = indicesAdmin().prepareGetMappings(TEST_REQUEST_TIMEOUT, "test")
927+
.get()
928+
.mappings()
929+
.get("test")
930+
.sourceAsMap();
931+
assertTrue(new WriteField("properties.vector_int8", () -> mappings).exists());
932+
assertTrue(new WriteField("properties.vector_int8.index_options.type", () -> mappings).get(null).toString().equals("int8_hnsw"));
933+
assertTrue(new WriteField("properties.vector_bbq", () -> mappings).exists());
934+
assertTrue(new WriteField("properties.vector_bbq.index_options.type", () -> mappings).get(null).toString().equals("bbq_hnsw"));
911935

912936
}
913937
}

server/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ private static void postProcessDynamicArrayMapping(DocumentParserContext context
806806
fieldName,
807807
context.indexSettings().getIndexVersionCreated()
808808
);
809+
builder.dimensions(mappers.size());
809810
DenseVectorFieldMapper denseVectorFieldMapper = builder.build(builderContext);
810811
context.updateDynamicMappers(fullFieldName, List.of(denseVectorFieldMapper));
811812
}

server/src/main/java/org/elasticsearch/search/SearchFeatures.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public Set<NodeFeature> getFeatures() {
3131
public static final NodeFeature RESCORER_MISSING_FIELD_BAD_REQUEST = new NodeFeature("search.rescorer.missing.field.bad.request");
3232
public static final NodeFeature INT_SORT_FOR_INT_SHORT_BYTE_FIELDS = new NodeFeature("search.sort.int_sort_for_int_short_byte_fields");
3333
static final NodeFeature MULTI_MATCH_CHECKS_POSITIONS = new NodeFeature("search.multi.match.checks.positions");
34+
public static final NodeFeature BBQ_HNSW_DEFAULT_INDEXING = new NodeFeature("search.vectors.mappers.default_bbq_hnsw");
3435

3536
@Override
3637
public Set<NodeFeature> getTestFeatures() {
@@ -39,7 +40,8 @@ public Set<NodeFeature> getTestFeatures() {
3940
COMPLETION_FIELD_SUPPORTS_DUPLICATE_SUGGESTIONS,
4041
RESCORER_MISSING_FIELD_BAD_REQUEST,
4142
INT_SORT_FOR_INT_SHORT_BYTE_FIELDS,
42-
MULTI_MATCH_CHECKS_POSITIONS
43+
MULTI_MATCH_CHECKS_POSITIONS,
44+
BBQ_HNSW_DEFAULT_INDEXING
4345
);
4446
}
4547
}

server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.time.Instant;
2525
import java.util.stream.Stream;
2626

27+
import static org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper.BBQ_DIMS_DEFAULT_THRESHOLD;
2728
import static org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper.MAX_DIMS_COUNT;
2829
import static org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper.MIN_DIMS_FOR_DYNAMIC_FLOAT_MAPPING;
2930
import static org.hamcrest.CoreMatchers.containsString;
@@ -980,16 +981,27 @@ private void doTestDefaultDenseVectorMappings(DocumentMapper mapper, XContentBui
980981
builder.startObject()
981982
.field("mapsToFloatTooSmall", Randomness.get().doubles(MIN_DIMS_FOR_DYNAMIC_FLOAT_MAPPING - 1, 0.0, 5.0).toArray())
982983
.field("mapsToFloatTooBig", Randomness.get().doubles(MAX_DIMS_COUNT + 1, 0.0, 5.0).toArray())
983-
.field("mapsToDenseVector", Randomness.get().doubles(MIN_DIMS_FOR_DYNAMIC_FLOAT_MAPPING, 0.0, 5.0).toArray())
984+
.field("mapsToInt8HnswDenseVector", Randomness.get().doubles(MIN_DIMS_FOR_DYNAMIC_FLOAT_MAPPING, 0.0, 5.0).toArray())
985+
.field("mapsToBBQHnswDenseVector", Randomness.get().doubles(BBQ_DIMS_DEFAULT_THRESHOLD, 0.0, 5.0).toArray())
984986
.endObject()
985987
);
986988
ParsedDocument parsedDocument = mapper.parse(new SourceToParse("id", source, builder.contentType()));
987989
Mapping update = parsedDocument.dynamicMappingsUpdate();
988990
assertNotNull(update);
989991
assertThat(((FieldMapper) update.getRoot().getMapper("mapsToFloatTooSmall")).fieldType().typeName(), equalTo("float"));
990992
assertThat(((FieldMapper) update.getRoot().getMapper("mapsToFloatTooBig")).fieldType().typeName(), equalTo("float"));
991-
assertThat(((FieldMapper) update.getRoot().getMapper("mapsToDenseVector")).fieldType().typeName(), equalTo("dense_vector"));
992-
DenseVectorFieldMapper dvFieldMapper = ((DenseVectorFieldMapper) update.getRoot().getMapper("mapsToDenseVector"));
993+
assertThat(((FieldMapper) update.getRoot().getMapper("mapsToInt8HnswDenseVector")).fieldType().typeName(), equalTo("dense_vector"));
994+
DenseVectorFieldMapper int8DVFieldMapper = ((DenseVectorFieldMapper) update.getRoot().getMapper("mapsToInt8HnswDenseVector"));
995+
assertThat(
996+
((DenseVectorFieldMapper.DenseVectorIndexOptions) int8DVFieldMapper.fieldType().getIndexOptions()).getType().getName(),
997+
equalTo("int8_hnsw")
998+
);
999+
assertThat(((FieldMapper) update.getRoot().getMapper("mapsToBBQHnswDenseVector")).fieldType().typeName(), equalTo("dense_vector"));
1000+
DenseVectorFieldMapper bbqDVFieldMapper = ((DenseVectorFieldMapper) update.getRoot().getMapper("mapsToBBQHnswDenseVector"));
1001+
assertThat(
1002+
((DenseVectorFieldMapper.DenseVectorIndexOptions) bbqDVFieldMapper.fieldType().getIndexOptions()).getType().getName(),
1003+
equalTo("bbq_hnsw")
1004+
);
9931005
}
9941006

9951007
public void testDefaultDenseVectorMappingsObject() throws IOException {

0 commit comments

Comments
 (0)