18
18
import org .elasticsearch .script .field .vectors .MultiDenseVector ;
19
19
import org .elasticsearch .script .field .vectors .MultiDenseVectorDocValuesField ;
20
20
import org .elasticsearch .test .ESTestCase ;
21
+ import org .junit .BeforeClass ;
21
22
22
23
import java .io .IOException ;
23
24
import java .nio .ByteBuffer ;
28
29
29
30
public class MultiDenseVectorScriptDocValuesTests extends ESTestCase {
30
31
32
+ @ BeforeClass
33
+ public static void setup () {
34
+ assumeTrue ("Requires multi-dense vector support" , MultiDenseVectorFieldMapper .FEATURE_FLAG .isEnabled ());
35
+ }
36
+
31
37
public void testFloatGetVectorValueAndGetMagnitude () throws IOException {
32
38
int dims = 3 ;
33
39
float [][][] vectors = { { { 1 , 1 , 1 }, { 1 , 1 , 2 }, { 1 , 1 , 3 } }, { { 1 , 0 , 2 } } };
34
40
float [][] expectedMagnitudes = { { 1.7320f , 2.4495f , 3.3166f }, { 2.2361f } };
35
41
36
- IndexVersion indexVersion = IndexVersion .current ();
37
- BinaryDocValues docValues = wrap (vectors , ElementType .FLOAT , indexVersion );
42
+ BinaryDocValues docValues = wrap (vectors , ElementType .FLOAT );
38
43
BinaryDocValues magnitudeValues = wrap (expectedMagnitudes );
39
44
MultiDenseVectorDocValuesField field = new FloatMultiDenseVectorDocValuesField (
40
45
docValues ,
@@ -64,7 +69,7 @@ public void testByteGetVectorValueAndGetMagnitude() throws IOException {
64
69
float [][][] vectors = { { { 1 , 1 , 1 }, { 1 , 1 , 2 }, { 1 , 1 , 3 } }, { { 1 , 0 , 2 } } };
65
70
float [][] expectedMagnitudes = { { 1.7320f , 2.4495f , 3.3166f }, { 2.2361f } };
66
71
67
- BinaryDocValues docValues = wrap (vectors , ElementType .BYTE , IndexVersion . current () );
72
+ BinaryDocValues docValues = wrap (vectors , ElementType .BYTE );
68
73
BinaryDocValues magnitudeValues = wrap (expectedMagnitudes );
69
74
MultiDenseVectorDocValuesField field = new ByteMultiDenseVectorDocValuesField (
70
75
docValues ,
@@ -91,10 +96,9 @@ public void testByteGetVectorValueAndGetMagnitude() throws IOException {
91
96
92
97
public void testFloatMetadataAndIterator () throws IOException {
93
98
int dims = 3 ;
94
- IndexVersion indexVersion = IndexVersion .current ();
95
99
float [][][] vectors = new float [][][] { fill (new float [3 ][dims ], ElementType .FLOAT ), fill (new float [2 ][dims ], ElementType .FLOAT ) };
96
100
float [][] magnitudes = new float [][] { new float [3 ], new float [2 ] };
97
- BinaryDocValues docValues = wrap (vectors , ElementType .FLOAT , indexVersion );
101
+ BinaryDocValues docValues = wrap (vectors , ElementType .FLOAT );
98
102
BinaryDocValues magnitudeValues = wrap (magnitudes );
99
103
100
104
MultiDenseVectorDocValuesField field = new FloatMultiDenseVectorDocValuesField (
@@ -120,10 +124,9 @@ public void testFloatMetadataAndIterator() throws IOException {
120
124
121
125
public void testByteMetadataAndIterator () throws IOException {
122
126
int dims = 3 ;
123
- IndexVersion indexVersion = IndexVersion .current ();
124
127
float [][][] vectors = new float [][][] { fill (new float [3 ][dims ], ElementType .BYTE ), fill (new float [2 ][dims ], ElementType .BYTE ) };
125
128
float [][] magnitudes = new float [][] { new float [3 ], new float [2 ] };
126
- BinaryDocValues docValues = wrap (vectors , ElementType .BYTE , indexVersion );
129
+ BinaryDocValues docValues = wrap (vectors , ElementType .BYTE );
127
130
BinaryDocValues magnitudeValues = wrap (magnitudes );
128
131
MultiDenseVectorDocValuesField field = new ByteMultiDenseVectorDocValuesField (
129
132
docValues ,
@@ -159,7 +162,7 @@ public void testFloatMissingValues() throws IOException {
159
162
int dims = 3 ;
160
163
float [][][] vectors = { { { 1 , 1 , 1 }, { 1 , 1 , 2 }, { 1 , 1 , 3 } }, { { 1 , 0 , 2 } } };
161
164
float [][] magnitudes = { { 1.7320f , 2.4495f , 3.3166f }, { 2.2361f } };
162
- BinaryDocValues docValues = wrap (vectors , ElementType .FLOAT , IndexVersion . current () );
165
+ BinaryDocValues docValues = wrap (vectors , ElementType .FLOAT );
163
166
BinaryDocValues magnitudeValues = wrap (magnitudes );
164
167
MultiDenseVectorDocValuesField field = new FloatMultiDenseVectorDocValuesField (
165
168
docValues ,
@@ -183,7 +186,7 @@ public void testByteMissingValues() throws IOException {
183
186
int dims = 3 ;
184
187
float [][][] vectors = { { { 1 , 1 , 1 }, { 1 , 1 , 2 }, { 1 , 1 , 3 } }, { { 1 , 0 , 2 } } };
185
188
float [][] magnitudes = { { 1.7320f , 2.4495f , 3.3166f }, { 2.2361f } };
186
- BinaryDocValues docValues = wrap (vectors , ElementType .BYTE , IndexVersion . current () );
189
+ BinaryDocValues docValues = wrap (vectors , ElementType .BYTE );
187
190
BinaryDocValues magnitudeValues = wrap (magnitudes );
188
191
MultiDenseVectorDocValuesField field = new ByteMultiDenseVectorDocValuesField (
189
192
docValues ,
@@ -207,7 +210,7 @@ public void testFloatGetFunctionIsNotAccessible() throws IOException {
207
210
int dims = 3 ;
208
211
float [][][] vectors = { { { 1 , 1 , 1 }, { 1 , 1 , 2 }, { 1 , 1 , 3 } }, { { 1 , 0 , 2 } } };
209
212
float [][] magnitudes = { { 1.7320f , 2.4495f , 3.3166f }, { 2.2361f } };
210
- BinaryDocValues docValues = wrap (vectors , ElementType .FLOAT , IndexVersion . current () );
213
+ BinaryDocValues docValues = wrap (vectors , ElementType .FLOAT );
211
214
BinaryDocValues magnitudeValues = wrap (magnitudes );
212
215
MultiDenseVectorDocValuesField field = new FloatMultiDenseVectorDocValuesField (
213
216
docValues ,
@@ -233,7 +236,7 @@ public void testByteGetFunctionIsNotAccessible() throws IOException {
233
236
int dims = 3 ;
234
237
float [][][] vectors = { { { 1 , 1 , 1 }, { 1 , 1 , 2 }, { 1 , 1 , 3 } }, { { 1 , 0 , 2 } } };
235
238
float [][] magnitudes = { { 1.7320f , 2.4495f , 3.3166f }, { 2.2361f } };
236
- BinaryDocValues docValues = wrap (vectors , ElementType .BYTE , IndexVersion . current () );
239
+ BinaryDocValues docValues = wrap (vectors , ElementType .BYTE );
237
240
BinaryDocValues magnitudeValues = wrap (magnitudes );
238
241
MultiDenseVectorDocValuesField field = new ByteMultiDenseVectorDocValuesField (
239
242
docValues ,
@@ -303,7 +306,7 @@ public long cost() {
303
306
};
304
307
}
305
308
306
- public static BinaryDocValues wrap (float [][][] vectors , ElementType elementType , IndexVersion indexVersion ) {
309
+ public static BinaryDocValues wrap (float [][][] vectors , ElementType elementType ) {
307
310
return new BinaryDocValues () {
308
311
int idx = -1 ;
309
312
int maxIdx = vectors .length ;
@@ -313,7 +316,7 @@ public BytesRef binaryValue() {
313
316
if (idx >= maxIdx ) {
314
317
throw new IllegalStateException ("max index exceeded" );
315
318
}
316
- return mockEncodeDenseVector (vectors [idx ], elementType , indexVersion );
319
+ return mockEncodeDenseVector (vectors [idx ], elementType , IndexVersion . current () );
317
320
}
318
321
319
322
@ Override
0 commit comments