4646import org .apache .lucene .util .SameThreadExecutorService ;
4747import org .apache .lucene .util .VectorUtil ;
4848import org .elasticsearch .common .logging .LogConfigurator ;
49+ import org .elasticsearch .index .codec .vectors .BFloat16 ;
4950
5051import java .io .IOException ;
5152import java .util .Arrays ;
@@ -68,9 +69,13 @@ public class ES93HnswBinaryQuantizedVectorsFormatTests extends BaseKnnVectorsFor
6869
6970 private KnnVectorsFormat format ;
7071
72+ boolean useBFloat16 () {
73+ return false ;
74+ }
75+
7176 @ Override
7277 public void setUp () throws Exception {
73- format = new ES93HnswBinaryQuantizedVectorsFormat (DEFAULT_MAX_CONN , DEFAULT_BEAM_WIDTH , random ().nextBoolean ());
78+ format = new ES93HnswBinaryQuantizedVectorsFormat (DEFAULT_MAX_CONN , DEFAULT_BEAM_WIDTH , random ().nextBoolean (), useBFloat16 () );
7479 super .setUp ();
7580 }
7681
@@ -137,12 +142,12 @@ public void testSingleVectorCase() throws Exception {
137142 }
138143
139144 public void testLimits () {
140- expectThrows (IllegalArgumentException .class , () -> new ES93HnswBinaryQuantizedVectorsFormat (-1 , 20 , false ));
141- expectThrows (IllegalArgumentException .class , () -> new ES93HnswBinaryQuantizedVectorsFormat (0 , 20 , false ));
142- expectThrows (IllegalArgumentException .class , () -> new ES93HnswBinaryQuantizedVectorsFormat (20 , 0 , false ));
143- expectThrows (IllegalArgumentException .class , () -> new ES93HnswBinaryQuantizedVectorsFormat (20 , -1 , false ));
144- expectThrows (IllegalArgumentException .class , () -> new ES93HnswBinaryQuantizedVectorsFormat (512 + 1 , 20 , false ));
145- expectThrows (IllegalArgumentException .class , () -> new ES93HnswBinaryQuantizedVectorsFormat (20 , 3201 , false ));
145+ expectThrows (IllegalArgumentException .class , () -> new ES93HnswBinaryQuantizedVectorsFormat (-1 , 20 , false , false ));
146+ expectThrows (IllegalArgumentException .class , () -> new ES93HnswBinaryQuantizedVectorsFormat (0 , 20 , false , false ));
147+ expectThrows (IllegalArgumentException .class , () -> new ES93HnswBinaryQuantizedVectorsFormat (20 , 0 , false , false ));
148+ expectThrows (IllegalArgumentException .class , () -> new ES93HnswBinaryQuantizedVectorsFormat (20 , -1 , false , false ));
149+ expectThrows (IllegalArgumentException .class , () -> new ES93HnswBinaryQuantizedVectorsFormat (512 + 1 , 20 , false , false ));
150+ expectThrows (IllegalArgumentException .class , () -> new ES93HnswBinaryQuantizedVectorsFormat (20 , 3201 , false , false ));
146151 expectThrows (
147152 IllegalArgumentException .class ,
148153 () -> new ES93HnswBinaryQuantizedVectorsFormat (20 , 100 , false , false , 1 , new SameThreadExecutorService ())
@@ -189,7 +194,8 @@ public void testSimpleOffHeapSizeImpl(Directory dir, IndexWriterConfig config, b
189194 assertEquals (1L , (long ) offHeap .get ("vex" ));
190195 assertTrue (offHeap .get ("veb" ) > 0L );
191196 if (expectVecOffHeap ) {
192- assertEquals (vector .length * Float .BYTES , (long ) offHeap .get ("vec" ));
197+ int bytes = useBFloat16 () ? BFloat16 .BYTES : Float .BYTES ;
198+ assertEquals (vector .length * bytes , (long ) offHeap .get ("vec" ));
193199 }
194200 }
195201 }
0 commit comments