Skip to content

Commit

Permalink
Updating testing and logging for dense_vector dynamic dims (#100546) (#…
Browse files Browse the repository at this point in the history
…100833)

This adds a test for dynamic dims update mapping merges.

Also, this adds logging to help investigate a periodically failing test.

related to: #100502
  • Loading branch information
benwtrent authored Oct 13, 2023
1 parent 364ae21 commit 23280ee
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@ setup:
version: ' - 8.10.99'
reason: 'Dynamic mapping of floats to dense_vector was added in 8.11'

# Additional logging for issue: https://github.com/elastic/elasticsearch/issues/100502
- do:
cluster.put_settings:
body: >
{
"persistent": {
"logger.org.elasticsearch.index": "TRACE"
}
}
---
teardown:
- skip:
version: ' - 8.10.99'
reason: 'Dynamic mapping of floats to dense_vector was added in 8.11'

- do:
cluster.put_settings:
body: >
{
"persistent": {
"logger.org.elasticsearch.index": null
}
}
---
"Fields with float arrays below the threshold still map as float":

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import org.apache.lucene.search.FieldExistsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.codec.CodecService;
import org.elasticsearch.index.codec.PerFieldMapperCodec;
Expand Down Expand Up @@ -231,6 +233,26 @@ public void testDims() {
}
}

public void testMergeDims() throws IOException {
XContentBuilder mapping = mapping(b -> {
b.startObject("field");
b.field("type", "dense_vector");
b.endObject();
});
MapperService mapperService = createMapperService(mapping);

mapping = mapping(b -> {
b.startObject("field");
b.field("type", "dense_vector").field("dims", 4).field("similarity", "cosine").field("index", true);
b.endObject();
});
merge(mapperService, mapping);
assertEquals(
XContentHelper.convertToMap(BytesReference.bytes(mapping), false, mapping.contentType()).v2(),
XContentHelper.convertToMap(mapperService.documentMapper().mappingSource().uncompressed(), false, mapping.contentType()).v2()
);
}

public void testDefaults() throws Exception {
DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> b.field("type", "dense_vector").field("dims", 3)));

Expand Down

0 comments on commit 23280ee

Please sign in to comment.