Skip to content

Commit

Permalink
Merge branch 'delayedClosing' into vecToDocMap
Browse files Browse the repository at this point in the history
  • Loading branch information
Likith101 committed Apr 12, 2024
2 parents 38895df + bc33fa1 commit 8d76951
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions faiss_vector_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,28 @@ func (vc *vecIndexCache) monitor() {
}
}

func (vc *vecIndexCache) update(fieldIDPlus1 uint16,
index *faiss.IndexImpl, vecDocIDMap map[int64]uint32) {
vc.m.Lock()

// the first time we've hit the cache, try to spawn a monitoring routine
// which will reconcile the moving averages for all the fields being hit
if len(vc.cache) == 0 {
go vc.monitor()
}

_, ok := vc.cache[fieldIDPlus1]
if !ok {
// initializing the alpha with 0.4 essentially means that we are favoring
// the history a little bit more relative to the current sample value.
// this makes the average to be kept above the threshold value for a
// longer time and thereby the index to be resident in the cache
// for longer time.
vc.cache[fieldIDPlus1] = initCacheEntry(index, vecDocIDMap, 0.4)
}
vc.m.Unlock()
}

func (e *ewma) add(val uint64) {
if e.avg == 0.0 {
e.avg = float64(val)
Expand Down

0 comments on commit 8d76951

Please sign in to comment.