Fix for DenseVectorFieldMapperTests to properly initialize random vector given the dimensions in mappings (#129912)

This commit is contained in:
Panagiotis Bailis 2025-06-25 12:05:11 +03:00 committed by GitHub
parent 56d5009924
commit f095b3c592
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 4 deletions

View File

@ -560,9 +560,6 @@ tests:
- class: org.elasticsearch.xpack.rank.rrf.RRFRankClientYamlTestSuiteIT
method: test {yaml=rrf/950_pinned_interaction/rrf with pinned retriever as a sub-retriever}
issue: https://github.com/elastic/elasticsearch/issues/129845
- class: org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapperTests
method: testExistsQueryMinimalMapping
issue: https://github.com/elastic/elasticsearch/issues/129911
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
method: test {p0=esql/60_usage/Basic ESQL usage output (telemetry) non-snapshot version}
issue: https://github.com/elastic/elasticsearch/issues/129888
@ -571,6 +568,7 @@ tests:
extractedAssemble, #2]"
issue: https://github.com/elastic/elasticsearch/issues/119871
# Examples:
#
# Mute a single test case in a YAML test suite:

View File

@ -65,6 +65,7 @@ import java.util.Set;
import static org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat.DEFAULT_BEAM_WIDTH;
import static org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat.DEFAULT_MAX_CONN;
import static org.apache.lucene.tests.index.BaseKnnVectorsFormatTestCase.randomNormalizedVector;
import static org.elasticsearch.index.codec.vectors.IVFVectorsFormat.DYNAMIC_NPROBE;
import static org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper.DEFAULT_OVERSAMPLE;
import static org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper.IVF_FORMAT;
@ -147,7 +148,17 @@ public class DenseVectorFieldMapperTests extends MapperTestCase {
@Override
protected Object getSampleValueForDocument() {
return elementType == ElementType.FLOAT ? List.of(0.5, 0.5, 0.5, 0.5) : List.of((byte) 1, (byte) 1, (byte) 1, (byte) 1);
return elementType == ElementType.FLOAT
? convertToList(randomNormalizedVector(this.dims))
: List.of((byte) 1, (byte) 1, (byte) 1, (byte) 1);
}
private static List<Float> convertToList(float[] vector) {
List<Float> list = new ArrayList<>(vector.length);
for (float v : vector) {
list.add(v);
}
return list;
}
@Override