diff --git a/faiss_vector_cache.go b/faiss_vector_cache.go index ba1e465..244872a 100644 --- a/faiss_vector_cache.go +++ b/faiss_vector_cache.go @@ -27,22 +27,6 @@ import ( faiss "github.com/blevesearch/go-faiss" ) -type vectorIndexCache struct { - closeCh chan struct{} - m sync.RWMutex - cache map[uint16]*cacheEntry -} - -type ewma struct { - alpha float64 - avg float64 - // every hit to the cache entry is recorded as part of a sample - // which will be used to calculate the average in the next cycle of average - // computation (which is average traffic for the field till now). this is - // used to track the per second hits to the cache entries. - sample uint64 -} - func newVectorIndexCache() *vectorIndexCache { return &vectorIndexCache{ cache: make(map[uint16]*cacheEntry), @@ -50,6 +34,12 @@ func newVectorIndexCache() *vectorIndexCache { } } +type vectorIndexCache struct { + closeCh chan struct{} + m sync.RWMutex + cache map[uint16]*cacheEntry +} + func (vc *vectorIndexCache) Clear() { vc.m.Lock() close(vc.closeCh) @@ -231,6 +221,18 @@ func (vc *vectorIndexCache) monitor() { } } +// ----------------------------------------------------------------------------- + +type ewma struct { + alpha float64 + avg float64 + // every hit to the cache entry is recorded as part of a sample + // which will be used to calculate the average in the next cycle of average + // computation (which is average traffic for the field till now). this is + // used to track the per second hits to the cache entries. + sample uint64 +} + func (e *ewma) add(val uint64) { if e.avg == 0.0 { e.avg = float64(val) @@ -241,6 +243,8 @@ func (e *ewma) add(val uint64) { } } +// ----------------------------------------------------------------------------- + func createCacheEntry(index *faiss.IndexImpl, vecDocIDMap map[int64]uint32, alpha float64) *cacheEntry { return &cacheEntry{ index: index,