From f9df387118b4ae7614c21c5e7371aa0efe43035b Mon Sep 17 00:00:00 2001 From: zhenghaoz Date: Mon, 14 Feb 2022 21:01:32 +0800 Subject: [PATCH] return zero recall on empty ground truth (#381) --- base/search/hnsw.go | 3 +++ base/search/ivf.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/base/search/hnsw.go b/base/search/hnsw.go index 2a3580c39..b1e2665c0 100644 --- a/base/search/hnsw.go +++ b/base/search/hnsw.go @@ -349,6 +349,9 @@ func (b *HNSWBuilder) evaluate(idx *HNSW, prune0 bool) float32 { } return nil }) + if count == 0 { + return 0 + } return result / count } diff --git a/base/search/ivf.go b/base/search/ivf.go index b3e61fc0e..3bdcc08cc 100644 --- a/base/search/ivf.go +++ b/base/search/ivf.go @@ -302,6 +302,9 @@ func (b *IVFBuilder) evaluate(idx *IVF, prune0 bool) float32 { } return nil }) + if count == 0 { + return 0 + } return result / count }