Skip to content

Commit

Permalink
Change cagra.build_index to cagra.build (rapidsai#187)
Browse files Browse the repository at this point in the history
This changes the build_index method to build in the python API for cagra. All of the other python api's use a `build` method for building the index, as do both the C++ and Rust api's as well.

Authors:
  - Ben Frederickson (https://github.com/benfred)

Approvers:
  - Corey J. Nolet (https://github.com/cjnolet)

URL: rapidsai/cuvs#187
  • Loading branch information
benfred authored Jun 14, 2024
1 parent 771cc91 commit 615749e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ from cuvs.neighbors import cagra
dataset = load_data()
index_params = cagra.IndexParams()

index = cagra.build_index(build_params, dataset)
index = cagra.build(build_params, dataset)
```

### C++ API
Expand Down
2 changes: 1 addition & 1 deletion docs/source/python_api/neighbors_cagra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Index
Index build
###########

.. autofunction:: cuvs.neighbors.cagra.build_index
.. autofunction:: cuvs.neighbors.cagra.build

Index search
############
Expand Down
2 changes: 1 addition & 1 deletion docs/source/working_with_ann_indexes_python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Building an index
dataset = load_data()
index_params = cagra.IndexParams()
index = cagra.build_index(build_params, dataset)
index = cagra.build(build_params, dataset)
Searching an index
Expand Down
4 changes: 2 additions & 2 deletions python/cuvs/cuvs/neighbors/cagra/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Index,
IndexParams,
SearchParams,
build_index,
build,
load,
save,
search,
Expand All @@ -29,7 +29,7 @@
"Index",
"IndexParams",
"SearchParams",
"build_index",
"build",
"load",
"save",
"search",
Expand Down
16 changes: 12 additions & 4 deletions python/cuvs/cuvs/neighbors/cagra/cagra.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#
# cython: language_level=3

import warnings

import numpy as np

cimport cuvs.common.cydlpack
Expand Down Expand Up @@ -231,7 +233,7 @@ cdef class Index:


@auto_sync_resources
def build_index(IndexParams index_params, dataset, resources=None):
def build(IndexParams index_params, dataset, resources=None):
"""
Build the CAGRA index from the dataset for efficient search.
Expand Down Expand Up @@ -268,7 +270,7 @@ def build_index(IndexParams index_params, dataset, resources=None):
>>> dataset = cp.random.random_sample((n_samples, n_features),
... dtype=cp.float32)
>>> build_params = cagra.IndexParams(metric="sqeuclidean")
>>> index = cagra.build_index(build_params, dataset)
>>> index = cagra.build(build_params, dataset)
>>> distances, neighbors = cagra.search(cagra.SearchParams(),
... index, dataset,
... k)
Expand Down Expand Up @@ -301,6 +303,12 @@ def build_index(IndexParams index_params, dataset, resources=None):
return idx


def build_index(IndexParams index_params, dataset, resources=None):
warnings.warn("cagra.build_index is deprecated, use cagra.build instead",
FutureWarning)
return build(index_params, dataset, resources=resources)


cdef class SearchParams:
"""
CAGRA search parameters
Expand Down Expand Up @@ -501,7 +509,7 @@ def search(SearchParams search_params,
>>> dataset = cp.random.random_sample((n_samples, n_features),
... dtype=cp.float32)
>>> # Build index
>>> index = cagra.build_index(cagra.IndexParams(), dataset)
>>> index = cagra.build(cagra.IndexParams(), dataset)
>>> # Search using the built index
>>> queries = cp.random.random_sample((n_queries, n_features),
... dtype=cp.float32)
Expand Down Expand Up @@ -596,7 +604,7 @@ def save(filename, Index index, bool include_dataset=True, resources=None):
>>> dataset = cp.random.random_sample((n_samples, n_features),
... dtype=cp.float32)
>>> # Build index
>>> index = cagra.build_index(cagra.IndexParams(), dataset)
>>> index = cagra.build(cagra.IndexParams(), dataset)
>>> # Serialize and deserialize the cagra index built
>>> cagra.save("my_index.bin", index)
>>> index_loaded = cagra.load("my_index.bin")
Expand Down
6 changes: 3 additions & 3 deletions python/cuvs/cuvs/test/test_cagra.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def run_cagra_build_search_test(
)

if array_type == "device":
index = cagra.build_index(build_params, dataset_device)
index = cagra.build(build_params, dataset_device)
else:
index = cagra.build_index(build_params, dataset)
index = cagra.build(build_params, dataset)

if not add_data_on_build:
dataset_1 = dataset[: n_rows // 2, :]
Expand Down Expand Up @@ -198,7 +198,7 @@ def test_save_load(dtype, include_dataset):
dataset_device = device_ndarray(dataset)

build_params = cagra.IndexParams()
index = cagra.build_index(build_params, dataset_device)
index = cagra.build(build_params, dataset_device)

assert index.trained
filename = "my_index.bin"
Expand Down

0 comments on commit 615749e

Please sign in to comment.