Skip to content

Commit

Permalink
Update query_rewriter.go
Browse files Browse the repository at this point in the history
cosine and dot into distance
  • Loading branch information
rderbier committed May 7, 2024
1 parent 117de1b commit f1ece2b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions graphql/resolve/query_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,9 @@ func rewriteAsSimilarByIdQuery(
distanceFormula := "math((v2 - v1) dot (v2 - v1))" // default - euclidian

if metric == schema.SimilarSearchMetricDotProduct {
distanceFormula = "math(v1 dot v2)"
distanceFormula = "math((1.0 - (v1 dot v2)) /2.0)"
} else if metric == schema.SimilarSearchMetricCosine {
distanceFormula = "math((v1 dot v2) / ((v1 dot v1) * (v2 dot v2)))"
distanceFormula = "math((1.0 - ((v1 dot v2) / ((v1 dot v1) * (v2 dot v2)))) / 2.0)"
}

// First generate the query to fetch the uid
Expand Down Expand Up @@ -822,7 +822,7 @@ func rewriteAsSimilarByEmbeddingQuery(
distanceFormula := "math((v2 - $search_vector) dot (v2 - $search_vector))" // default = euclidian

if metric == schema.SimilarSearchMetricDotProduct {
distanceFormula = "math(($search_vector) dot v2)"
distanceFormula = "math(( 1.0 - (($search_vector) dot v2)) /2.0)"
} else if metric == schema.SimilarSearchMetricCosine {
distanceFormula = "math(( ($search_vector) dot v2) / (( ($search_vector) dot ($search_vector)) * (v2 dot v2)))"
}
Expand Down

0 comments on commit f1ece2b

Please sign in to comment.