barrel_embed_cohere (barrel_embed v2.3.1)

View Source

Cohere embedding provider

Uses Cohere's Embed API for embedding generation. Requires a Cohere API key.

Requirements

A Cohere API key, either: - Set via COHERE_API_KEY environment variable - Passed in config as api_key => <<"...">>>

Configuration

   Config = #{
       api_key => <<"...">>,                           %% API key (or use env var)
       url => <<"https://api.cohere.com/v1">>,         %% API base URL (default)
       model => <<"embed-english-v3.0">>,              %% Model name (default, 1024 dims)
       input_type => <<"search_document">>,            %% Input type (default)
       timeout => 30000,                               %% Timeout in ms (default)
       dimension => 1024                               %% Vector dimension (default)
   }.

Input Types

- <<"search_document">> - For documents to be searched - <<"search_query">> - For search queries - <<"classification">> - For classification tasks - <<"clustering">> - For clustering tasks

Supported Models

- <<"embed-english-v3.0">> - Default, 1024 dims, English - <<"embed-multilingual-v3.0">> - 1024 dims, 100+ languages - <<"embed-english-light-v3.0">> - 384 dims, faster/cheaper - <<"embed-multilingual-light-v3.0">> - 384 dims, multilingual light

Summary

Functions

Check if Cohere API is available.

Get dimension for this provider.

Generate embedding for a single text.

Generate embeddings for multiple texts. Cohere supports native batch embedding.

Initialize the provider.

Provider name.

Functions

available(Config)

-spec available(map()) -> boolean().

Check if Cohere API is available.

dimension(Config)

-spec dimension(map()) -> pos_integer().

Get dimension for this provider.

embed(Text, Config)

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

Generate embedding for a single text.

embed_batch(Texts, Config)

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

Generate embeddings for multiple texts. Cohere supports native batch embedding.

init(Config)

-spec init(map()) -> {ok, map()} | {error, term()}.

Initialize the provider.

name()

-spec name() -> atom().

Provider name.