@@ -241,7 +241,7 @@ public void add(long key, float vector[]) {
241241 if (c_ptr == 0 ) {
242242 throw new IllegalStateException ("Index already closed" );
243243 }
244- c_add (c_ptr , key , vector );
244+ c_add_f32 (c_ptr , key , vector );
245245 }
246246
247247 /**
@@ -255,7 +255,7 @@ public long[] search(float vector[], long count) {
255255 if (c_ptr == 0 ) {
256256 throw new IllegalStateException ("Index already closed" );
257257 }
258- return c_search (c_ptr , vector , count );
258+ return c_search_f32 (c_ptr , vector , count );
259259 }
260260
261261 /**
@@ -272,6 +272,108 @@ public float[] get(long key) {
272272 return c_get (c_ptr , key );
273273 }
274274
275+ /**
276+ * Adds a double precision vector with a specified key to the index.
277+ *
278+ * @param key the key associated with the vector
279+ * @param vector the double precision vector data
280+ */
281+ public void add (long key , double vector []) {
282+ if (c_ptr == 0 ) {
283+ throw new IllegalStateException ("Index already closed" );
284+ }
285+ c_add_f64 (c_ptr , key , vector );
286+ }
287+
288+ /**
289+ * Searches for closest vectors to the specified double precision query vector.
290+ *
291+ * @param vector the double precision query vector data
292+ * @param count the number of nearest neighbors to search
293+ * @return an array of keys of the nearest neighbors
294+ */
295+ public long [] search (double vector [], long count ) {
296+ if (c_ptr == 0 ) {
297+ throw new IllegalStateException ("Index already closed" );
298+ }
299+ return c_search_f64 (c_ptr , vector , count );
300+ }
301+
302+ /**
303+ * Adds an int8 quantized vector with a specified key to the index.
304+ *
305+ * @param key the key associated with the vector
306+ * @param vector the int8 quantized vector data
307+ */
308+ public void add (long key , byte vector []) {
309+ if (c_ptr == 0 ) {
310+ throw new IllegalStateException ("Index already closed" );
311+ }
312+ c_add_i8 (c_ptr , key , vector );
313+ }
314+
315+ /**
316+ * Searches for closest vectors to the specified int8 quantized query vector.
317+ *
318+ * @param vector the int8 quantized query vector data
319+ * @param count the number of nearest neighbors to search
320+ * @return an array of keys of the nearest neighbors
321+ */
322+ public long [] search (byte vector [], long count ) {
323+ if (c_ptr == 0 ) {
324+ throw new IllegalStateException ("Index already closed" );
325+ }
326+ return c_search_i8 (c_ptr , vector , count );
327+ }
328+
329+ /**
330+ * Retrieves the vector at the specified key and populates the provided float
331+ * buffer.
332+ *
333+ * @param key key to lookup.
334+ * @param buffer buffer to populate with vector data.
335+ * @throws IllegalArgumentException if key is not available or buffer size is
336+ * incorrect.
337+ */
338+ public void getInto (long key , float [] buffer ) {
339+ if (c_ptr == 0 ) {
340+ throw new IllegalStateException ("Index already closed" );
341+ }
342+ c_get_into_f32 (c_ptr , key , buffer );
343+ }
344+
345+ /**
346+ * Retrieves the vector at the specified key and populates the provided double
347+ * buffer.
348+ *
349+ * @param key key to lookup.
350+ * @param buffer buffer to populate with vector data.
351+ * @throws IllegalArgumentException if key is not available or buffer size is
352+ * incorrect.
353+ */
354+ public void getInto (long key , double [] buffer ) {
355+ if (c_ptr == 0 ) {
356+ throw new IllegalStateException ("Index already closed" );
357+ }
358+ c_get_into_f64 (c_ptr , key , buffer );
359+ }
360+
361+ /**
362+ * Retrieves the vector at the specified key and populates the provided byte
363+ * buffer.
364+ *
365+ * @param key key to lookup.
366+ * @param buffer buffer to populate with vector data.
367+ * @throws IllegalArgumentException if key is not available or buffer size is
368+ * incorrect.
369+ */
370+ public void getInto (long key , byte [] buffer ) {
371+ if (c_ptr == 0 ) {
372+ throw new IllegalStateException ("Index already closed" );
373+ }
374+ c_get_into_i8 (c_ptr , key , buffer );
375+ }
376+
275377 /**
276378 * Saves the index to a file.
277379 *
@@ -573,12 +675,6 @@ private static native long c_create(
573675
574676 private static native void c_reserve (long ptr , long capacity );
575677
576- private static native void c_add (long ptr , long key , float vector []);
577-
578- private static native long [] c_search (long ptr , float vector [], long count );
579-
580- private static native float [] c_get (long ptr , long key );
581-
582678 private static native void c_save (long ptr , String path );
583679
584680 private static native void c_load (long ptr , String path );
@@ -588,4 +684,26 @@ private static native long c_create(
588684 private static native boolean c_remove (long ptr , long key );
589685
590686 private static native boolean c_rename (long ptr , long from , long to );
687+
688+ private static native float [] c_get (long ptr , long key );
689+
690+ // Overloaded methods:
691+ private static native void c_add_f32 (long ptr , long key , float vector []);
692+
693+ private static native void c_add_f64 (long ptr , long key , double vector []);
694+
695+ private static native void c_add_i8 (long ptr , long key , byte vector []);
696+
697+ private static native long [] c_search_f32 (long ptr , float vector [], long count );
698+
699+ private static native long [] c_search_f64 (long ptr , double vector [], long count );
700+
701+ private static native long [] c_search_i8 (long ptr , byte vector [], long count );
702+
703+ private static native void c_get_into_f32 (long ptr , long key , float buffer []);
704+
705+ private static native void c_get_into_f64 (long ptr , long key , double buffer []);
706+
707+ private static native void c_get_into_i8 (long ptr , long key , byte buffer []);
708+
591709}
0 commit comments