Skip to content

Commit

Permalink
Re-situating distance metrics for vector similarity (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavdangeti authored Nov 16, 2023
1 parent 315ab2b commit bdca567
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,24 @@ type VectorField interface {
// Similarity metric to be used for scoring the vectors
Similarity() string
}

// -----------------------------------------------------------------------------

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"
)

const DefaultSimilarityMetric = EuclideanDistance

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

0 comments on commit bdca567

Please sign in to comment.