CohereEmbeddingProvider

org.llm4s.llmconnect.provider.CohereEmbeddingProvider

Embedding provider implementation for Cohere's native embed API (POST <baseUrl>/v2/embed).

This is not an OpenAI-compatible endpoint: it takes texts, an input_type and the embedding_types to return, and answers with the vectors keyed by type ({"embeddings": {"float": [[...]]}}). That is why it is a module of its own and not a dialect in llm4s-openai-compatible, where Cohere's chat client lives.

Texts are sent in requests of at most CohereEmbeddingProvider.MaxTextsPerRequest (Cohere's limit); the vectors come back in input order and the billed tokens of every request are summed into the response's usage. The first failing request fails the whole call.

Requires a Cohere API key (COHERE_API_KEY) in the provider configuration. The vectors have the model's default size; no output_dimension is sent.

Cohere supplies chat through llm4s-openai-compatible, so this is an org.llm4s.llmconnect.spi.EmbeddingProviderDescriptor only, registered by Llm4sCohereModule.

Attributes

See also

EmbeddingProvider for the common embedding interface

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

Builds the provider for the SPI, with CohereInputType.default; see fromConfig to choose the input type.

Builds the provider for the SPI, with CohereInputType.default; see fromConfig to choose the input type.

Attributes

Creates an EmbeddingProvider backed by Cohere, sending inputType with every request.

Creates an EmbeddingProvider backed by Cohere, sending inputType with every request.

Attributes

Inherited methods

def aliases: Set[String]

Alternative spellings accepted in EMBEDDING_MODEL=<name>/<model>, folded onto id.

Alternative spellings accepted in EMBEDDING_MODEL=<name>/<model>, folded onto id.

Attributes

Inherited from:
EmbeddingProviderDescriptor
def buildConfig(section: EmbeddingProviderSection, modelOverride: Option[String]): Result[EmbeddingProviderConfig]

Turns this provider's config section into the EmbeddingProviderConfig its client needs.

Turns this provider's config section into the EmbeddingProviderConfig its client needs.

The default implementation resolves model, base URL and API key against configSpec, which is all any of the project's own providers needs. Override it only for a provider whose config genuinely cannot be expressed that way.

Value parameters

modelOverride

the <model> half of EMBEDDING_MODEL=<id>/<model>, when the unified form was used. Takes precedence over the section.

section

the llm4s.embeddings.<id> section, already parsed, its apiKey already falling back to the shared llm4s.credentials.<id>.apiKey when it sets none. Empty rather than absent when the user configured nothing. Everything this method needs arrives typed, in here: a descriptor never reads configuration itself.

Attributes

Inherited from:
EmbeddingProviderDescriptor
def dimensionsOf(model: String): Option[Int]

The vector dimensions of model, when this provider knows them.

The vector dimensions of model, when this provider knows them.

Attributes

Inherited from:
EmbeddingProviderDescriptor

Concrete fields

The most texts Cohere accepts in one /v2/embed request.

The most texts Cohere accepts in one /v2/embed request.

Attributes

What this provider needs from llm4s.embeddings.<id>, and its defaults.

What this provider needs from llm4s.embeddings.<id>, and its defaults.

Attributes

val id: ProviderId

Canonical id, e.g. ProviderId("voyage"). Must be unique among the embedding providers in a registry.

Canonical id, e.g. ProviderId("voyage"). Must be unique among the embedding providers in a registry.

Chat and embedding ids live in separate namespaces, so a provider that supplies both — OpenAI, Ollama — uses the same id for each without a clash. That is what lets EMBEDDING_MODEL=ollama/nomic-embed-text and a named chat section with provider = "ollama" name the same provider.

Attributes

override val modelDimensions: Map[String, Int]

Default output dimensions; the client does not send an output_dimension parameter.

Default output dimensions; the client does not send an output_dimension parameter.

Attributes