Skip to content

Commit

Permalink
MB-59692: Upgrade to [email protected]
Browse files Browse the repository at this point in the history
Use re-situated SimilarityMetrics constants.
  • Loading branch information
abhinavdangeti committed Nov 16, 2023
1 parent 9440161 commit e6299d4
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 52 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ go 1.20
require (
github.com/RoaringBitmap/roaring v1.2.3
github.com/bits-and-blooms/bitset v1.2.0
github.com/blevesearch/bleve_index_api v1.1.2
github.com/blevesearch/bleve_index_api v1.1.3
github.com/blevesearch/geo v0.1.18
github.com/blevesearch/go-metrics v0.0.0-20201227073835-cf1acfcdf475
github.com/blevesearch/go-porterstemmer v1.0.3
github.com/blevesearch/goleveldb v1.0.1
github.com/blevesearch/gtreap v0.1.1
github.com/blevesearch/scorch_segment_api/v2 v2.2.2
github.com/blevesearch/scorch_segment_api/v2 v2.2.3
github.com/blevesearch/segment v0.9.1
github.com/blevesearch/snowball v0.6.1
github.com/blevesearch/snowballstem v0.9.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/RoaringBitmap/roaring v1.2.3 h1:yqreLINqIrX22ErkKI0vY47/ivtJr6n+kMhVO
github.com/RoaringBitmap/roaring v1.2.3/go.mod h1:plvDsJQpxOC5bw8LRteu/MLWHsHez/3y6cubLI4/1yE=
github.com/bits-and-blooms/bitset v1.2.0 h1:Kn4yilvwNtMACtf1eYDlG8H77R07mZSPbMjLyS07ChA=
github.com/bits-and-blooms/bitset v1.2.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA=
github.com/blevesearch/bleve_index_api v1.1.2 h1:A8MhXiNbZ9DI+lZytWkOY75MwesRdOlE+7/MzdC9YXY=
github.com/blevesearch/bleve_index_api v1.1.2/go.mod h1:PbcwjIcRmjhGbkS/lJCpfgVSMROV6TRubGGAODaK1W8=
github.com/blevesearch/bleve_index_api v1.1.3 h1:aNyMEiWFviY/1zYm7JCr2lZRIiYX0TMtz3oymxxbApc=
github.com/blevesearch/bleve_index_api v1.1.3/go.mod h1:PbcwjIcRmjhGbkS/lJCpfgVSMROV6TRubGGAODaK1W8=
github.com/blevesearch/geo v0.1.18 h1:Np8jycHTZ5scFe7VEPLrDoHnnb9C4j636ue/CGrhtDw=
github.com/blevesearch/geo v0.1.18/go.mod h1:uRMGWG0HJYfWfFJpK3zTdnnr1K+ksZTuWKhXeSokfnM=
github.com/blevesearch/go-faiss v1.0.3-0.20231110151003-0ea762e5c06d h1:qIVY0mozIvyrOJso6EnuWnXMDjOy9DqCC+TOEdthdNg=
Expand All @@ -19,8 +19,8 @@ github.com/blevesearch/gtreap v0.1.1/go.mod h1:QaQyDRAT51sotthUWAH4Sj08awFSSWzgY
github.com/blevesearch/mmap-go v1.0.2/go.mod h1:ol2qBqYaOUsGdm7aRMRrYGgPvnwLe6Y+7LMvAB5IbSA=
github.com/blevesearch/mmap-go v1.0.4 h1:OVhDhT5B/M1HNPpYPBKIEJaD0F3Si+CrEKULGCDPWmc=
github.com/blevesearch/mmap-go v1.0.4/go.mod h1:EWmEAOmdAS9z/pi/+Toxu99DnsbhG1TIxUoRmJw/pSs=
github.com/blevesearch/scorch_segment_api/v2 v2.2.2 h1:wRkJ2tAP0HsS4M2pK/qDkNV0PvUo33umcsjzLIgvVA4=
github.com/blevesearch/scorch_segment_api/v2 v2.2.2/go.mod h1:7mKEerrxzvfImS2pMvpfV5MGFYVcQ9NBTkBd/ApU7cI=
github.com/blevesearch/scorch_segment_api/v2 v2.2.3 h1:apMwrcLmPrlMZ2n+SzcTJ6v0EVWjVU6PXZ+IlC+MTiw=
github.com/blevesearch/scorch_segment_api/v2 v2.2.3/go.mod h1:ZDNK8ckaZNQ1nLz5ELvAd7BffgiNEwtkZMYF9B6rt8E=
github.com/blevesearch/segment v0.9.1 h1:+dThDy+Lvgj5JMxhmOVlgFfkUtZV2kw49xax4+jTfSU=
github.com/blevesearch/segment v0.9.1/go.mod h1:zN21iLm7+GnBHWTao9I+Au/7MBiL8pPFtJBJTsk6kQw=
github.com/blevesearch/snowball v0.6.1 h1:cDYjn/NCH+wwt2UdehaLpr2e4BwLIjN4V/TdLsL+B5A=
Expand Down
2 changes: 1 addition & 1 deletion mapping/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type FieldMapping struct {

// Similarity is the similarity algorithm used for scoring
// vector fields.
// See: util.DefaultSimilarityMetric & util.SupportedSimilarityMetrics
// See: index.DefaultSimilarityMetric & index.SupportedSimilarityMetrics
Similarity string `json:"similarity,omitempty"`
}

Expand Down
7 changes: 4 additions & 3 deletions mapping/mapping_vectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"reflect"

"github.com/blevesearch/bleve/v2/document"
index "github.com/blevesearch/bleve_index_api"
"github.com/blevesearch/bleve/v2/util"
)

Expand Down Expand Up @@ -87,7 +88,7 @@ func validateVectorField(field *FieldMapping) error {
}

if field.Similarity == "" {
field.Similarity = util.DefaultSimilarityMetric
field.Similarity = index.DefaultSimilarityMetric
}

// following fields are not applicable for vector
Expand All @@ -98,10 +99,10 @@ func validateVectorField(field *FieldMapping) error {
field.DocValues = false
field.SkipFreqNorm = true

if _, ok := util.SupportedSimilarityMetrics[field.Similarity]; !ok {
if _, ok := index.SupportedSimilarityMetrics[field.Similarity]; !ok {
return fmt.Errorf("invalid similarity metric: '%s', "+
"valid metrics are: %+v", field.Similarity,
reflect.ValueOf(util.SupportedSimilarityMetrics).MapKeys())
reflect.ValueOf(index.SupportedSimilarityMetrics).MapKeys())
}

return nil
Expand Down
3 changes: 1 addition & 2 deletions search/query/knn.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/blevesearch/bleve/v2/mapping"
"github.com/blevesearch/bleve/v2/search"
"github.com/blevesearch/bleve/v2/search/searcher"
"github.com/blevesearch/bleve/v2/util"
index "github.com/blevesearch/bleve_index_api"
)

Expand Down Expand Up @@ -65,7 +64,7 @@ func (q *KNNQuery) Searcher(ctx context.Context, i index.IndexReader,
fieldMapping := m.FieldMappingForPath(q.VectorField)
similarityMetric := fieldMapping.Similarity
if similarityMetric == "" {
similarityMetric = util.DefaultSimilarityMetric
similarityMetric = index.DefaultSimilarityMetric
}
if q.K <= 0 || len(q.Vector) == 0 {
return nil, fmt.Errorf("k must be greater than 0 and vector must be non-empty")
Expand Down
3 changes: 1 addition & 2 deletions search/scorer/scorer_knn.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"reflect"

"github.com/blevesearch/bleve/v2/search"
"github.com/blevesearch/bleve/v2/util"
index "github.com/blevesearch/bleve_index_api"
)

Expand Down Expand Up @@ -68,7 +67,7 @@ func (sqs *KNNQueryScorer) Score(ctx *search.SearchContext,
if sqs.includeScore || sqs.options.Explain {
var scoreExplanation *search.Explanation
score := knnMatch.Score
if sqs.similarityMetric == util.EuclideanDistance {
if sqs.similarityMetric == index.EuclideanDistance {
// eucliden distances need to be inverted to work
// tf-idf scoring
score = 1.0 / score
Expand Down
38 changes: 0 additions & 38 deletions util/knn.go

This file was deleted.

0 comments on commit e6299d4

Please sign in to comment.