Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Tools · Function

embed

Generates an embedding for one value with an embedding model. The returned object includes the original value and its numeric embedding vector.

How it works

embed sends one value to the selected embedding model and asynchronously returns both the original value and its numeric embedding vector. The value's type depends on the model, while the returned embedding can be used for similarity retrieval or downstream processing.

Syntax

embed({ model, value })】【。

Parameters

NameTypeDescription
modelEmbeddingModelThe embedding model to use.
valueVALUEThe value to embed. The type depends on the model.

Returns

An object containing value (the embedded input) and embedding (number[]), the embedding vector.

Key points

  • Use embed when one input value must be converted into an embedding.
  • It is intended for one-off embedding operations rather than batch embedding.
  • Typical uses include similarity retrieval and feeding the vector into later processing.
  • Provide the embedding model through the model parameter.
  • Provide the single input through the value parameter.
  • Read the resulting numeric vector from the returned embedding property.

Common mistakes

  • The value type is model-dependent, so pass the kind of input supported by the chosen embedding model.

Example: Embed one value

import { embed } from 'ai';

const { embedding } = await embed({
  model: 'openai/text-embedding-3-small',
  value: 'sunny day at the beach',
});

console.log(embedding);

Creates a numeric embedding for one text value and prints the resulting vector.

When to use it

Similarity retrieval

Convert a single document, query, or phrase into a vector for similarity search.

Vector indexing

Create vectors for one-off inputs before storing or comparing them.

Downstream processing

Pass an embedding into a downstream ranking, clustering, or classification workflow.

  • embedMany
  • EmbeddingModel
  • embeddingModel

Source: embed. Checked 2026-10-15.