1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use super::{
common::{VectorDistanceMetric, VectorRelationBinding},
definition::CuvsOperation,
};
/// CAGRA graph construction algorithm.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum VectorCagraBuildAlgo {
/// Constructs the graph using an IVF-PQ index.
IvfPq,
/// Constructs the graph using NN-descent; does not support cosine.
NnDescent,
}
/// CAGRA search kernel selection.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum VectorCagraSearchAlgo {
/// Allows cuVS to select the search kernel.
Auto,
/// Uses one cooperative thread array per query.
SingleCta,
/// Uses multiple cooperative thread arrays per query.
MultiCta,
/// Uses the multi-kernel search implementation.
MultiKernel,
}
/// Query-local CAGRA graph and search parameters.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct VectorCagraParams {
/// Dense rows indexed by the graph.
pub dataset: VectorRelationBinding,
/// Dense query rows matched against the dataset.
pub queries: VectorRelationBinding,
/// Number of neighbors returned per query row.
pub k: usize,
/// Distance or similarity used to rank neighbors.
pub metric: VectorDistanceMetric,
/// Output graph edges per vertex; must be below dataset row count.
pub graph_degree: u32,
/// Build graph edges per vertex; must exceed `graph_degree` and be below dataset rows.
pub intermediate_graph_degree: u32,
/// Algorithm used to construct the query-local graph.
pub build_algo: VectorCagraBuildAlgo,
/// Intermediate result capacity; must be at least `k`.
pub itopk_size: u32,
/// Starting graph nodes explored per search iteration.
pub search_width: u32,
/// Maximum search iteration count; zero selects it automatically.
pub max_iterations: u32,
/// Native search kernel selection.
pub search_algo: VectorCagraSearchAlgo,
}
impl VectorCagraParams {
/// Uses registry defaults for graph construction and search tuning.
///
/// The supplied bindings, neighbor count, and metric are retained without validation.
pub fn new(
dataset: VectorRelationBinding,
queries: VectorRelationBinding,
k: usize,
metric: VectorDistanceMetric,
) -> Self {
let descriptor = CuvsOperation::Cagra.descriptor();
let integer = |name| {
descriptor.option(name).and_then(|option| option.kind.default_u64()).expect("CAGRA integer default") as u32
};
Self {
dataset,
queries,
k,
metric,
graph_degree: integer("graph_degree"),
intermediate_graph_degree: integer("intermediate_graph_degree"),
build_algo: VectorCagraBuildAlgo::IvfPq,
itopk_size: integer("itopk_size"),
search_width: integer("search_width"),
max_iterations: integer("max_iterations"),
search_algo: VectorCagraSearchAlgo::Auto,
}
}
}