1use thiserror::Error;
4
5use crate::config::DistanceMetric;
6
7#[derive(Debug, Error)]
8pub enum KnnError {
9 #[error("Dataset too small: need at least 2 points, got {n}")]
10 DatasetTooSmall { n: usize },
11
12 #[error("Dimension mismatch: data slice length {len} is not divisible by d={d}")]
13 DimensionMismatch { len: usize, d: usize },
14
15 #[error("KNN method not implemented: {method}")]
16 MethodNotImplemented { method: String },
17
18 #[error("KNN index error: {0}")]
19 Index(String),
20
21 #[error("GPU adapter unavailable: {0}")]
22 GpuUnavailable(String),
23
24 #[error(
25 "KNN graph size mismatch: graph has n={graph_n} (neighbors len {neighbors_len}), \
26 data has n={data_n}"
27 )]
28 GraphSizeMismatch {
29 graph_n: usize,
30 neighbors_len: usize,
31 data_n: usize,
32 },
33
34 #[error(
35 "KNN graph k={graph_k} is too small; need at least {required_k} \
36 (typically n_neighbors + 50, capped by n − 1)"
37 )]
38 GraphInsufficientK { graph_k: usize, required_k: usize },
39
40 #[error("KNN graph metric {graph:?} does not match requested metric {requested:?}")]
41 GraphMetricMismatch {
42 graph: DistanceMetric,
43 requested: DistanceMetric,
44 },
45
46 #[error("KNN graph I/O error: {0}")]
47 Io(String),
48}