OpenAIEmbeddingProvider

org.llm4s.llmconnect.provider.OpenAIEmbeddingProvider

OpenAI embedding provider implementation.

Provides text embeddings using OpenAI's embedding API (text-embedding-3-small, text-embedding-3-large, text-embedding-ada-002). Supports batch embedding of multiple texts in a single request.

== Supported Models ==

  • text-embedding-3-small - Efficient, lower cost (recommended)
  • text-embedding-3-large - Higher quality, higher cost
  • text-embedding-ada-002 - Legacy model

== Token Usage == The response includes token usage information when available from the API.

OpenAI's entry in the embedding half of the provider SPI.

The object that builds the provider is also its org.llm4s.llmconnect.spi.EmbeddingProviderDescriptor, so there is one place per provider rather than a descriptor shadowing a factory.

Attributes

See also

EmbeddingProvider for the provider interface

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

Builds the provider for the SPI; see fromConfig for the direct route.

Builds the provider for the SPI; see fromConfig for the direct route.

Attributes

Creates an OpenAI embedding provider from configuration.

Creates an OpenAI embedding provider from configuration.

Value parameters

cfg

embedding provider configuration with API key and base URL

Attributes

Returns

configured EmbeddingProvider instance

An embedding provider that authenticates with bearer tokens from tokenProvider rather than an API key (#2274): Azure OpenAI with Microsoft Entra ID, whose baseUrl is the resource's unified v1 API - https://<resource>.openai.azure.com/openai/v1 - and whose model is the embedding deployment's name. cfg.apiKey is not used. AzureEntraId.defaultCredential() in llm4s-azure-identity gives a provider that caches the token and refreshes it before it expires; a token the service rejects with a 401 is reported to tokenProvider, so the next call fetches a new one.

An embedding provider that authenticates with bearer tokens from tokenProvider rather than an API key (#2274): Azure OpenAI with Microsoft Entra ID, whose baseUrl is the resource's unified v1 API - https://<resource>.openai.azure.com/openai/v1 - and whose model is the embedding deployment's name. cfg.apiKey is not used. AzureEntraId.defaultCredential() in llm4s-azure-identity gives a provider that caches the token and refreshes it before it expires; a token the service rejects with a 401 is reported to tokenProvider, so the next call fetches a new one.

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 key is llm4s.embeddings.openai.apiKey when that is set, and otherwise OpenAI's shared llm4s.credentials.openai.apiKey, which this module's reference.conf binds to OPENAI_API_KEY - the same key the OpenAI chat sections use, so one variable serves both.

The key is llm4s.embeddings.openai.apiKey when that is set, and otherwise OpenAI's shared llm4s.credentials.openai.apiKey, which this module's reference.conf binds to OPENAI_API_KEY - the same key the OpenAI chat sections use, so one variable serves both.

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]

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