FastEmbed Provider

View Source

Lightweight local embedding using FastEmbed (ONNX-based).

Requirements

# Using virtualenv with uv (recommended)
./scripts/setup_venv.sh
uv pip install fastembed --python .venv/bin/python

# Or install manually
pip install fastembed

Why FastEmbed?

FastEmbed is a lighter alternative to sentence-transformers:

FastEmbedsentence-transformers
Install size~100MB~2GB+
DependenciesONNX RuntimePyTorch
PerformanceOptimized inferenceStandard
QualitySimilarSimilar

Configuration

{ok, State} = barrel_embed:init(#{
    embedder => {fastembed, #{
        python => "python3",                    % default, fallback only
        model => "BAAI/bge-small-en-v1.5",     % default
        timeout => 120000                       % default, ms
    }}
}).

Options

OptionTypeDefaultDescription
pythonstring"python3"Python executable, used only if the managed venv could not be created
modelstring"BAAI/bge-small-en-v1.5"Model name
timeoutinteger120000Timeout in milliseconds

barrel_embed manages its own Python virtualenv automatically and installs fastembed into it on first use. See Python Virtualenv Setup for the managed venv API.

Supported Models

ModelDimensionsNotes
BAAI/bge-small-en-v1.5384Default, fast
BAAI/bge-base-en-v1.5768Good balance
BAAI/bge-large-en-v1.51024Highest quality
sentence-transformers/all-MiniLM-L6-v2384Popular lightweight
nomic-ai/nomic-embed-text-v1.5768Good general-purpose

Example

%% Initialize
{ok, State} = barrel_embed:init(#{
    embedder => {fastembed, #{
        model => "BAAI/bge-small-en-v1.5"
    }}
}).

%% Generate embedding
{ok, Vec} = barrel_embed:embed(<<"Fast and lightweight">>, State).
384 = length(Vec).

%% Batch embedding
{ok, Vecs} = barrel_embed:embed_batch([
    <<"Document 1">>,
    <<"Document 2">>
], State).

When to Use FastEmbed

Choose FastEmbed when:

  • Disk space is limited
  • PyTorch is not desired
  • You need lightweight local inference
  • Quality requirements are standard (not maximum)

Choose sentence-transformers (local provider) when:

  • You need access to all HuggingFace models
  • You're already using PyTorch
  • You need maximum compatibility