Skip to content

Commit

Permalink
MB-63334: Fix race condition in NormalizeVector
Browse files Browse the repository at this point in the history
  • Loading branch information
CascadingRadium committed Nov 4, 2024
1 parent bed244c commit 1e4f31b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions mapping/mapping_vectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (
"fmt"
"reflect"

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

// Min and Max allowed dimensions for a vector field;
Expand Down Expand Up @@ -263,5 +263,10 @@ func validateVectorFieldAlias(field *FieldMapping, parentName string,
}

func NormalizeVector(vec []float32) []float32 {
return faiss.NormalizeVector(vec)
// make a copy of the vector to avoid modifying the original
// vector in-place
vecCopy := make([]float32, len(vec))
copy(vecCopy, vec)
// normalize the vector copy using in-place normalization provided by faiss
return faiss.NormalizeVector(vecCopy)
}

0 comments on commit 1e4f31b

Please sign in to comment.