public class CosineSimilarity extends Object
| Constructor and Description |
|---|
CosineSimilarity() |
| Modifier and Type | Method and Description |
|---|---|
static double |
between(Embedding embeddingA,
Embedding embeddingB)
Calculates cosine similarity between two vectors.
|
static double |
fromRelevanceScore(double relevanceScore)
Converts relevance score into cosine similarity.
|
public static double between(Embedding embeddingA, Embedding embeddingB)
Cosine similarity measures the cosine of the angle between two vectors, indicating their directional similarity. It produces a value in the range:
-1 indicates vectors are diametrically opposed (opposite directions).
0 indicates vectors are orthogonal (no directional similarity).
1 indicates vectors are pointing in the same direction (but not necessarily of the same magnitude).
Not to be confused with cosine distance ([0..2]), which quantifies how different two vectors are.
embeddingA - first embedding vectorembeddingB - second embedding vectorpublic static double fromRelevanceScore(double relevanceScore)
relevanceScore - Relevance score in the range [0..1] where 0 is not relevant and 1 is relevant.Copyright © 2023. All rights reserved.