From 403254726b5867a266ad36ddb7e6bc126ad7bdd7 Mon Sep 17 00:00:00 2001 From: kevindiu Date: Tue, 11 Jul 2023 23:18:31 +0000 Subject: [PATCH 1/2] fix hack/benchmark search interface Signed-off-by: kevindiu --- hack/benchmark/core/benchmark/strategy/search.go | 2 +- hack/benchmark/internal/core/algorithm/algorithm.go | 4 +++- hack/benchmark/internal/core/algorithm/ngt/ngt.go | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/hack/benchmark/core/benchmark/strategy/search.go b/hack/benchmark/core/benchmark/strategy/search.go index 13236ccccf..1b480190a1 100644 --- a/hack/benchmark/core/benchmark/strategy/search.go +++ b/hack/benchmark/core/benchmark/strategy/search.go @@ -43,7 +43,7 @@ func NewSearch(size int, epsilon, radius float32, opts ...StrategyOption) benchm } b.StartTimer() defer b.StopTimer() - return c.Search(v.([]float32), size, epsilon, radius) + return c.Search(ctx, v.([]float32), size, epsilon, radius) }, ), WithPreProp64( diff --git a/hack/benchmark/internal/core/algorithm/algorithm.go b/hack/benchmark/internal/core/algorithm/algorithm.go index 77382f27e6..2ab650be69 100644 --- a/hack/benchmark/internal/core/algorithm/algorithm.go +++ b/hack/benchmark/internal/core/algorithm/algorithm.go @@ -17,6 +17,8 @@ // Package algorithm provides core interface package algorithm +import "context" + type Mode uint32 const ( @@ -29,7 +31,7 @@ type Closer interface { } type Bit32 interface { - Search(vec []float32, size int, epsilon, radius float32) (interface{}, error) + Search(ctx context.Context, vec []float32, size int, epsilon, radius float32) (interface{}, error) Insert(vec []float32) (uint, error) InsertCommit(vec []float32, poolSize uint32) (uint, error) BulkInsert(vecs [][]float32) ([]uint, []error) diff --git a/hack/benchmark/internal/core/algorithm/ngt/ngt.go b/hack/benchmark/internal/core/algorithm/ngt/ngt.go index 5d8fa245d6..cc352a60a8 100644 --- a/hack/benchmark/internal/core/algorithm/ngt/ngt.go +++ b/hack/benchmark/internal/core/algorithm/ngt/ngt.go @@ -18,6 +18,7 @@ package ngt import ( + "context" "os" c "github.com/vdaas/vald/hack/benchmark/internal/core/algorithm" @@ -74,8 +75,8 @@ func New(opts ...Option) (c.Bit32, error) { return c, nil } -func (c *core) Search(vec []float32, size int, epsilon, radius float32) (interface{}, error) { - return c.NGT.Search(vec, size, epsilon, radius) +func (c *core) Search(ctx context.Context, vec []float32, size int, epsilon, radius float32) (interface{}, error) { + return c.NGT.Search(ctx, vec, size, epsilon, radius) } func (c *core) Close() { From 82bd7493d2aa2bf16aa37058941680246f68dd04 Mon Sep 17 00:00:00 2001 From: kevindiu Date: Tue, 11 Jul 2023 23:25:51 +0000 Subject: [PATCH 2/2] change bit64 interface Signed-off-by: kevindiu --- hack/benchmark/core/benchmark/strategy/search.go | 2 +- hack/benchmark/internal/core/algorithm/algorithm.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hack/benchmark/core/benchmark/strategy/search.go b/hack/benchmark/core/benchmark/strategy/search.go index 1b480190a1..7f6aafe362 100644 --- a/hack/benchmark/core/benchmark/strategy/search.go +++ b/hack/benchmark/core/benchmark/strategy/search.go @@ -59,7 +59,7 @@ func NewSearch(size int, epsilon, radius float32, opts ...StrategyOption) benchm } b.StartTimer() defer b.StopTimer() - return c.Search(float32To64(v.([]float32)), size, epsilon, radius) + return c.Search(ctx, float32To64(v.([]float32)), size, epsilon, radius) }, ), }, opts...)...) diff --git a/hack/benchmark/internal/core/algorithm/algorithm.go b/hack/benchmark/internal/core/algorithm/algorithm.go index 2ab650be69..1a576e518a 100644 --- a/hack/benchmark/internal/core/algorithm/algorithm.go +++ b/hack/benchmark/internal/core/algorithm/algorithm.go @@ -46,7 +46,7 @@ type Bit32 interface { } type Bit64 interface { - Search(vec []float64, size int, epsilon, radius float32) (interface{}, error) + Search(ctx context.Context, vec []float64, size int, epsilon, radius float32) (interface{}, error) Insert(vec []float64) (uint, error) InsertCommit(vec []float64, poolSize uint32) (uint, error) BulkInsert(vecs [][]float64) ([]uint, []error)