barrel_embed (barrel_embed v2.3.0)
View SourceEmbedding coordinator
Lightweight embedding generation for Erlang. Manages a chain of embedding providers with automatic fallback.
Providers
Local: - local: Local Python with sentence-transformers (CPU, no external calls) - ollama: Local Ollama server - fastembed: FastEmbed ONNX-based embeddings (lighter than sentence-transformers)
Cloud: - openai: OpenAI Embeddings API - cohere: Cohere Embed API - voyage: Voyage AI Embeddings - jina: Jina AI Embeddings - mistral: Mistral AI Embeddings (EU data residency) - azure: Azure OpenAI Embeddings - bedrock: AWS Bedrock Embeddings (Titan, Cohere) - vertex: Google Vertex AI Embeddings
Specialized: - splade: SPLADE sparse embeddings for hybrid search - colbert: ColBERT multi-vector embeddings for fine-grained matching - clip: CLIP image/text cross-modal embeddings
Configuration
%% Local Python embeddings (requires Python + sentence-transformers)
Embedder = {local, #{
python => "python3",
model => "BAAI/bge-base-en-v1.5"
}}.
%% Ollama server
Embedder = {ollama, #{
url => <<"http://localhost:11434">>,
model => <<"nomic-embed-text">>
}}.
%% OpenAI API (requires API key)
Embedder = {openai, #{
api_key => <<"sk-...">>, %% or set OPENAI_API_KEY env var
model => <<"text-embedding-3-small">>
}}.
%% Provider chain with fallback
Embedder = [
{ollama, #{url => <<"http://localhost:11434">>}},
{local, #{}} %% fallback to CPU
].
Summary
Functions
Get the dimension of embeddings.
Generate embedding for a single text.
Generate embeddings for multiple texts.
Generate embeddings for multiple texts with options.
Check if uvloop is installed in the managed venv.
Get information about the current embedding configuration.
Initialize embedding state from configuration.
Install dependencies for a specific provider.
Refresh the managed venv. Deletes and recreates the venv with base dependencies.
Get the managed venv path.
Types
-type embed_state() :: #{providers := [provider()], dimension := pos_integer(), batch_size := pos_integer()}.
Functions
-spec dimension(embed_state() | undefined) -> pos_integer() | undefined.
Get the dimension of embeddings.
-spec embed(binary(), embed_state() | undefined) -> {ok, [float()]} | {error, term()}.
Generate embedding for a single text.
-spec embed_batch([binary()], embed_state() | undefined) -> {ok, [[float()]]} | {error, term()}.
Generate embeddings for multiple texts.
-spec embed_batch([binary()], map(), embed_state() | undefined) -> {ok, [[float()]]} | {error, term()}.
Generate embeddings for multiple texts with options.
-spec has_uvloop() -> boolean().
Check if uvloop is installed in the managed venv.
-spec info(embed_state() | undefined) -> map().
Get information about the current embedding configuration.
-spec init(map()) -> {ok, embed_state() | undefined} | {error, term()}.
Initialize embedding state from configuration.
If no embedder key is present in Config, returns {ok, undefined}.
Install dependencies for a specific provider.
Refresh the managed venv. Deletes and recreates the venv with base dependencies.
-spec venv_path() -> string().
Get the managed venv path.