Whatever message this page gives is out now! Go check it out!

Embed

Last update:
May 18, 2026

Description

Generates an embedding vector for a single text input using the configured embedding model. This is typically used for:
  • indexing documents into a VectorStore, or
  • creating a query vector for similarity search.

Returns

A struct containing:
  • embeddings – the embedding vector (array of numbers)
  • tokenUsage – provider‑specific token usage metrics (if available)
  • finishReason – reason the call completed (if provided by the provider)
  • metadata – additional metadata returned by the provider

Syntax

embed(string text)

Usage

Use embed() for one‑off embedding generation, such as:
  • embedding a single user query before calling vectorStoreClient.search({vector: ...}), or
  • embedding a newly created document you’re about to upsert into a VectorStore.
For batch ingestion of many texts, prefer embedAll() to reduce overhead.

Example

<cfscript>
    // Assume embeddingModel was created via GetEmbeddingModel(embedConfig)

    inputText = "ColdFusion integrates AI models and vector databases.";

    result = embeddingModel.embed(inputText);

    // result is a struct with:
    // - result.embeddings   : array of numeric values (the vector)
    // - result.tokenUsage   : provider-specific token stats (if supported)
    // - result.finishReason : string (if provided)
    // - result.metadata     : struct with extra information (if any)

    writeOutput("<h4>Single embedding result</h4>");
    writeDump(result);

    // Use the embedding vector directly with a VectorStore search, e.g.:
    //
    // queryVector = result.embeddings;
    // searchResult = vectorStoreClient.search({ vector: queryVector, topK: 5 });
</cfscript>

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page