Skip to content

Function: embedding()

@providerprotocol/ai


@providerprotocol/ai / @providerprotocol/ai / embedding

embedding<TParams>(options): EmbeddingInstance<TParams>

Defined in: src/core/embedding.ts:370

Creates an embedding instance configured with the specified options.

This is the primary factory function for creating embedding instances. It validates provider capabilities, binds the model, and returns an instance with an embed method for generating embeddings.

TParams = unknown

Provider-specific parameter type

EmbeddingOptions<TParams>

Configuration options for the embedding instance

EmbeddingInstance<TParams>

A configured embedding instance ready for use

When the provider does not support the embedding modality

import { embedding } from 'upp';
import { openai } from 'upp/openai';
const embedder = embedding({
model: openai('text-embedding-3-large'),
params: { dimensions: 1536 }
});
// Single input
const result = await embedder.embed('Hello world');
// Batch input
const batch = await embedder.embed(['doc1', 'doc2', 'doc3']);
// Large-scale with progress
const stream = embedder.embed(documents, { chunked: true });
for await (const progress of stream) {
console.log(`${progress.percent}% complete`);
}