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

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.