barrel_vectordb_server (barrel_vectordb v2.1.2)

View Source

Per-store gen_batch_server managing RocksDB, vector index, and embeddings

Each store runs as a separate gen_batch_server registered under its name. Handles all document operations, search, and embedding coordination.

Uses gen_batch_server to automatically batch concurrent write operations into single atomic RocksDB WriteBatch operations, improving throughput under concurrent load.

Supports pluggable vector index backends: - hnsw: Pure Erlang HNSW implementation (default) - faiss: Facebook FAISS via NIF binding (optional, requires barrel_faiss)

Summary

Functions

Add document with auto-embedding.

Add multiple documents.

Index a vector without storing text/metadata (see barrel_vectordb).

Index multiple vectors without storing text/metadata.

Add document with explicit vector.

Add multiple documents with pre-computed vectors (bulk insert).

Trigger BM25 index compaction (disk backend only).

Get BM25 index information.

Checkpoint HNSW index to disk.

Get document count.

Delete document.

Embed single text.

Embed multiple texts.

Get embedder information.

Get document by ID.

The store's storage path (RocksDB dir; bm25/diskann nest under it).

Handle a batch of operations. Partitions operations into reads (processed immediately) and writes (batched atomically).

Peek at documents (sample without search).

Search with text query.

Search with BM25 text query. Opts: #{k => integer()}

Hybrid search combining BM25 and vector search. Opts: #{k => integer(), bm25_weight => float(), vector_weight => float(), fusion => rrf | linear}

Search with vector query.

Start a named store. Config options: - db_path: RocksDB storage path - dimension: Vector dimension - hnsw: HNSW index configuration - batch: gen_batch_server options (max_batch_size, min_batch_size)

Get store statistics.

Stop a store.

Update document metadata (re-embeds the text).

Insert or update document.

Types

store_ref/0

-type store_ref() :: atom() | binary() | pid().

Functions

add(Store, Id, Text, Metadata)

-spec add(store_ref(), binary(), binary(), map()) -> ok | {error, term()}.

Add document with auto-embedding.

add_batch(Store, Docs)

-spec add_batch(store_ref(), [{binary(), binary(), map()}]) ->
                   {ok, #{inserted := non_neg_integer()}} | {error, term()}.

Add multiple documents.

add_index_only(Store, Id, Text, Vector)

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

Index a vector without storing text/metadata (see barrel_vectordb).

add_index_only_batch(Store, Entries)

-spec add_index_only_batch(store_ref(), [{binary(), binary(), [float()]}]) ->
                              {ok, #{inserted := non_neg_integer()}} | {error, term()}.

Index multiple vectors without storing text/metadata.

add_vector(Store, Id, Text, Metadata, Vector)

-spec add_vector(store_ref(), binary(), binary(), map(), [float()]) -> ok | {error, term()}.

Add document with explicit vector.

add_vector_batch(Store, Docs)

-spec add_vector_batch(store_ref(), [{binary(), binary(), map(), [float()]}]) ->
                          {ok, #{inserted := non_neg_integer()}} | {error, term()}.

Add multiple documents with pre-computed vectors (bulk insert).

bm25_compact(Store)

-spec bm25_compact(store_ref()) -> ok | {error, term()}.

Trigger BM25 index compaction (disk backend only).

bm25_info(Store)

-spec bm25_info(store_ref()) -> {ok, map()} | {error, bm25_not_enabled}.

Get BM25 index information.

checkpoint(Store)

-spec checkpoint(store_ref()) -> ok.

Checkpoint HNSW index to disk.

count(Store)

-spec count(store_ref()) -> non_neg_integer().

Get document count.

delete(Store, Id)

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

Delete document.

embed(Store, Text)

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

Embed single text.

embed_batch(Store, Texts)

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

Embed multiple texts.

embedder_info(Store)

-spec embedder_info(store_ref()) -> {ok, map()}.

Get embedder information.

get(Store, Id)

-spec get(store_ref(), binary()) -> {ok, map()} | not_found | {error, term()}.

Get document by ID.

get_db_path(Store)

-spec get_db_path(store_ref()) -> {ok, string()}.

The store's storage path (RocksDB dir; bm25/diskann nest under it).

handle_batch(Ops, State)

Handle a batch of operations. Partitions operations into reads (processed immediately) and writes (batched atomically).

init(_)

peek(Store, Limit)

-spec peek(store_ref(), pos_integer()) -> {ok, [map()]}.

Peek at documents (sample without search).

search(Store, Query, Opts)

-spec search(store_ref(), binary(), map()) -> {ok, [map()]} | {error, term()}.

Search with text query.

search_bm25(Store, Query, Opts)

-spec search_bm25(store_ref(), binary(), map()) -> {ok, [{binary(), float()}]} | {error, term()}.

Search with BM25 text query. Opts: #{k => integer()}

search_hybrid(Store, Query, Opts)

-spec search_hybrid(store_ref(), binary(), map()) -> {ok, [map()]} | {error, term()}.

Hybrid search combining BM25 and vector search. Opts: #{k => integer(), bm25_weight => float(), vector_weight => float(), fusion => rrf | linear}

search_vector(Store, Vector, Opts)

-spec search_vector(store_ref(), [float()], map()) -> {ok, [map()]} | {error, term()}.

Search with vector query.

start_link(Name, Config)

-spec start_link(atom() | binary(), map()) -> {ok, pid()} | {error, term()}.

Start a named store. Config options: - db_path: RocksDB storage path - dimension: Vector dimension - hnsw: HNSW index configuration - batch: gen_batch_server options (max_batch_size, min_batch_size)

Default batch settings optimized for vector DB workloads: - min_batch_size: 4 (responsive for single inserts, batches concurrent ones) - max_batch_size: 256 (reasonable upper bound for memory/latency)

stats(Store)

-spec stats(store_ref()) -> {ok, map()}.

Get store statistics.

stop(Store)

-spec stop(store_ref()) -> ok.

Stop a store.

terminate(Reason, State)

update(Store, Id, Text, Metadata)

-spec update(store_ref(), binary(), binary(), map()) -> ok | not_found | {error, term()}.

Update document metadata (re-embeds the text).

upsert(Store, Id, Text, Metadata)

-spec upsert(store_ref(), binary(), binary(), map()) -> ok | {error, term()}.

Insert or update document.