VEC_DISTANCE_COSINE

MariaDB starting with 11.7
Vectors were introduced in MariaDB 11.7
Syntax
VEC_DISTANCE_COSINE(v, s)
Description
VEC_Distance_Cosine
is an SQL function that calculates a Cosine distance between two vectors.
If the vector index was not built for the cosine function (see CREATE TABLE with Vectors), the index will not be used, and a full table scan 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?