View Source HNSWLib.BFIndex (hnswlib v0.1.5)
Documentation for HNSWLib.BFIndex
.
Summary
Functions
Add items to the index.
Delete vectors with the given labels from the index.
Get the current number of elements in the index.
Get the maximum number of elements the index can hold.
Get the current number of threads to use in the index.
Query the index with a single vector or a list of vectors.
Load index from disk.
Construct a new BFIndex
Save current index to disk.
Get the current number of threads to use in the index.
Functions
@spec add_items( %HNSWLib.BFIndex{dim: term(), reference: term(), space: term()}, Nx.Tensor.t(), [ {:ids, Nx.Tensor.t() | [non_neg_integer()] | nil} ] ) :: :ok | {:error, String.t()}
Add items to the index.
Positional Parameters
data:
Nx.Tensor.t()
.Data to add to the index.
Keyword Parameters
ids:
Nx.Tensor.t() | [non_neg_integer()] | nil
.IDs to assign to the data.
If
nil
, IDs will be assigned sequentially starting from 0.Defaults to
nil
.
Delete vectors with the given labels from the index.
@spec get_current_count(%HNSWLib.BFIndex{ dim: term(), reference: term(), space: term() }) :: {:ok, integer()} | {:error, String.t()}
Get the current number of elements in the index.
@spec get_max_elements(%HNSWLib.BFIndex{dim: term(), reference: term(), space: term()}) :: {:ok, integer()} | {:error, String.t()}
Get the maximum number of elements the index can hold.
@spec get_num_threads(%HNSWLib.BFIndex{dim: term(), reference: term(), space: term()}) :: {:ok, integer()} | {:error, String.t()}
Get the current number of threads to use in the index.
@spec knn_query( %HNSWLib.BFIndex{dim: term(), reference: term(), space: term()}, Nx.Tensor.t() | binary() | [binary()], [{:k, pos_integer()}] ) :: :ok | {:error, String.t()}
Query the index with a single vector or a list of vectors.
Positional Parameters
query:
Nx.Tensor.t() | binary() | [binary()]
.A vector or a list of vectors to query.
If query is a list of vectors, the vectors must be of the same dimension.
Keyword Paramters
k:
pos_integer()
.Number of nearest neighbors to return.
@spec load_index(:cosine | :ip | :l2, non_neg_integer(), Path.t(), [ {:max_elements, non_neg_integer()} ]) :: {:ok, %HNSWLib.BFIndex{dim: term(), reference: term(), space: term()}} | {:error, String.t()}
Load index from disk.
Positional Parameters
space:
:cosine
|:ip
|:l2
.An atom that indicates the vector space. Valid values are
:cosine
, cosine space:ip
, inner product space:l2
, L2 space
dim:
non_neg_integer()
.Number of dimensions for each vector.
path:
Path.t()
.Path to load the index from.
Keyword Parameters
max_elements:
non_neg_integer()
.Maximum number of elements to load from the index.
If set to 0, all elements will be loaded.
Defaults to 0.
@spec new(:cosine | :ip | :l2, non_neg_integer(), non_neg_integer()) :: {:ok, %HNSWLib.BFIndex{dim: term(), reference: term(), space: term()}} | {:error, String.t()}
Construct a new BFIndex
Positional Parameters
space:
:cosine
|:ip
|:l2
.An atom that indicates the vector space. Valid values are
:cosine
, cosine space:ip
, inner product space:l2
, L2 space
dim:
non_neg_integer()
.Number of dimensions for each vector.
max_elements:
non_neg_integer()
.Number of maximum elements.
@spec save_index( %HNSWLib.BFIndex{dim: term(), reference: term(), space: term()}, Path.t() ) :: {:ok, integer()} | {:error, String.t()}
Save current index to disk.
Positional Parameters
path:
Path.t()
.Path to save the index to.
@spec set_num_threads( %HNSWLib.BFIndex{dim: term(), reference: term(), space: term()}, pos_integer() ) :: {:ok, integer()} | {:error, String.t()}
Get the current number of threads to use in the index.