QVAC Logo

embed( )

Generates embeddings for a single text using a specified model.

function embed(params: { modelId: string; text: string }): Promise<number[]>;
function embed(params: { modelId: string; text: string[] }): Promise<number[][]>;

Parameters

NameTypeRequired?Description
paramsEmbedParamsThe embedding parameters

EmbedParams

FieldTypeRequired?Description
modelIdstringThe identifier of the embedding model to use
textstring | string[]The input text(s) to embed. A single string returns number[]; an array returns number[][].

Returns

  • Promise<number[]> — When text is a single string, returns the embedding vector.
  • Promise<number[][]> — When text is an array, returns an array of embedding vectors.

Throws

ErrorWhen
INVALID_RESPONSE_TYPEResponse type does not match expected "embed"

Examples

// Single text
const vector = await embed({ modelId: "embedding-model", text: "Hello world" });
console.log(vector.length); // e.g. 384

// Multiple texts (batch)
const vectors = await embed({
  modelId: "embedding-model",
  text: ["Hello world", "How are you?"]
});
console.log(vectors.length); // 2

On this page