- Categories:
VECTOR_INNER_PRODUCTΒΆ
Computes the inner product of two vectors.
The inner product (also known as the dot or scalar product) multiplies two vectors. The result represents the combined direction of the two vectors. Similar vectors result in larger inner products than dissimilar ones.
SyntaxΒΆ
VECTOR_INNER_PRODUCT( <vector>, <vector> )
ArgumentsΒΆ
vector
First VECTOR value.
vector
Second VECTOR value.
ReturnsΒΆ
Returns a VECTOR that is the inner product of the two vectors given as inputs.
Usage notesΒΆ
Due to computational optimizations in the vector comparison functions, floating-point errors might be slightly larger than usual (that is, about 1e-4).
ExamplesΒΆ
This example uses the VECTOR_INNER_PRODUCT function to determine which vectors in the table
are closest to each other between columns a
and b
:
CREATE TABLE vectors (a VECTOR(FLOAT, 3), b VECTOR(FLOAT, 3));
INSERT INTO vectors SELECT [1.1,2.2,3]::VECTOR(FLOAT,3), [1,1,1]::VECTOR(FLOAT,3);
INSERT INTO vectors SELECT [1,2.2,3]::VECTOR(FLOAT,3), [4,6,8]::VECTOR(FLOAT,3);
-- Compute the pairwise inner product between columns a and b
SELECT VECTOR_INNER_PRODUCT(a, b) FROM vectors;
+------+
| 6.3 |
|------|
| 41.2 |
+------+