EmbeddingProviderDescriptor

org.llm4s.llmconnect.spi.EmbeddingProviderDescriptor

Everything llm4s needs to know about one embedding provider, supplied by the provider itself.

This is ProviderDescriptor's counterpart for the embedding half of the SPI, and it is deliberately a separate trait rather than a method on the chat descriptor: the two sets overlap but neither contains the other. OpenAI and Ollama supply both a chat client and an embedding provider, Voyage supplies only embeddings, and Anthropic only chat. Folding embeddings into ProviderDescriptor would force an embedding-only provider to implement buildClient and buildConfig only to fail them.

Register it by listing it in an Llm4sProviderModule's Llm4sProviderModule.embeddingProviders, exactly as a chat provider is registered, and EmbeddingClient.from can reach it with nothing in llm4s-core edited.

The module's reference.conf binds the vendor's variable to the shared key, which a section without an apiKey of its own falls back to:

llm4s.credentials.jina.apiKey = ${?JINA_API_KEY}

Attributes

Example
object JinaEmbeddings extends EmbeddingProviderDescriptor:
 val id = ProviderId("jina")
 override val configSpec = EmbeddingConfigSpec(
   requiresApiKey = true,
   defaultBaseUrl = Some("https://api.jina.ai/v1"),
   apiKeyEnv      = Seq("JINA_API_KEY")   // what llm4s.credentials.jina.apiKey binds
 )
 def build(config: EmbeddingProviderConfig): Result[EmbeddingProvider] =
   Right(JinaEmbeddingProvider.fromConfig(config))
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Members list

Value members

Abstract methods

Constructs the embedding provider for an already-resolved config.

Constructs the embedding provider for an already-resolved config.

The config has been read and validated by the caller, so a Left here means something only this provider can detect — a model its API does not offer, say.

Attributes

def 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

Concrete 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

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

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

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

Attributes

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

def modelDimensions: Map[String, Int]

Vector dimensions of the models this provider knows, keyed by model name as it appears in EMBEDDING_MODEL=<id>/<model>.

Vector dimensions of the models this provider knows, keyed by model name as it appears in EMBEDDING_MODEL=<id>/<model>.

This is what ModelDimensionRegistry answers from, so a provider's dimensions travel with the provider rather than living in a central table in llm4s-core - which is how ollama came to have no entries at all while its documented configuration depended on them.

A model missing here still embeds; only a caller that needs its dimensionality up front is told it is unknown. Override dimensionsOf instead when model names have variants that share a size.

Attributes