Function: embedding()
@providerprotocol/ai / @providerprotocol/ai / embedding
Function: embedding()
Section titled “Function: 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.
Type Parameters
Section titled “Type Parameters”TParams
Section titled “TParams”TParams = unknown
Provider-specific parameter type
Parameters
Section titled “Parameters”options
Section titled “options”EmbeddingOptions<TParams>
Configuration options for the embedding instance
Returns
Section titled “Returns”EmbeddingInstance<TParams>
A configured embedding instance ready for use
Throws
Section titled “Throws”When the provider does not support the embedding modality
Example
Section titled “Example”import { embedding } from 'upp';import { openai } from 'upp/openai';
const embedder = embedding({ model: openai('text-embedding-3-large'), params: { dimensions: 1536 }});
// Single inputconst result = await embedder.embed('Hello world');
// Batch inputconst batch = await embedder.embed(['doc1', 'doc2', 'doc3']);
// Large-scale with progressconst stream = embedder.embed(documents, { chunked: true });for await (const progress of stream) { console.log(`${progress.percent}% complete`);}