Skip to content

Commit

Permalink
evaluate HNSW in parallel (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenghaoz authored Feb 1, 2022
1 parent c896921 commit 78d2a82
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions base/search/hnsw.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,18 +332,23 @@ func recall(expected, actual []int32) float32 {
return result / float32(len(actual))
}

func (b *HNSWBuilder) evaluate(idx VectorIndex, prune0 bool) float32 {
func (b *HNSWBuilder) evaluate(idx *HNSW, prune0 bool) float32 {
testSize := mathutil.Min(b.testSize, len(b.data))
samples := b.rng.Sample(0, len(b.data), testSize)
var result, count float32
for _, i := range samples {
expected, _ := b.bruteForce.Search(b.data[i], b.k, prune0)
var mu sync.Mutex
_ = base.Parallel(len(samples), idx.numJobs, func(_, i int) error {
sample := samples[i]
expected, _ := b.bruteForce.Search(b.data[sample], b.k, prune0)
if len(expected) > 0 {
actual, _ := idx.Search(b.data[i], b.k, prune0)
actual, _ := idx.Search(b.data[sample], b.k, prune0)
mu.Lock()
defer mu.Unlock()
result += recall(expected, actual)
count++
}
}
return nil
})
return result / count
}

Expand Down

0 comments on commit 78d2a82

Please sign in to comment.