barrel_vectordb_store (barrel_vectordb v2.1.1)

View Source

Vector store gen_server managing RocksDB and HNSW index

Uses RocksDB column families: - vectors: chunk_id → binary float32 array - metadata: chunk_id → term_to_binary(map) - text: chunk_id → UTF-8 binary - hnsw_graph: node_id → serialized HNSW node

Summary

Functions

Add a chunk with auto-embedding

Add a chunk with explicit vector

Get chunk count

Delete a chunk

Get a chunk by ID

Get DiskANN ID mapping database handles Returns {ok, {Db, CfFwd, CfRev}} | {error, not_started}

Get store info

Rebuild HNSW index from stored vectors

Search for similar chunks

Search for similar chunks with options

Start the vector store

Stop the vector store

Types

metadata/0

-type metadata() ::
          #{file => binary(),
            start_line => pos_integer(),
            end_line => pos_integer(),
            type => atom(),
            atom() => term()}.

search_result/0

-type search_result() ::
          #{id := binary(),
            text := binary(),
            metadata := metadata(),
            score := float(),
            vector => vector()}.

vector/0

-type vector() :: [float()] | binary().

Functions

add(ChunkId, Text, Metadata)

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

Add a chunk with auto-embedding

add(ChunkId, Text, Metadata, Vector)

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

Add a chunk with explicit vector

count()

-spec count() -> non_neg_integer().

Get chunk count

delete(ChunkId)

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

Delete a chunk

get(ChunkId)

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

Get a chunk by ID

get_diskann_db()

-spec get_diskann_db() ->
                        {ok, {rocksdb:db_handle(), rocksdb:cf_handle(), rocksdb:cf_handle()}} |
                        {error, term()}.

Get DiskANN ID mapping database handles Returns {ok, {Db, CfFwd, CfRev}} | {error, not_started}

handle_call(Request, From, State)

handle_cast(Msg, State)

handle_info(Info, State)

info()

-spec info() -> map().

Get store info

init(Config)

rebuild_index()

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

Rebuild HNSW index from stored vectors

search(Query, K)

-spec search(binary() | [float()], pos_integer()) -> {ok, [search_result()]} | {error, term()}.

Search for similar chunks

search(Query, K, Options)

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

Search for similar chunks with options

start_link(Config)

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

Start the vector store

stop()

-spec stop() -> ok.

Stop the vector store

terminate(Reason, State)