All pages
Powered by GitBook
1 of 1

Loading...

VEC_DISTANCE_COSINE

Calculate Cosine distance. This function computes the Cosine distance between two vectors, measuring the cosine of the angle between them.

Syntax

VEC_DISTANCE_COSINE(v, s)

Description

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.

Example

See Also

This page is licensed: CC BY-SA / Gnu FDL

Cosine distance
CREATE TABLE with Vectors
VEC_DISTANCE
VEC_DISTANCE_EUCLIDEAN
VEC_DISTANCE
VEC_DISTANCE_EUCLIDEAN
Vector Overview
CREATE TABLE with Vectors
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 |
+-----------------------------------------------------------------------+

Vectors are available from .

Cover

WEBINAR

The Next Generation of MariaDB: Powered by Vector Search

Watch Now
MariaDB 11.7