COSINE_SIMILARITY
All functions > ARRAY > COSINE_SIMILARITY
Calculates the cosine similarity between two arrays.
Syntax
COSINE_SIMILARITY(array1, array2)
sql
Arguments
Parameter | Type | Required | Description |
---|---|---|---|
array1 | ARRAYDOUBLE | Yes | First vector (array of doubles) |
array2 | ARRAYDOUBLE | Yes | Second vector (array of doubles) |
Returns
DOUBLE - Cosine similarity between -1 and 1
Notes
- Measures angle between two vectors
- Formula: dot(x,y) / (||x|| * ||y||)
- Returns value between -1 (opposite) and 1 (same direction)
- Arrays must be same length
- Used in text similarity and recommendation systems