@@ -32,8 +32,29 @@ private HnswDistanceType() { }
3232 * The default; typically "Euclidean squared" internally.
3333 */
3434 public static final short Euclidean = 1 ;
35+ /**
36+ * Cosine similarity compares two vectors irrespective of their magnitude (compares the angle of two vectors).
37+ * Often used for document or semantic similarity.
38+ * Value range: 0.0 - 2.0 (0.0: same direction, 1.0: orthogonal, 2.0: opposite direction)
39+ */
40+ public static final short Cosine = 2 ;
41+ /**
42+ * For normalized vectors (vector length == 1.0), the dot product is equivalent to the cosine similarity.
43+ * Because of this, the dot product is often preferred as it performs better.
44+ * Value range (normalized vectors): 0.0 - 2.0 (0.0: same direction, 1.0: orthogonal, 2.0: opposite direction)
45+ */
46+ public static final short DotProduct = 3 ;
47+ /**
48+ * A custom dot product similarity measure that does not require the vectors to be normalized.
49+ * Note: this is no replacement for cosine similarity (like DotProduct for normalized vectors is).
50+ * The non-linear conversion provides a high precision over the entire float range (for the raw dot product).
51+ * The higher the dot product, the lower the distance is (the nearer the vectors are).
52+ * The more negative the dot product, the higher the distance is (the farther the vectors are).
53+ * Value range: 0.0 - 2.0 (nonlinear; 0.0: nearest, 1.0: orthogonal, 2.0: farthest)
54+ */
55+ public static final short DotProductNonNormalized = 10 ;
3556
36- public static final String [] names = { "Unknown" , "Euclidean" , };
57+ public static final String [] names = { "Unknown" , "Euclidean" , "Cosine" , "DotProduct" , "" , "" , "" , "" , "" , "" , "DotProductNonNormalized" , };
3758
3859 public static String name (int e ) { return names [e ]; }
3960}
0 commit comments