VECTOR_COSINE_SIMILARITY
functionsupportedAI & MLComputes the cosine similarity between two vectors. Cosine similarity is based on the angle between two vectors in a multi-dimensional space; the magnitude of the vectors is not considered. The cosine similarity value is the inner product of the vectors divided by the product of their lengths. The cosine similarity is always in the interval [-1, 1]. For example, identical vectors have a cosine similarity of 1, two orthogonal vectors have a similarity of 0, and two opposite vectors have a similarity of -1.
Syntax
VECTOR_COSINE_SIMILARITY( <vector>, <vector> )
Parameters
| Name | Required | Description |
|---|---|---|
vector | required | The VECTOR value to calculate the angle from. |
vector | required | The VECTOR value to calculate the angle to. |
Returns
Returns a FLOAT value in the interval [-1, 1], which indicates the cosine similarity between the two input vectors.
Usage notes
- Vector functions are optimized in a way that can reduce floating point precision. This function’s results have a margin of error up to 1e-4.