`COSINE_SIMILARITY`

Data 360 Query Guide, mirrored from developer.salesforce.com: **Applies to:** ✅ Data 360 SQL ✅ Tableau Hyper API

markdownreferencev13X3T-JVMBguide: data-cloud-query-guidestage: referencetrust: officialsource: developer.salesforce.comservice: data360interface: sql`COSINE_SIMILARITY`Data 360Data CloudData 360 Query Guide

Created 23 Oct 2026 · Modified 23 Oct 2026 · 1 version

Mirror of <https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference/cosine-similarity.html> (Salesforce, Data 360 Query Guide), read 2026-10-23. Salesforce's own page is the authority; this copy exists because that site refuses non-browser readers.

COSINE_SIMILARITY

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Computes the cosine similarity between two vectors, measuring directional alignment.

  • <array1>: The first vector (array(real) or array(double-precision)).
  • <array2>: The second vector (array(real) or array(double-precision)).

Returns a double-precision value between -1 and 1, where 1 indicates identical direction, 0 indicates orthogonal, and -1 indicates opposite direction.

  • Both input arrays must be of the same element type and length.
  • If any element is NULL, the result is NULL.
  • Zero vectors cause division by zero.
  • For optimal performance, use array definitions with non-nullable elements.

Compute the cosine similarity between two vectors.

Returns approximately -0.42857, indicating the vectors are somewhat opposed in direction.

Read this document as markdown — the same bytes an agent receives.