Skip to content

Commit

Permalink
updated quantiser
Browse files Browse the repository at this point in the history
  • Loading branch information
metonymic-smokey committed May 21, 2024
1 parent a9fced1 commit d2229d8
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions section_faiss_vector_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,17 +348,17 @@ func (v *vectorIndexOpaque) mergeAndWriteVectorIndexes(sbs []*SegmentBase,

nvecs := len(finalVecIDs)

// index type to be created after merge based on the number of vectors
// in indexData added into the index.
nlist := determineCentroids(nvecs)
indexDescription, indexClass := determineIndexToUse(nvecs, nlist)

// safe to assume that all the indexes are of the same config values, given
// that they are extracted from the field mapping info.
dims := vecIndexes[0].D()
metric := vecIndexes[0].MetricType()
indexOptimizedFor := indexes[0].indexOptimizedFor

// index type to be created after merge based on the number of vectors
// in indexData added into the index.
nlist := determineCentroids(nvecs)
indexDescription, indexClass := determineIndexToUse(nvecs, nlist, indexOptimizedFor)

// freeing the reconstructed indexes immediately - waiting till the end
// to do the same is not needed because the following operations don't need
// the reconstructed ones anymore and doing so will hold up memory which can
Expand Down Expand Up @@ -456,9 +456,12 @@ const (

// Returns a description string for the index and quantizer type
// and an index type.
func determineIndexToUse(nvecs, nlist int) (string, int) {
func determineIndexToUse(nvecs, nlist int, indexOptimizedFor string) (string, int) {
switch {
case nvecs >= 10000:
if indexOptimizedFor == index.IndexOptimizedForMemory {
return fmt.Sprintf("IVF%d,SQ4", nlist), IndexTypeIVF
}
return fmt.Sprintf("IVF%d,SQ8", nlist), IndexTypeIVF
case nvecs >= 1000:
return fmt.Sprintf("IVF%d,Flat", nlist), IndexTypeIVF
Expand Down Expand Up @@ -489,7 +492,8 @@ func (vo *vectorIndexOpaque) writeVectorIndexes(w *CountHashWriter) (offset uint

nvecs := len(ids)
nlist := determineCentroids(nvecs)
indexDescription, indexClass := determineIndexToUse(nvecs, nlist)
indexDescription, indexClass := determineIndexToUse(nvecs, nlist,
content.indexOptimizedFor)
faissIndex, err := faiss.IndexFactory(int(content.dim), indexDescription, metric)
if err != nil {
return 0, err
Expand Down

0 comments on commit d2229d8

Please sign in to comment.