The llm_embedding function generates vector embeddings that represent the semantic meaning of text from specified table columns.

Modalities

Text

Supported. Pass one or more text columns in context_columns.

Image

Not supported directly. Describe the image with llm_complete (type: 'image'), then embed the description.

Voice

Not supported on raw audio. Transcribe with llm_complete (type: 'audio'), then embed the transcript.

1. Simple Usage (without data)

1.1 Basic Embedding Generation

Description: This example generates vector embeddings for each product, combining the product_name and product_description columns using the text-embedding-3-small model. The output is a semantic vector that represents the content of the product’s name and description.
Description: This example demonstrates how to use the vector embeddings for similarity search. It calculates the cosine similarity between embeddings of different products to find similar items based on their semantic meaning. Only product pairs with a similarity greater than 0.8 are included.

2. Input Parameters

The llm_embedding function accepts two primary inputs: model configuration and column mappings.

2.1 Model Configuration

  • Parameter: model_name and secret_name

2.1.1 Model Selection

  • Description: Specifies the model used for text generation.
  • Example:

2.1.2 Model Selection with Secret

  • Description: Specifies the model along with the secret name to be used for authentication when accessing the model.
  • Example:

2.2 Context Columns Configuration

  • Parameter: context_columns array
  • Description: Specifies the text columns from the table to be passed to the model for embedding generation. Each column can have two properties:
    • data: The SQL column data (required)
    • name: Custom name for the column (optional)
  • Note: Embeddings are text-only. For image or voice content, derive text first (see Modalities above).
  • Example:

3. Output

The function returns a JSON array containing floating-point numbers that represent the semantic vector of the input text. Example Output:
For a product with the description “Wireless headphones with noise cancellation”, the output might look like this:
This array of floating-point numbers encodes the semantic meaning of the product description in high-dimensional space.