Skip to content

Commit f095b3c

Browse files
authored
Fix for DenseVectorFieldMapperTests to properly initialize random vector given the dimensions in mappings (#129912)
1 parent 56d5009 commit f095b3c

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

muted-tests.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,6 @@ tests:
560560
- class: org.elasticsearch.xpack.rank.rrf.RRFRankClientYamlTestSuiteIT
561561
method: test {yaml=rrf/950_pinned_interaction/rrf with pinned retriever as a sub-retriever}
562562
issue: https://github.com/elastic/elasticsearch/issues/129845
563-
- class: org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapperTests
564-
method: testExistsQueryMinimalMapping
565-
issue: https://github.com/elastic/elasticsearch/issues/129911
566563
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
567564
method: test {p0=esql/60_usage/Basic ESQL usage output (telemetry) non-snapshot version}
568565
issue: https://github.com/elastic/elasticsearch/issues/129888
@@ -571,6 +568,7 @@ tests:
571568
extractedAssemble, #2]"
572569
issue: https://github.com/elastic/elasticsearch/issues/119871
573570

571+
574572
# Examples:
575573
#
576574
# Mute a single test case in a YAML test suite:

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565

6666
import static org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat.DEFAULT_BEAM_WIDTH;
6767
import static org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat.DEFAULT_MAX_CONN;
68+
import static org.apache.lucene.tests.index.BaseKnnVectorsFormatTestCase.randomNormalizedVector;
6869
import static org.elasticsearch.index.codec.vectors.IVFVectorsFormat.DYNAMIC_NPROBE;
6970
import static org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper.DEFAULT_OVERSAMPLE;
7071
import static org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper.IVF_FORMAT;
@@ -147,7 +148,17 @@ private void indexMapping(XContentBuilder b, IndexVersion indexVersion) throws I
147148

148149
@Override
149150
protected Object getSampleValueForDocument() {
150-
return elementType == ElementType.FLOAT ? List.of(0.5, 0.5, 0.5, 0.5) : List.of((byte) 1, (byte) 1, (byte) 1, (byte) 1);
151+
return elementType == ElementType.FLOAT
152+
? convertToList(randomNormalizedVector(this.dims))
153+
: List.of((byte) 1, (byte) 1, (byte) 1, (byte) 1);
154+
}
155+
156+
private static List<Float> convertToList(float[] vector) {
157+
List<Float> list = new ArrayList<>(vector.length);
158+
for (float v : vector) {
159+
list.add(v);
160+
}
161+
return list;
151162
}
152163

153164
@Override

0 commit comments

Comments
 (0)