Vector distance functions

  • Latest Dynatrace
  • Reference
  • Published Mar 06, 2025

vectorL1Distance

Calculates the taxicab distance between numeric array expressions. It can be used to query embedding vectors that are most similar (for example, have the lowest distance) to a given vector.

Syntax

vectorL1Distance(firstExpression, secondExpression)

Parameters

Returns

The data type of the returned value is double. Returns null for arrays of different lengths and arrays of other types.

Examples

Example 1
data record(a = array(1, 1, 1), b = array(1, 2, 3)),
record(a = array(1.0, 1.0, 1.0), b = array(1.0, 2.0, 3.0)),
record(a = array(1, 2), b = array(1, 2)),
record(a = array(1, 2), b = array(1, 2, 3)),
record(a = array(1, 2), b = array(1, "foo"))
| fields a, b, vectorL1Distance(a, b)

Query result:

vectorL2Distance

Calculates the Euclidean distance between numeric array expressions. It can be used to query embedding vectors that are most similar (for example, have the lowest distance) to a given vector.

Syntax

vectorL2Distance(firstExpression, secondExpression)

Parameters

Returns

The data type of the returned value is double. Returns null for arrays of different lengths and arrays of other types.

Examples

Example 1
data record(a = array(1, 1, 1), b = array(1, 2, 3)),
record(a = array(1.0, 1.0, 1.0), b = array(1.0, 2.0, 3.0)),
record(a = array(1, 2), b = array(1, 2)),
record(a = array(1, 2), b = array(1, 2, 3)),
record(a = array(1, 2), b = array(1, "foo"))
| fields a, b, vectorL2Distance(a, b)

Query result:

vectorCosineDistance

Calculates the cosine distance between numeric array expressions. It can be used to query embedding vectors that are most similar (for example, have the lowest distance) to a given vector.

Syntax

vectorCosineDistance(firstExpression, secondExpression)

Parameters

Returns

The data type of the returned value is double. Returns null for arrays of different lengths and arrays of other types.

Examples

Example 1
data record(a = array(1, 1, 1), b = array(1, 2, 3)),
record(a = array(1.0, 1.0, 1.0), b = array(1.0, 2.0, 3.0)),
record(a = array(1, 2), b = array(1, 2)),
record(a = array(1, 2), b = array(1, 2, 3)),
record(a = array(1, 2), b = array(1, "foo"))
| fields a, b, vectorCosineDistance(a, b)

Query result:

vectorInnerProductDistance

Calculates the negative dot product between numeric array expressions. It can be used to query embedding vectors that are most similar to a given vector.

Syntax

vectorInnerProductDistance(firstExpression, secondExpression)

Parameters

Returns

The data type of the returned value is double. Returns null for arrays of different lengths and arrays of other types.

Examples

Example 1
data record(a = array(1, 1, 1), b = array(1, 2, 3)),
record(a = array(1.0, 1.0, 1.0), b = array(1.0, 2.0, 3.0)),
record(a = array(1, 2), b = array(1, 2)),
record(a = array(1, 2), b = array(1, 2, 3)),
record(a = array(1, 2), b = array(1, "foo"))
| fields a, b, vectorInnerProductDistance(a, b)

Query result:

Related tags
Dynatrace Platform