OpenAiEmbeddingModel.ts
OpenAiEmbeddingModel.ts overview
Section titled “OpenAiEmbeddingModel.ts overview”The OpenAiEmbeddingModel module adapts OpenAI-compatible embeddings
endpoints to Effect’s embedding model service. It sends embedding requests
through OpenAiClient, exposes constructors for layers and AiModel
values, supports scoped request configuration overrides, and checks that the
provider returns one numeric vector for each requested input.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”configuration
Section titled “configuration”withConfigOverride
Section titled “withConfigOverride”Provides scoped request config overrides for OpenAI-compatible embedding model operations.
When to use
Use to apply embedding request options to one effect without changing the model’s default configuration.
Details
The overrides are merged with any existing Config service for the duration
of the supplied effect. Fields in overrides take precedence over existing
config, and the helper supports both effect.pipe(withConfigOverride(overrides))
and withConfigOverride(effect, overrides).
See
Configfor available OpenAI-compatible embedding request configuration fields
Signature
declare const withConfigOverride: { (overrides: typeof Config.Service): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, Config>> <A, E, R>(self: Effect.Effect<A, E, R>, overrides: typeof Config.Service): Effect.Effect<A, E, Exclude<R, Config>>}Since v4.0.0
constructors
Section titled “constructors”Creates an OpenAI-compatible embedding model service backed by OpenAiClient.
When to use
Use when you need to build or provide an EmbeddingModel service directly
from an existing OpenAiClient.
Details
The service sends embedding requests through OpenAiClient.createEmbedding.
Request config is merged as the selected model, constructor config, then
scoped Config, so scoped overrides take precedence. Provider usage
prompt_tokens is exposed as usage.inputTokens.
Gotchas
Provider responses must contain one numeric vector for every requested input
with unique, in-range index values; otherwise embedding operations fail with
AiError.InvalidOutputError.
See
modelfor the higher-levelAiModeldescriptor that also providesEmbeddingModel.Dimensionslayerfor providing the service as aLayerwithConfigOverridefor scoping embedding request overrides
Signature
declare const make: (args_0: { readonly model: string readonly config?: Omit<typeof Config.Service, "model"> | undefined}) => Effect.Effect<EmbeddingModel.Service, never, OpenAiClient>Since v4.0.0
Creates an AiModel for an OpenAI-compatible embedding model with its configured vector dimensions.
When to use
Use to provide an OpenAI-compatible EmbeddingModel and its Dimensions
service to an Effect program.
See
layerfor providing only the embedding model servicewithConfigOverridefor scoped request configuration overrides
Signature
declare const model: ( model: string, options: { readonly dimensions: number; readonly config?: Omit<typeof Config.Service, "model" | "dimensions"> }) => AiModel.Model<"openai", EmbeddingModel.EmbeddingModel | EmbeddingModel.Dimensions, OpenAiClient>Since v4.0.0
context
Section titled “context”Config (class)
Section titled “Config (class)”Context service for OpenAI embedding model configuration.
When to use
Use when you need to provide shared default request options for
OpenAI-compatible embedding operations through the Effect context, such as
dimensions, encoding_format, or user.
Details
The service stores the embedding request payload without input. Requests
combine the selected model, layer or constructor config, and scoped context
config, with scoped context config taking precedence.
See
withConfigOverridefor scoping embedding request overrides
Signature
declare class ConfigSince v4.0.0
layers
Section titled “layers”Creates a layer for an OpenAI-compatible embedding model service.
When to use
Use when composing application layers and you want an OpenAI-compatible
embeddings endpoint to satisfy EmbeddingModel.EmbeddingModel while
supplying OpenAiClient from another layer.
See
makefor constructing the embedding model service effectfullymodelfor creating anAiModelwith configured dimensions
Signature
declare const layer: (options: { readonly model: string readonly config?: Omit<typeof Config.Service, "model"> | undefined}) => Layer.Layer<EmbeddingModel.EmbeddingModel, never, OpenAiClient>Since v4.0.0
models
Section titled “models”Model (type alias)
Section titled “Model (type alias)”A model identifier accepted by an OpenAI-compatible embeddings endpoint.
Signature
type Model = stringSince v4.0.0