VECTOR_INNER_PRODUCT

Returns the inner product, also known as the dot or scalar product, between two vectors. The inner product measures how closely two vectors align with each other, both in magnitude and the cosine of the angle between them. It is calculated by multiplying the corresponding elements of the vectors and then summing the results.

If the vectors have similar directions and large magnitudes, the inner product has a large positive value. If they are orthogonal, the inner product is zero, regardless of magnitude. If they point in roughly opposite directions, and at least one has a small magnitude, the inner product is small and negative.

Syntax

VECTOR_INNER_PRODUCT(<array>, <array>)

Parameters

Parameter Description Supported input types
<array> The first array used in the inner product calculation. Any array of numeric data types.
<array> The second array used in the inner product calculation. Any array of numeric data types.

Notes

Both input array arguments must have the same number of elements.

Return Type

DOUBLE

Examples

The following example returns the inner product of two vectors that have similar directions and magnitudes:

SELECT VECTOR_INNER_PRODUCT([1, 2], [3, 4]) AS product;
product (DOUBLE)
11

The following example returns the inner product of two vectors that are orthogonal to each other:

SELECT VECTOR_INNER_PRODUCT([3, 4], [-4, 3]) AS product;
product (DOUBLE)
0

The following example returns the inner product of two vectors that are pointing in very different directions that are not orthogonal:

SELECT VECTOR_INNER_PRODUCT([3, 4], [4, -2]) AS product;
product (DOUBLE)
4