barrel_embed_provider behaviour (barrel_embed v2.3.1)

View Source

Embedding 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.

Callbacks

available/1

(optional)
-callback available(Config :: map()) -> boolean().

dimension/1

-callback dimension(Config :: map()) -> pos_integer().

embed/2

-callback embed(Text :: binary(), Config :: map()) -> {ok, Vector :: [float()]} | {error, term()}.

embed_batch/2

-callback embed_batch(Texts :: [binary()], Config :: map()) ->
                         {ok, Vectors :: [[float()]]} | {error, term()}.

init/1

(optional)
-callback init(Config :: map()) -> {ok, NewConfig :: map()} | {error, term()}.

name/0

-callback name() -> atom().

Functions

call_embed(Module, Text, Config)

-spec call_embed(module(), binary(), map()) -> {ok, [float()]} | {error, term()}.

Call embed on a provider module. Wraps the call with error handling.

call_embed_batch(Module, Texts, Config)

-spec call_embed_batch(module(), [binary()], map()) -> {ok, [[float()]]} | {error, term()}.

Call embed_batch on a provider module. Wraps the call with error handling.

check_available(Module, Config)

-spec check_available(module(), map()) -> boolean().

Check if a provider is available. Returns true if the provider doesn't implement available/1.