VEC_DISTANCE_COSINE

Syntax
VEC_DISTANCE_COSINE(v, s)Description
VEC_Distance_Cosine is an SQL function that calculates the Cosine distance between two (not necessarily normalized) vectors.
Vectors must be of the same length. A distance between two vectors of different lengths is not defined, and VEC_Distance_Cosine will return NULL in such cases.
If the vector index was not built for the cosine function (see CREATE TABLE with Vectors), the index is not used — a full table scan is performed instead. The VEC_DISTANCE function is a generic function that behaves either as VEC_DISTANCE_EUCLIDEAN or VEC_DISTANCE_COSINE, depending on the underlying index type.
Example
SELECT VEC_DISTANCE_COSINE(vec_fromtext('[1,2,3]'), vec_fromtext('[3,5,7]'));
+-----------------------------------------------------------------------+
| VEC_DISTANCE_COSINE(vec_fromtext('[1,2,3]'), vec_fromtext('[3,5,7]')) |
+-----------------------------------------------------------------------+
| 0.00258509695694209 |
+-----------------------------------------------------------------------+See Also
This page is licensed: CC BY-SA / Gnu FDL
Last updated
Was this helpful?

