RAFT (libraft-cu12)

26.4.0 · active · verified Thu Apr 16

libraft-cu12 is a core C++ library providing Reusable Algorithms Functions and other Tools (RAFT) for high-performance computing on NVIDIA GPUs. It serves as a foundational component for other RAPIDS libraries, including Python wrappers like `pylibraft`. The current version is 26.4.0, and it follows a monthly release cadence, aligned with the broader RAPIDS ecosystem.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates usage of `pylibraft`, which is the Python interface to RAFT algorithms. `libraft-cu12` provides the underlying C++ and CUDA implementations that `pylibraft` utilizes. This example builds and queries an approximate nearest neighbor (IVF-PQ) index on GPU data using CuPy arrays.

# libraft-cu12 provides the C++ core for RAFT.
# Python users typically interact with RAFT functionality via the `pylibraft` package.
# Ensure pylibraft-cu12 is installed (it depends on libraft-cu12):
# pip install pylibraft-cu12 --extra-index-url https://pypi.nvidia.com

import cupy as cp
from pylibraft.neighbors import ivf_pq

# Example using pylibraft, which relies on libraft-cu12
n_samples = 5000
n_features = 50

# Generate some random data on GPU using CuPy
dataset = cp.random.random_sample((n_samples, n_features), dtype=cp.float32)
queries = cp.random.random_sample((100, n_features), dtype=cp.float32)

# Build an IVF-PQ index
index_params = ivf_pq.IndexParams(
    n_lists=1024,
    metric="sqeuclidean",
    pq_dim=10
)
index = ivf_pq.build(index_params, dataset)

# Search the index
k = 5
search_params = ivf_pq.SearchParams(n_probes=20)
distances, neighbors = ivf_pq.search(search_params, index, queries, k)

print(f"Distances shape: {distances.shape}")
print(f"Neighbors shape: {neighbors.shape}")

view raw JSON →