AddEmbeddings

Adds two embedding vectors and returns the result as a normalized vector.

Format 

AddEmbeddings ( v1 ; v2 )

Parameters 

v1 and v2 - any text expression, text field, or container field that contains embedding vectors with the same dimensions.

Data type returned 

text, container

Originated in version 

22.0

Description 

This function performs vector addition on two embedding vectors and returns the result as a normalized vector. Normalization focuses the resulting vector on its semantic direction rather than its magnitude, which is standard practice for comparing or manipulating embeddings.

Use this function to combine the semantic meaning of two concepts represented by vectors. For example, adding the vector for "I like dogs" and the vector for "I like cats" might result in a vector that represents a concept closer to "I like pets" or "I like both dogs and cats." This can be useful in semantic search to broaden concepts or in data analysis to find aggregated meanings.

If v1 and v2 are text, they must be in the form of JSON arrays. Typically, though, using embedding vectors as binary container data improves performance.

Notes 

  • Embedding vectors must be generated from the same model to ensure compatibility and performance; mixing embedding vectors from different models isn't supported.

  • This function returns "?" if:

    • If v1 and v2 have different dimensions

    • Or the result is a zero vector (which can happen if v1 and v2 are identical but have opposite signs), because the function can't normalize a zero vector

Example 1 

AddEmbeddings ( "[1, 2, 3]" ; "[4, 5, 6]" ) returns [0.40160966445124940405, 0.56225353023174917677, 0.722897396012249005]. The addition is [1+4, 2+5, 3+6] = [5, 7, 9]. Then the function normalizes this vector and returns it as a JSON array because both inputs were text.

Example 2 

AddEmbeddings ( Products::Smartphone_Embedding ; Products::Premium_Embedding ) returns container data for the normalized vector that represents the combined concept of "premium smartphone."

This example assumes the Products::Smartphone_Embedding field contains the embedding vector for the text "smartphone" and Products::Premium_Embedding contains the embedding vector for the text "premium." The resulting vector could be used with the Perform Semantic Find script step to find product descriptions that are semantically close to this combined concept.