From ee5519a6bbd63636647ea95162ee16415bc15c7a Mon Sep 17 00:00:00 2001 From: David Rubinstein Date: Mon, 23 Oct 2023 12:32:41 -0400 Subject: [PATCH] Add voyager to algorithms --- .github/workflows/benchmarks.yml | 1 + ann_benchmarks/algorithms/voyager/Dockerfile | 7 +++ ann_benchmarks/algorithms/voyager/config.yml | 45 ++++++++++++++++++++ ann_benchmarks/algorithms/voyager/module.py | 31 ++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 ann_benchmarks/algorithms/voyager/Dockerfile create mode 100644 ann_benchmarks/algorithms/voyager/config.yml create mode 100644 ann_benchmarks/algorithms/voyager/module.py diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index 364d704ac..2ac15ed1c 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -64,6 +64,7 @@ jobs: - vald - vearch - vespa + - voyager - weaviate include: - library: pynndescent diff --git a/ann_benchmarks/algorithms/voyager/Dockerfile b/ann_benchmarks/algorithms/voyager/Dockerfile new file mode 100644 index 000000000..f4361d741 --- /dev/null +++ b/ann_benchmarks/algorithms/voyager/Dockerfile @@ -0,0 +1,7 @@ +FROM ann-benchmarks + +RUN apt-get install -y python-setuptools python-pip +RUN pip3 install voyager + +RUN python3 -c 'import voyager' + diff --git a/ann_benchmarks/algorithms/voyager/config.yml b/ann_benchmarks/algorithms/voyager/config.yml new file mode 100644 index 000000000..f8c964108 --- /dev/null +++ b/ann_benchmarks/algorithms/voyager/config.yml @@ -0,0 +1,45 @@ +float: + any: + - base_args: ['@metric'] + constructor: Voyager + disabled: false + docker_tag: ann-benchmarks-voyager + module: ann_benchmarks.algorithms.voyager + name: voyager + run_groups: + M-12: + arg_groups: [{M: 12, efConstruction: 500}] + args: {} + query_args: [[10, 20, 40, 80, 120, 200, 400, 600, 800]] + M-16: + arg_groups: [{M: 16, efConstruction: 500}] + args: {} + query_args: [[10, 20, 40, 80, 120, 200, 400, 600, 800]] + M-24: + arg_groups: [{M: 24, efConstruction: 500}] + args: {} + query_args: [[10, 20, 40, 80, 120, 200, 400, 600, 800]] + M-36: + arg_groups: [{M: 36, efConstruction: 500}] + args: {} + query_args: [[10, 20, 40, 80, 120, 200, 400, 600, 800]] + M-4: + arg_groups: [{M: 4, efConstruction: 500}] + args: {} + query_args: [[10, 20, 40, 80, 120, 200, 400, 600, 800]] + M-48: + arg_groups: [{M: 48, efConstruction: 500}] + args: {} + query_args: [[10, 20, 40, 80, 120, 200, 400, 600, 800]] + M-64: + arg_groups: [{M: 64, efConstruction: 500}] + args: {} + query_args: [[10, 20, 40, 80, 120, 200, 400, 600, 800]] + M-8: + arg_groups: [{M: 8, efConstruction: 500}] + args: {} + query_args: [[10, 20, 40, 80, 120, 200, 400, 600, 800]] + M-96: + arg_groups: [{M: 96, efConstruction: 500}] + args: {} + query_args: [[10, 20, 40, 80, 120, 200, 400, 600, 800]] diff --git a/ann_benchmarks/algorithms/voyager/module.py b/ann_benchmarks/algorithms/voyager/module.py new file mode 100644 index 000000000..f7bd88d97 --- /dev/null +++ b/ann_benchmarks/algorithms/voyager/module.py @@ -0,0 +1,31 @@ +import numpy as np +import voyager + +from ..base.module import BaseANN + + +class Voyager(BaseANN): + def __init__(self, metric, method_param): + self.metric = {"angular": 2, "euclidean": 0}[metric] + self.method_param = method_param + self.name = "voyager (%s)" % (self.method_param) + + def fit(self, X): + self.p = voyager.Index( + space=voyager.Space(self.metric), + num_dimensions=len(X[0]), + max_elements=len(X), + ef_construction=self.method_param["efConstruction"], + M=self.method_param["M"], + ) + data_labels = np.arange(len(X)) + self.p.add_items(np.asarray(X), data_labels) + + def set_query_arguments(self, ef): + self.ef = ef + + def query(self, v, n): + return self.p.query(np.expand_dims(v, axis=0), k=n, query_ef=self.ef)[0][0] + + def freeIndex(self): + del self.p