Skip to content

Commit

Permalink
correct ordering of vector IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
metonymic-smokey committed Jan 4, 2024
1 parent f52bb04 commit 272d1d9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions section_faiss_vector_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
index "github.com/blevesearch/bleve_index_api"
faiss "github.com/blevesearch/go-faiss"
seg "github.com/blevesearch/scorch_segment_api/v2"
"golang.org/x/exp/maps"
)

func init() {
Expand Down Expand Up @@ -300,6 +299,8 @@ func (v *vectorIndexOpaque) mergeAndWriteVectorIndexes(fieldID int, sbs []*Segme
// index type to be created after merge.
indexType, isIVF := getIndexType(len(vecToDocID))

var finalVecIDs []int64

// merging of indexes with reconstruction
// method. the indexes[i].vecIds is such that it has only the valid vecs
// of this vector index present in it, so we'd be reconstructed only the
Expand All @@ -320,6 +321,8 @@ func (v *vectorIndexOpaque) mergeAndWriteVectorIndexes(fieldID int, sbs []*Segme
return err
}
indexData = append(indexData, recons...)
// Adding vector IDs in the same order as the vectors
finalVecIDs = append(finalVecIDs, indexes[i].vecIds...)
}
}

Expand All @@ -333,7 +336,6 @@ func (v *vectorIndexOpaque) mergeAndWriteVectorIndexes(fieldID int, sbs []*Segme
// that they are extracted from the field mapping info.
dims := vecIndexes[0].D()
metric := vecIndexes[0].MetricType()
finalVecIDs := maps.Keys(vecToDocID)

index, err := faiss.IndexFactory(dims, indexType, metric)
if err != nil {
Expand Down

0 comments on commit 272d1d9

Please sign in to comment.