function embed<TAdapter>(options): Promise<EmbeddingResult>;Defined in: packages/ai/src/activities/embed/index.ts:189
Embed activity - generates embedding vectors from text and image inputs.
Accepts a single item or an array of items; the result always carries an embeddings array with one vector per input item, in input order.
TAdapter extends EmbeddingAdapter<string, any, any, any>
EmbedOptions<TAdapter>
Promise<EmbeddingResult>
Embed a single text
import { embed } from '@tanstack/ai'
import { openaiEmbedding } from '@tanstack/ai-openai'
const result = await embed({
adapter: openaiEmbedding('text-embedding-3-small'),
input: 'a red guitar',
})
console.log(result.embeddings[0].vector)Batch with requested dimensions
const result = await embed({
adapter: openaiEmbedding('text-embedding-3-large'),
input: ['a red guitar', 'a blue drum kit'],
dimensions: 1024,
})Multimodal embedding (text + image fused into one vector)
import { cohereEmbedding } from '@tanstack/ai-cohere'
// A nested array of parts fuses them into a single vector. The outer array
// is the item list, so this embeds one fused item into one vector.
const result = await embed({
adapter: cohereEmbedding('embed-v4.0'),
input: [
[
{ type: 'text', content: 'product photo' },
{ type: 'image', source: { type: 'data', value: base64, mimeType: 'image/png' } },
],
],
modelOptions: { inputType: 'search_document' },
})