vector_index/error.rs
1//! Error types for the vector index.
2
3use thiserror::Error;
4
5/// Result alias for operations on a [`HnswIndex`](crate::HnswIndex).
6pub type IndexResult<T> = core::result::Result<T, IndexError>;
7
8/// Errors returned by index operations.
9#[derive(Debug, Error)]
10pub enum IndexError {
11 /// Attempted to insert a point with an ID that already exists.
12 #[error("duplicate point id: {0}")]
13 DuplicateId(crate::PointId),
14
15 /// Attempted to access a point ID that is not in the index.
16 #[error("unknown point id: {0}")]
17 UnknownId(crate::PointId),
18
19 /// The index is empty and the requested operation is not defined.
20 #[error("operation requires a non-empty index")]
21 Empty,
22
23 /// Configuration parameter out of valid range.
24 #[error("invalid config: {0}")]
25 InvalidConfig(&'static str),
26
27 /// A point's dimension does not match the index's dimension.
28 ///
29 /// Only raised by metrics that enforce a fixed dimension at runtime.
30 #[error("dimension mismatch: expected {expected}, got {actual}")]
31 DimensionMismatch {
32 /// Dimension declared at index construction.
33 expected: usize,
34 /// Dimension of the offending point.
35 actual: usize,
36 },
37}