Skip to content

Commit

Permalink
MB-62354: Support Cosine Similarity (#52)
Browse files Browse the repository at this point in the history
* MB-62354: Support Cosine Similarity

* resolve comment

* fix overflow

* code review
  • Loading branch information
CascadingRadium authored Aug 5, 2024
1 parent 468428b commit a428bcb
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,17 @@ type VectorField interface {
const (
EuclideanDistance = "l2_norm"

// dotProduct(vecA, vecB) = vecA . vecB = |vecA| * |vecB| * cos(theta);
// where, theta is the angle between vecA and vecB
// If vecA and vecB are normalized (unit magnitude), then
// vecA . vecB = cos(theta), which is the cosine similarity.
// Thus, we don't need a separate similarity type for cosine similarity
CosineSimilarity = "dot_product"
InnerProduct = "dot_product"

CosineSimilarity = "cosine"
)

const DefaultSimilarityMetric = EuclideanDistance

// Supported similarity metrics for vector fields
var SupportedSimilarityMetrics = map[string]struct{}{
EuclideanDistance: {},
InnerProduct: {},
CosineSimilarity: {},
}

Expand Down

0 comments on commit a428bcb

Please sign in to comment.