Create text embeddings

The Resources.Embed class provides methods to create text embeddings.

Create text embeddings

Description: This method creates a new text embedding.

Function signature and example:

async create(
  { engineName, text, textTruncate }: CreateEmbedParams,
  options: RequestOptions = {},
): Promise<Models.CreateEmbeddingsResult>
const embedding = await client.embed.create({
  engineName: 'Marengo-retrieval-2.6',
  textTruncate: 'start',
  text: '<YOUR_TEXT>
});

console.log("Created a text embedding")
console.log(`  Engine: ${embedding.engineName}`);
console.log(`  Embedding: ${embedding.textEmbedding.float}`)

Parameters:

NameTypeRequiredDescription
paramsCreateEmbedParamsYesParameters for creating the text embedding.
optionsRequestOptionsNoAdditional options for the request. Defaults to {}.

The CreateEmbedParams interface defines the parameters for creating a text embedding.

NameTypeRequiredDescription
engineNamestringYesThe name of the video understanding engine to use. Example: "Marengo-retrieval-2.6".
textstringYesThe text for which you want to create an embedding.
textTruncate'none' | 'start' | 'end'NoSpecifies how to truncate the text if it exceeds the maximum length of 77 tokens.

Return value: Returns a Promise that resolves to a Models.CreateEmbeddingsResult instance.

API Reference: For a description of each field in the request and response, see the Create text embeddings page.

Related guide: Create text embeddings.