Barrel API

The barrel module, the single entry point to the embedded database, grouped by area.

This is the barrel module, the one API you use to embed the database. Every function takes the database handle returned by barrel:open/1,2 (except the lifecycle calls). Reach for the guides for worked examples; this page is the map.

Lifecycle

FunctionDescription
open/1, open/2Open (creating if needed) a database; open/2 takes per-layer options. Returns a handle.
close/1Close a database handle.
info/1Database info (counts, floors, cursors).
delete/1Delete a database and its files.

Open from a long-lived process: the database links its vector store to the caller. See Embedding Barrel.

Documents

FunctionDescription
put_doc/2,3Create or update a document (a map with <<"id">>).
get_doc/2,3Read a document by id.
delete_doc/2,3Delete a document (writes a tombstone).
find/2,3Structured path query (#{where => [...]}).
put_docs/2,3, get_docs/2,3, delete_docs/2Batch variants; one result per id, in order.

Queries (BQL)

FunctionDescription
query/2,3Run a BQL statement; returns rows + meta.
query_fold/5Stream a query in chunks (chunk_size, has_more/continuation).
explain_query/2,3Return the plan for a BQL statement.

See the BQL reference and the querying guide.

Attachments

FunctionDescription
put_attachment/4, get_attachment/3Store and read a blob by name.
list_attachments/2, delete_attachment/3, attachment_info/3List, delete, inspect.
open_attachment_writer/4 -> write_attachment/2 -> finish_attachment/1Stream a large blob in (abort_attachment/1 to cancel).
open_attachment_reader/3 -> read_attachment/1 -> close_attachment_reader/1Stream a blob out.
FunctionDescription
vector_add/4,5, vector_add_batch/2Attach a vector (or a batch) to documents.
vector_get/2, vector_delete/2, vector_stats/1Read, delete, and count vectors.
search_vector/3Nearest-neighbour search by vector (#{k => N}).
search_bm25/3Keyword search (needs a BM25 backend enabled at open).
search_hybrid/3, search/3Hybrid vector + keyword, and text search when an embedder is configured.

Hybrid search and auto-embedding need an embedder via barrel_embed; without one they return {error, embedder_not_configured}. See Record mode.

Changes and subscriptions

FunctionDescription
changes/2,3Read the changes feed from first or a cursor.
hlc_encode/1, hlc_decode/1Turn a feed position into a URL-safe cursor and back.
subscribe/2,3, subscribe_ack/2, subscribe_stop/1Subscribe to changes with backpressure.
subscribe_query/2,3, unsubscribe_query/1Live queries (BQL SUBSCRIBE).

Timeline

FunctionDescription
branch/2,3Branch a database (at now, or a past point in time).
merge/1,2Merge a branch back.

See Timeline.

History

FunctionDescription
history/1,2, history_floor/1Read the retained change history and its floor.
doc_versions/2, version_body/3List a document’s versions and read a past body.

See Audit & provenance.