QVAC Logo

embed( )

Generates embeddings for a single text using a specified model.

function embed(params: { modelId: string; text: string }, options?: RPCOptions): Promise<{ embedding: number[]; stats?: EmbedStats }>;
function embed(params: { modelId: string; text: string[] }, options?: RPCOptions): Promise<{ embedding: number[][]; stats?: EmbedStats }>;

Parameters

NameTypeRequired?Description
paramsEmbedParamsThe embedding parameters
optionsRPCOptionsOptional RPC transport options

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<object> — Resolves to an object with the following fields:

FieldTypeDescription
embeddingnumber[] | number[][]The embedding vector(s). Single number[] when text is a string; number[][] when text is an array.
statsEmbedStats | undefinedPerformance statistics

EmbedStats

FieldTypeDescription
totalTimenumber | undefinedTotal embedding time in milliseconds
tokensPerSecondnumber | undefinedTokens processed per second
totalTokensnumber | undefinedTotal tokens processed
backendDevice"cpu" | "gpu" | undefinedCompute backend used for inference

Throws

ErrorWhen
INVALID_RESPONSE_TYPEResponse type does not match expected "embed"

Examples

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

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

On this page