Open History to see the last commit
1---
2id: embed
3title: embed
4---
5
6```ts
7function embed<TAdapter>(options): Promise<EmbeddingResult>;
8```
9
10Defined in: packages/ai/src/activities/embed/index.ts:190
11
12Embed activity - generates embedding vectors from text and image inputs.
13
14Accepts a single item or an array of items; the result always carries an
15`embeddings` array with one vector per input item, in input order.
16
17## Type Parameters
18
19### TAdapter
20
21`TAdapter` *extends* [`EmbeddingAdapter`](../interfaces/EmbeddingAdapter.md)\<`string`, `any`, `any`, `any`\>
22
23## Parameters
24
25### options
26
27`EmbedOptions`\<`TAdapter`\>
28
29## Returns
30
31`Promise`\<[`EmbeddingResult`](../interfaces/EmbeddingResult.md)\>
32
33## Examples
34
35**Embed a single text**
36
37```ts
38import { embed } from '@tanstack/ai'
39import { openaiEmbedding } from '@tanstack/ai-openai'
40
41const result = await embed({
42 adapter: openaiEmbedding('text-embedding-3-small'),
43 input: 'a red guitar',
44})
45
46console.log(result.embeddings[0].vector)
47```
48
49**Batch with requested dimensions**
50
51```ts
52const result = await embed({
53 adapter: openaiEmbedding('text-embedding-3-large'),
54 input: ['a red guitar', 'a blue drum kit'],
55 dimensions: 1024,
56})
57```
58
59**Multimodal embedding (text + image fused into one vector)**
60
61```ts
62import { cohereEmbedding } from '@tanstack/ai-cohere'
63
64// A nested array of parts fuses them into a single vector. The outer array
65// is the item list, so this embeds one fused item into one vector.
66const result = await embed({
67 adapter: cohereEmbedding('embed-v4.0'),
68 input: [
69 [
70 { type: 'text', content: 'product photo' },
71 { type: 'image', source: { type: 'data', value: base64, mimeType: 'image/png' } },
72 ],
73 ],
74 modelOptions: { inputType: 'search_document' },
75})
76```