barrel_vectordb_index_hnsw (barrel_vectordb v2.1.1)

View Source

HNSW backend wrapper for barrel_vectordb_index behaviour

Thin wrapper around barrel_vectordb_hnsw that adapts its API to the barrel_vectordb_index behaviour specification.

Summary

Functions

Delete a vector by ID.

Deserialize index from binary.

Get index information and statistics.

Insert a vector with the given ID.

Create a new HNSW index.

Search for K nearest neighbors.

Search for K nearest neighbors with options.

Serialize index to binary.

Get the number of vectors in the index.

Types

hnsw_config/0

-type hnsw_config() ::
          #hnsw_config{m :: pos_integer(),
                       m_max0 :: pos_integer(),
                       ef_construction :: pos_integer(),
                       ml :: float() | undefined,
                       distance_fn :: cosine | euclidean,
                       quantization :: quantization_method(),
                       tq_state :: term() | undefined}.

hnsw_index/0

-type hnsw_index() ::
          #hnsw_index{entry_point :: binary() | undefined,
                      max_layer :: non_neg_integer(),
                      nodes :: #{binary() => hnsw_node()},
                      config :: hnsw_config(),
                      size :: non_neg_integer(),
                      dimension :: pos_integer()}.

hnsw_node/0

-type hnsw_node() ::
          #hnsw_node{id :: binary(),
                     vector :: quantized_vector(),
                     norm :: float(),
                     layer :: non_neg_integer(),
                     neighbors :: #{non_neg_integer() => [binary()]}}.

quantization_method/0

-type quantization_method() :: scalar | pq | turboquant | subspace_turboquant | none.

quantized_vector/0

-type quantized_vector() :: binary().

Functions

delete(Index, Id)

-spec delete(hnsw_index(), binary()) -> {ok, hnsw_index()} | {error, term()}.

Delete a vector by ID.

deserialize(Binary)

-spec deserialize(binary()) -> {ok, hnsw_index()} | {error, term()}.

Deserialize index from binary.

info(Index)

-spec info(hnsw_index()) -> map().

Get index information and statistics.

insert(Index, Id, Vector)

-spec insert(hnsw_index(), binary(), [float()]) -> {ok, hnsw_index()} | {error, term()}.

Insert a vector with the given ID.

new(Config)

-spec new(map()) -> {ok, hnsw_index()} | {error, term()}.

Create a new HNSW index.

search(Index, Query, K)

-spec search(hnsw_index(), [float()], pos_integer()) -> [{binary(), float()}].

Search for K nearest neighbors.

search(Index, Query, K, Opts)

-spec search(hnsw_index(), [float()], pos_integer(), map()) -> [{binary(), float()}].

Search for K nearest neighbors with options.

serialize(Index)

-spec serialize(hnsw_index()) -> binary().

Serialize index to binary.

size(Index)

-spec size(hnsw_index()) -> non_neg_integer().

Get the number of vectors in the index.