Skip to main content

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. Alias: inner_product (aligned with pgvector for compatibility)

Syntax

Parameters

Notes

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

Return Type

DOUBLE

Examples

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

Rows: 1Execution time: 6.29ms

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

Rows: 1Execution time: 5.46ms

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

Rows: 1Execution time: 5.81ms