barrel_vectordb_index behaviour (barrel_vectordb v2.1.2)

View Source

Vector 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

backend/0

-type backend() :: hnsw | faiss | diskann.

Available backend types. Note: hybrid backend has been removed in favor of pure DiskANN

index/0

-type index() :: term().

Opaque index type. Implementation depends on the backend.

Callbacks

close/1

(optional)
-callback close(Index :: index()) -> ok.

delete/2

-callback delete(Index :: index(), Id :: binary()) -> {ok, index()} | {error, term()}.

deserialize/1

-callback deserialize(Binary :: binary()) -> {ok, index()} | {error, term()}.

info/1

-callback info(Index :: index()) -> map().

insert/3

-callback insert(Index :: index(), Id :: binary(), Vector :: [float()]) -> {ok, index()} | {error, term()}.

new/1

-callback new(Config :: map()) -> {ok, index()} | {error, term()}.

search/3

-callback search(Index :: index(), Query :: [float()], K :: pos_integer()) -> [{binary(), float()}].

search/4

-callback search(Index :: index(), Query :: [float()], K :: pos_integer(), Opts :: map()) ->
                    [{binary(), float()}].

serialize/1

-callback serialize(Index :: index()) -> binary().

size/1

-callback size(Index :: index()) -> non_neg_integer().

Functions

backend_module(_)

-spec backend_module(backend()) -> module().

Get the implementation module for a backend. Returns the module that implements the barrel_vectordb_index behaviour.

is_available(_)

-spec is_available(backend()) -> boolean().

Check if a backend is available. HNSW and diskann are always available. FAISS requires barrel_faiss NIF.