- 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.
- See also:
VECTOR_L2_DISTANCE , VECTOR_COSINE_SIMILARITY , Vector Embeddings
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 may be slightly larger than usual (e.g. 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 |
+------+