barrel_embed_provider behaviour (barrel_embed v2.5.0)
View SourceEmbedding provider behaviour definition
Implement this behaviour to add new embedding providers.
Example Implementation
-module(my_custom_embedder).
-behaviour(barrel_embed_provider).
-export([embed/2, embed_batch/2, dimension/1, name/0]).
embed(Text, Config) ->
%% Your embedding logic here
{ok, Vector}.
embed_batch(Texts, Config) ->
{ok, [embed(T, Config) || T <- Texts]}.
dimension(_Config) -> 768.
name() -> my_custom.
Summary
Functions
Call embed on a provider module. Wraps the call with error handling.
Call embed_batch on a provider module. Wraps the call with error handling.
Check if a provider is available. Returns true if the provider doesn't implement available/1.
The provider's model identity; providers without model_info/1 fall back to the config's model and revision keys.
Read the model id from Key (default Default) and the optional revision from a provider config.
Types
Callbacks
-callback dimension(Config :: map()) -> pos_integer().
-callback model_info(Config :: map()) -> model_info().
-callback name() -> atom().
Functions
Call embed on a provider module. Wraps the call with error handling.
Call embed_batch on a provider module. Wraps the call with error handling.
Check if a provider is available. Returns true if the provider doesn't implement available/1.
-spec model_info(module(), map()) -> model_info().
The provider's model identity; providers without model_info/1 fall back to the config's model and revision keys.
-spec model_info_from(map(), atom(), binary() | string() | undefined) -> model_info().
Read the model id from Key (default Default) and the optional revision from a provider config.