barrel_vectordb_index behaviour (barrel_vectordb v2.1.1)
View SourceVector index backend behaviour
Defines the interface that vector index backends must implement. Supports both pure Erlang HNSW and FAISS (via NIF) backends.
Available Backends
hnsw- Pure Erlang HNSW implementation (default)faiss- Facebook FAISS via NIF binding (optional)
Usage
%% Get the module for a backend
Mod = barrel_vectordb_index:backend_module(hnsw),
%% Create an index
{ok, Index} = Mod:new(#{dimension => 128}),
%% Insert vectors
{ok, Index2} = Mod:insert(Index, <<"doc1">>, [0.1, 0.2, ...]),
%% Search
Results = Mod:search(Index2, [0.1, 0.2, ...], 10).
Summary
Types
Available backend types. Note: hybrid backend has been removed in favor of pure DiskANN
Opaque index type. Implementation depends on the backend.
Functions
Get the implementation module for a backend. Returns the module that implements the barrel_vectordb_index behaviour.
Check if a backend is available. HNSW and diskann are always available. FAISS requires barrel_faiss NIF.
Types
-type backend() :: hnsw | faiss | diskann.
Available backend types. Note: hybrid backend has been removed in favor of pure DiskANN
-type index() :: term().
Opaque index type. Implementation depends on the backend.
Callbacks
-callback close(Index :: index()) -> ok.
-callback search(Index :: index(), Query :: [float()], K :: pos_integer()) -> [{binary(), float()}].
-callback size(Index :: index()) -> non_neg_integer().
Functions
Get the implementation module for a backend. Returns the module that implements the barrel_vectordb_index behaviour.
Check if a backend is available. HNSW and diskann are always available. FAISS requires barrel_faiss NIF.