Skip to content

Commit 82c02de

Browse files
authored
Fixing MultiDenseVectorScriptDocValuesTests tests (#116940)
This fixes two test issues: - 1. Now the tests skip if the multi_dense_vector feature isn't enabled - 2. fixes silly bwc testing where we were testing for big-endian floats, which aren't possible. closes: #116862 closes: #116863
1 parent c72d5fd commit 82c02de

File tree

2 files changed

+36
-39
lines changed

2 files changed

+36
-39
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,6 @@ tests:
234234
- class: org.elasticsearch.search.basic.SearchWithRandomIOExceptionsIT
235235
method: testRandomDirectoryIOExceptions
236236
issue: https://github.com/elastic/elasticsearch/issues/114824
237-
- class: org.elasticsearch.index.mapper.vectors.MultiDenseVectorScriptDocValuesTests
238-
method: testFloatGetVectorValueAndGetMagnitude
239-
issue: https://github.com/elastic/elasticsearch/issues/116863
240237
- class: org.elasticsearch.xpack.inference.InferenceRestIT
241238
method: test {p0=inference/30_semantic_text_inference/Calculates embeddings using the default ELSER 2 endpoint}
242239
issue: https://github.com/elastic/elasticsearch/issues/116542

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

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,46 +18,48 @@
1818
import org.elasticsearch.script.field.vectors.MultiDenseVector;
1919
import org.elasticsearch.script.field.vectors.MultiDenseVectorDocValuesField;
2020
import org.elasticsearch.test.ESTestCase;
21-
import org.elasticsearch.test.index.IndexVersionUtils;
21+
import org.junit.BeforeClass;
2222

2323
import java.io.IOException;
2424
import java.nio.ByteBuffer;
2525
import java.nio.ByteOrder;
2626
import java.util.Iterator;
27-
import java.util.List;
2827

2928
import static org.hamcrest.Matchers.containsString;
3029

3130
public class MultiDenseVectorScriptDocValuesTests extends ESTestCase {
3231

32+
@BeforeClass
33+
public static void setup() {
34+
assumeTrue("Requires multi-dense vector support", MultiDenseVectorFieldMapper.FEATURE_FLAG.isEnabled());
35+
}
36+
3337
public void testFloatGetVectorValueAndGetMagnitude() throws IOException {
3438
int dims = 3;
3539
float[][][] vectors = { { { 1, 1, 1 }, { 1, 1, 2 }, { 1, 1, 3 } }, { { 1, 0, 2 } } };
3640
float[][] expectedMagnitudes = { { 1.7320f, 2.4495f, 3.3166f }, { 2.2361f } };
3741

38-
for (IndexVersion indexVersion : List.of(IndexVersionUtils.randomCompatibleVersion(random()), IndexVersion.current())) {
39-
BinaryDocValues docValues = wrap(vectors, ElementType.FLOAT, indexVersion);
40-
BinaryDocValues magnitudeValues = wrap(expectedMagnitudes);
41-
MultiDenseVectorDocValuesField field = new FloatMultiDenseVectorDocValuesField(
42-
docValues,
43-
magnitudeValues,
44-
"test",
45-
ElementType.FLOAT,
46-
dims
47-
);
48-
MultiDenseVectorScriptDocValues scriptDocValues = field.toScriptDocValues();
49-
for (int i = 0; i < vectors.length; i++) {
50-
field.setNextDocId(i);
51-
assertEquals(vectors[i].length, field.size());
52-
assertEquals(dims, scriptDocValues.dims());
53-
Iterator<float[]> iterator = scriptDocValues.getVectorValues();
54-
float[] magnitudes = scriptDocValues.getMagnitudes();
55-
assertEquals(expectedMagnitudes[i].length, magnitudes.length);
56-
for (int j = 0; j < vectors[i].length; j++) {
57-
assertTrue(iterator.hasNext());
58-
assertArrayEquals(vectors[i][j], iterator.next(), 0.0001f);
59-
assertEquals(expectedMagnitudes[i][j], magnitudes[j], 0.0001f);
60-
}
42+
BinaryDocValues docValues = wrap(vectors, ElementType.FLOAT);
43+
BinaryDocValues magnitudeValues = wrap(expectedMagnitudes);
44+
MultiDenseVectorDocValuesField field = new FloatMultiDenseVectorDocValuesField(
45+
docValues,
46+
magnitudeValues,
47+
"test",
48+
ElementType.FLOAT,
49+
dims
50+
);
51+
MultiDenseVectorScriptDocValues scriptDocValues = field.toScriptDocValues();
52+
for (int i = 0; i < vectors.length; i++) {
53+
field.setNextDocId(i);
54+
assertEquals(vectors[i].length, field.size());
55+
assertEquals(dims, scriptDocValues.dims());
56+
Iterator<float[]> iterator = scriptDocValues.getVectorValues();
57+
float[] magnitudes = scriptDocValues.getMagnitudes();
58+
assertEquals(expectedMagnitudes[i].length, magnitudes.length);
59+
for (int j = 0; j < vectors[i].length; j++) {
60+
assertTrue(iterator.hasNext());
61+
assertArrayEquals(vectors[i][j], iterator.next(), 0.0001f);
62+
assertEquals(expectedMagnitudes[i][j], magnitudes[j], 0.0001f);
6163
}
6264
}
6365
}
@@ -67,7 +69,7 @@ public void testByteGetVectorValueAndGetMagnitude() throws IOException {
6769
float[][][] vectors = { { { 1, 1, 1 }, { 1, 1, 2 }, { 1, 1, 3 } }, { { 1, 0, 2 } } };
6870
float[][] expectedMagnitudes = { { 1.7320f, 2.4495f, 3.3166f }, { 2.2361f } };
6971

70-
BinaryDocValues docValues = wrap(vectors, ElementType.BYTE, IndexVersion.current());
72+
BinaryDocValues docValues = wrap(vectors, ElementType.BYTE);
7173
BinaryDocValues magnitudeValues = wrap(expectedMagnitudes);
7274
MultiDenseVectorDocValuesField field = new ByteMultiDenseVectorDocValuesField(
7375
docValues,
@@ -94,10 +96,9 @@ public void testByteGetVectorValueAndGetMagnitude() throws IOException {
9496

9597
public void testFloatMetadataAndIterator() throws IOException {
9698
int dims = 3;
97-
IndexVersion indexVersion = IndexVersion.current();
9899
float[][][] vectors = new float[][][] { fill(new float[3][dims], ElementType.FLOAT), fill(new float[2][dims], ElementType.FLOAT) };
99100
float[][] magnitudes = new float[][] { new float[3], new float[2] };
100-
BinaryDocValues docValues = wrap(vectors, ElementType.FLOAT, indexVersion);
101+
BinaryDocValues docValues = wrap(vectors, ElementType.FLOAT);
101102
BinaryDocValues magnitudeValues = wrap(magnitudes);
102103

103104
MultiDenseVectorDocValuesField field = new FloatMultiDenseVectorDocValuesField(
@@ -123,10 +124,9 @@ public void testFloatMetadataAndIterator() throws IOException {
123124

124125
public void testByteMetadataAndIterator() throws IOException {
125126
int dims = 3;
126-
IndexVersion indexVersion = IndexVersion.current();
127127
float[][][] vectors = new float[][][] { fill(new float[3][dims], ElementType.BYTE), fill(new float[2][dims], ElementType.BYTE) };
128128
float[][] magnitudes = new float[][] { new float[3], new float[2] };
129-
BinaryDocValues docValues = wrap(vectors, ElementType.BYTE, indexVersion);
129+
BinaryDocValues docValues = wrap(vectors, ElementType.BYTE);
130130
BinaryDocValues magnitudeValues = wrap(magnitudes);
131131
MultiDenseVectorDocValuesField field = new ByteMultiDenseVectorDocValuesField(
132132
docValues,
@@ -162,7 +162,7 @@ public void testFloatMissingValues() throws IOException {
162162
int dims = 3;
163163
float[][][] vectors = { { { 1, 1, 1 }, { 1, 1, 2 }, { 1, 1, 3 } }, { { 1, 0, 2 } } };
164164
float[][] magnitudes = { { 1.7320f, 2.4495f, 3.3166f }, { 2.2361f } };
165-
BinaryDocValues docValues = wrap(vectors, ElementType.FLOAT, IndexVersion.current());
165+
BinaryDocValues docValues = wrap(vectors, ElementType.FLOAT);
166166
BinaryDocValues magnitudeValues = wrap(magnitudes);
167167
MultiDenseVectorDocValuesField field = new FloatMultiDenseVectorDocValuesField(
168168
docValues,
@@ -186,7 +186,7 @@ public void testByteMissingValues() throws IOException {
186186
int dims = 3;
187187
float[][][] vectors = { { { 1, 1, 1 }, { 1, 1, 2 }, { 1, 1, 3 } }, { { 1, 0, 2 } } };
188188
float[][] magnitudes = { { 1.7320f, 2.4495f, 3.3166f }, { 2.2361f } };
189-
BinaryDocValues docValues = wrap(vectors, ElementType.BYTE, IndexVersion.current());
189+
BinaryDocValues docValues = wrap(vectors, ElementType.BYTE);
190190
BinaryDocValues magnitudeValues = wrap(magnitudes);
191191
MultiDenseVectorDocValuesField field = new ByteMultiDenseVectorDocValuesField(
192192
docValues,
@@ -210,7 +210,7 @@ public void testFloatGetFunctionIsNotAccessible() throws IOException {
210210
int dims = 3;
211211
float[][][] vectors = { { { 1, 1, 1 }, { 1, 1, 2 }, { 1, 1, 3 } }, { { 1, 0, 2 } } };
212212
float[][] magnitudes = { { 1.7320f, 2.4495f, 3.3166f }, { 2.2361f } };
213-
BinaryDocValues docValues = wrap(vectors, ElementType.FLOAT, IndexVersion.current());
213+
BinaryDocValues docValues = wrap(vectors, ElementType.FLOAT);
214214
BinaryDocValues magnitudeValues = wrap(magnitudes);
215215
MultiDenseVectorDocValuesField field = new FloatMultiDenseVectorDocValuesField(
216216
docValues,
@@ -236,7 +236,7 @@ public void testByteGetFunctionIsNotAccessible() throws IOException {
236236
int dims = 3;
237237
float[][][] vectors = { { { 1, 1, 1 }, { 1, 1, 2 }, { 1, 1, 3 } }, { { 1, 0, 2 } } };
238238
float[][] magnitudes = { { 1.7320f, 2.4495f, 3.3166f }, { 2.2361f } };
239-
BinaryDocValues docValues = wrap(vectors, ElementType.BYTE, IndexVersion.current());
239+
BinaryDocValues docValues = wrap(vectors, ElementType.BYTE);
240240
BinaryDocValues magnitudeValues = wrap(magnitudes);
241241
MultiDenseVectorDocValuesField field = new ByteMultiDenseVectorDocValuesField(
242242
docValues,
@@ -306,7 +306,7 @@ public long cost() {
306306
};
307307
}
308308

309-
public static BinaryDocValues wrap(float[][][] vectors, ElementType elementType, IndexVersion indexVersion) {
309+
public static BinaryDocValues wrap(float[][][] vectors, ElementType elementType) {
310310
return new BinaryDocValues() {
311311
int idx = -1;
312312
int maxIdx = vectors.length;
@@ -316,7 +316,7 @@ public BytesRef binaryValue() {
316316
if (idx >= maxIdx) {
317317
throw new IllegalStateException("max index exceeded");
318318
}
319-
return mockEncodeDenseVector(vectors[idx], elementType, indexVersion);
319+
return mockEncodeDenseVector(vectors[idx], elementType, IndexVersion.current());
320320
}
321321

322322
@Override

0 commit comments

Comments
 (0)