Skip to main content Link Menu Expand (external link) Document Search Copy Copied

SELECT FROM cosvec-target

Before you begin

Comparing distance metrics

FeatureBase supplies two functions to measure VECTOR data type values:

  • cosine_distance measures the similarity of angles between two vectors, and is unaffected by their magnitude
  • euclidean distance measures the distance between points, rather than the angle between vectors

The following example illustrates the difference between these measures:

SELECT cosine_distance([1.0, 0.0], [0.0, 1.0]) as cos_1_0,
       euclidean_distance([1.0, 0.0], [0.0, 1.0]) as euc_1_0,
       cosine_distance([2.0, 0.0], [0.0, 2.0]) as cos_2_0,
       euclidean_distance([2.0, 0.0], [0.0, 2.0]) as euc_2_0;

 cos_1_0 |   euc_1_0 | cos_2_0 |  euc_2_0
---------+-----------+---------+----------
       1 | 1.4142135 |       1 | 2.828427

Further information