COSINE_SIMILARITY

All functions > ARRAY > COSINE_SIMILARITY

Calculates the cosine similarity between two arrays.

Signatures

Returns: Cosine similarity between -1 and 1

COSINE_SIMILARITY(array1: ARRAY<DOUBLE>, array2: ARRAY<DOUBLE>) → DOUBLE
sql
ParameterTypeRequiredDescription
array1ARRAY<DOUBLE>YesFirst vector (array of doubles)
array2ARRAY<DOUBLE>YesSecond vector (array of doubles)

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
Last update at: 2026/03/03 16:47:38
Last updated: 2026-03-03 16:48:19