Cagra Index Module

View as Markdown

Rust module: cuvs::cagra::index

Source: rust/cuvs/src/cagra/index.rs

Index

1#[derive(Debug)]
2pub struct Index(ffi::cuvsCagraIndex_t);

CAGRA ANN Index

Methods

NameSource
buildrust/cuvs/src/cagra/index.rs:38
newrust/cuvs/src/cagra/index.rs:52
searchrust/cuvs/src/cagra/index.rs:69
search_with_filterrust/cuvs/src/cagra/index.rs:107
serializerust/cuvs/src/cagra/index.rs:143
serialize_to_hnswlibrust/cuvs/src/cagra/index.rs:166
deserializerust/cuvs/src/cagra/index.rs:179

build

1pub fn build<T: Into<ManagedTensor>>(
2res: &Resources,
3params: &IndexParams,
4dataset: T,
5) -> Result<Index> { ... }

Builds a new Index from the dataset for efficient search.

Arguments

  • res - Resources to use
  • params - Parameters for building the index
  • dataset - A row-major matrix on either the host or device to index

Source: rust/cuvs/src/cagra/index.rs:38

new

1pub fn new() -> Result<Index> { ... }

Creates a new empty index

Source: rust/cuvs/src/cagra/index.rs:52

1pub fn search(
2&self,
3res: &Resources,
4params: &SearchParams,
5queries: &ManagedTensor,
6neighbors: &ManagedTensor,
7distances: &ManagedTensor,
8) -> Result<()> { ... }

Perform a Approximate Nearest Neighbors search on the Index

Arguments

  • res - Resources to use
  • params - Parameters to use in searching the index
  • queries - A matrix in device memory to query for
  • neighbors - Matrix in device memory that receives the indices of the nearest neighbors
  • distances - Matrix in device memory that receives the distances of the nearest neighbors

Source: rust/cuvs/src/cagra/index.rs:69

search_with_filter

1pub fn search_with_filter(
2&self,
3res: &Resources,
4params: &SearchParams,
5queries: &ManagedTensor,
6neighbors: &ManagedTensor,
7distances: &ManagedTensor,
8bitset: &ManagedTensor,
9) -> Result<()> { ... }

Perform a filtered Approximate Nearest Neighbors search on the Index

Like search, but accepts a bitset filter to exclude vectors during graph traversal. Filtered vectors are never visited, giving better recall than post-filtering.

Arguments

  • res - Resources to use
  • params - Parameters to use in searching the index
  • queries - A matrix in device memory to query for
  • neighbors - Matrix in device memory that receives the indices of the nearest neighbors
  • distances - Matrix in device memory that receives the distances of the nearest neighbors
  • bitset - A 1-D uint32 device tensor with ceil(n_rows / 32) elements. Each bit corresponds to a dataset row: bit 1 = include, bit 0 = exclude.

Source: rust/cuvs/src/cagra/index.rs:107

serialize

1pub fn serialize<P: AsRef<Path>>(
2&self,
3res: &Resources,
4filename: P,
5include_dataset: bool,
6) -> Result<()> { ... }

Save the CAGRA index to file.

Experimental, both the API and the serialization format are subject to change.

Arguments

  • res - Resources to use
  • filename - The file path for saving the index
  • include_dataset - Whether to write out the dataset to the file

Source: rust/cuvs/src/cagra/index.rs:143

serialize_to_hnswlib

1pub fn serialize_to_hnswlib<P: AsRef<Path>>(&self, res: &Resources, filename: P) -> Result<()> { ... }

Save the CAGRA index to file in hnswlib format.

NOTE: The saved index can only be read by the hnswlib wrapper in cuVS, as the serialization format is not compatible with the original hnswlib.

Experimental, both the API and the serialization format are subject to change.

Arguments

  • res - Resources to use
  • filename - The file path for saving the index

Source: rust/cuvs/src/cagra/index.rs:166

deserialize

1pub fn deserialize<P: AsRef<Path>>(res: &Resources, filename: P) -> Result<Index> { ... }

Load a CAGRA index from file.

Experimental, both the API and the serialization format are subject to change.

Arguments

  • res - Resources to use
  • filename - The path of the file that stores the index

Source: rust/cuvs/src/cagra/index.rs:179

Source: rust/cuvs/src/cagra/index.rs:17