API Reference#

Index.java#

namespace usearch#

Java bindings for Unum USearch vector search library.

class Index#

Java bindings for Unum USearch.

Provides interface to interact with USearch library and perform various operations related to indexing and searching.

Public Functions

inline Index(String metric, String quantization, long dimensions, long capacity, long connectivity, long expansion_add, long expansion_search)#

Creates a new instance of Index with specified parameters.

Parameters:
  • metric – the metric type for distance calculation between vectors

  • quantization – the scalar type for quantization of vector data

  • dimensions – the number of dimensions in the vectors

  • capacity – the initial capacity of the index

  • connectivity – the connectivity parameter that limits connections-per-node in graph

  • expansion_add – the expansion factor used for index construction when adding vectors

  • expansion_search – the expansion factor used for index construction during search operations

inline long size()#

Retrieves the current size of the index.

Returns:

the number of vectors currently indexed.

inline long connectivity()#

Retrieves the connectivity parameter of the index.

Returns:

the connectivity parameter that limits connections-per-node in graph.

inline long dimensions()#

Retrieves the number of dimensions of the vectors in the index.

Returns:

the number of dimensions in the vectors.

inline long capacity()#

Retrieves the current capacity of the index.

Returns:

the total capacity including current size.

inline void reserve(long capacity)#

Reserves memory for a specified number of incoming vectors.

Parameters:

capacity – the desired total capacity including current size.

inline void add(int key, float vector[])#

Adds a vector with a specified key to the index.

Parameters:
  • key – the key associated with the vector

  • vector – the vector data

inline int[] search (float vector[], long count)

Searches for closest vectors to the specified query vector.

Parameters:
  • vector – the query vector data

  • count – the number of nearest neighbors to search

Returns:

an array of keys of the nearest neighbors

inline void save(String path)#

Saves the index to a file.

Parameters:

path – the file path where the index will be saved.

inline void load(String path)#

Loads the index from a file.

Parameters:

path – the file path from where the index will be loaded.

inline void view(String path)#

Creates a view of the index from a file without copying it into memory.

Parameters:

path – the file path from where the view will be created.

inline boolean remove(int key)#

Removes the vector associated with the given key from the index.

Parameters:

key – the key of the vector to be removed.

Returns:

true 
if the vector was successfully removed,
false 
otherwise.

inline boolean rename(int from, int to)#

Renames the vector to map to a different key.

Parameters:
  • from – the key of the vector to be renamed.

  • to – the new key for the vector.

Returns:

true 
if the vector was successfully renamed,
false 
otherwise.

Public Static Functions

static inline void main (String[] args)

A simple main method to test the Index functionalities.

Parameters:

args – command line arguments (not used in this case)

Package Static Functions

static inline  [static initializer]

Private Members

long c_ptr = 0#

Private Static Functions

static native long c_create (String metric, String quantization, long dimensions, long capacity, long connectivity, long expansion_add, long expansion_search)
static native void c_destroy (long ptr)
static native long c_size (long ptr)
static native long c_connectivity (long ptr)
static native long c_dimensions (long ptr)
static native long c_capacity (long ptr)
static native void c_reserve (long ptr, long capacity)
static native void c_add (long ptr, int key, float vector[])
static native int[] c_search (long ptr, float vector[], long count)
static native void c_save (long ptr, String path)
static native void c_load (long ptr, String path)
static native void c_view (long ptr, String path)
static native boolean c_remove (long ptr, int key)
static native boolean c_rename (long ptr, int from, int to)
class Config#

Configuration class for building an Index instance.

This class provides a builder pattern to set various configurations for an Index. Once all configurations are set, calling build() will produce an instance of Index.

Public Functions

inline Config()#

Default constructor for the Config class.

inline Index build()#

Constructs an Index instance based on the current configuration settings.

Returns:

a newly constructed Index instance.

inline Config metric(String _metric)#

Sets the metric for distance calculation between vectors.

Parameters:

_metric – the metric type

Returns:

this configuration instance

inline Config quantization(String _quantization)#

Sets the scalar type for quantization of vector data.

Parameters:

_quantization – the quantization type

Returns:

this configuration instance

inline Config dimensions(long _dimensions)#

Sets the number of dimensions in the vectors.

Parameters:

_dimensions – the number of dimensions

Returns:

this configuration instance

inline Config capacity(long _capacity)#

Sets the initial capacity of the index.

Parameters:

_capacity – the index capacity

Returns:

this configuration instance

inline Config connectivity(long _connectivity)#

Sets the connectivity parameter that limits connections-per-node in the graph.

Parameters:

_connectivity – the connectivity value

Returns:

this configuration instance

inline Config expansion_add(long _expansion_add)#

Sets the expansion factor used for index construction when adding vectors.

Parameters:

_expansion_add – the expansion factor for adding vectors

Returns:

this configuration instance

inline Config expansion_search(long _expansion_search)#

Sets the expansion factor used for index construction during search operations.

Parameters:

_expansion_search – the expansion factor for search

Returns:

this configuration instance

Private Members

String _metric = "ip"#
String _quantization = "f32"#
long _dimensions = 0#
long _capacity = 0#
long _connectivity = 0#
long _expansion_add = 0#
long _expansion_search = 0#