How to Use cuVS: Vector Search and Clustering on the GPU

Sep 10, 2023 | Data Science

cuVS is an exciting new library that brings together the power of approximate nearest neighbors and clustering algorithms to leverage GPU performance effectively. This article aims to guide you on using cuVS, from installation to getting started with simple examples, while also addressing some common troubleshooting issues.

What is cuVS?

cuVS is a library designed to facilitate vector similarity search and clustering on GPUs. It derives its functionality from the algorithms available in RAPIDS RAFT and aims to make GPU use simpler for developers across various languages, including C++, Python, C, and Rust.

Installing cuVS

To install cuVS, we recommend using mamba due to its performance and ease of use. Follow these steps:

  • Make sure you have conda installed, as it is necessary for package management.
  • Open your terminal and execute the command below to install the desired package (you can adjust for languages):
  • mamba install -c conda-forge -c nvidia -c rapidsai cuvs
  • For nightly builds, replace ‘rapidsai’ with ‘rapidsai-nightly’:
  • mamba install -c conda-forge -c nvidia -c rapidsai-nightly cuvs=24.10

Getting Started

Now that cuVS is installed, let’s dive into using it! We will train an approximate nearest neighbors index using the CAGRA algorithm.

Python API Example

from cuvs.neighbors import cagra

dataset = load_data()
index_params = cagra.IndexParams()
index = cagra.build(build_params, dataset)

C++ API Example

#include 
using namespace cuvs::neighbors;

raft::device_matrix_view dataset = load_dataset();
raft::device_resources res;
cagra::index_params index_params;
auto index = cagra::build(res, index_params, dataset);

Understanding the Code: An Analogy

Imagine you are a librarian at a huge library. When a patron asks for a specific book, you employ a sophisticated indexing system to quickly find the location of that book. Similarly, in programming, when you implement the CAGRA algorithm, you are creating a kind of indexing system for your dataset—the program learns where similar data points are located, much like the librarian knows the position of each book. The code snippets provided above illustrate how to set up your index using different programming languages in a straightforward manner!

Troubleshooting Tips

If you run into issues while using cuVS, consider the following troubleshooting ideas:

  • Ensure you have the latest version of your packages installed and that your environment is correctly set up.
  • If you encounter errors related to Python/C++ versions, check compatibility between your package versions and the programming language you are using.
  • Check the official issue tracker for cuVS for known issues and solutions.
  • If all else fails, reach out to the RAPIDS Community for assistance.

For more insights, updates, or to collaborate on AI development projects, stay connected with [fxis.ai](https://fxis.ai).

Contributing

If you want to contribute to the cuVS library or learn more about development guidelines, check out the Contributing guidelines and the Developer Guide.

Conclusion

cuVS opens up new possibilities for GPU-based applications in vector similarity search and clustering. With its simple installation, extensive functionality, and the ability to leverage multiple programming languages, it’s an essential library for developers looking to enhance their applications.

At [fxis.ai](https://fxis.ai), we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox