Calculate Cosine distance. This function computes the Cosine distance between two vectors, measuring the cosine of the angle between them.
VEC_DISTANCE_COSINE(v, s)VEC_Distance_Cosine is an SQL function that calculates the 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 ), the index is not used — a full table scan is performed instead. The function is a generic function that behaves either as or VEC_DISTANCE_COSINE, depending on the underlying index type.
This page is licensed: CC BY-SA / Gnu FDL
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 |
+-----------------------------------------------------------------------+
WEBINAR
The Next Generation of MariaDB: Powered by Vector Search