Skip to main content

vicinity/
error.rs

1//! Error types for vicinity.
2
3use thiserror::Error;
4
5/// Errors that can occur during indexing/search operations.
6#[derive(Debug, Clone, PartialEq, Error)]
7pub enum RetrieveError {
8    /// Empty query provided.
9    #[error("query is empty")]
10    EmptyQuery,
11
12    /// Empty index (no documents indexed).
13    #[error("index is empty")]
14    EmptyIndex,
15
16    /// Invalid parameter value.
17    #[error("invalid parameter: {0}")]
18    InvalidParameter(String),
19
20    /// Dimension mismatch between query and documents.
21    #[error("dimension mismatch: query has {query_dim} dimensions, document has {doc_dim}")]
22    DimensionMismatch { query_dim: usize, doc_dim: usize },
23
24    /// Invalid sparse vector (empty or malformed).
25    #[error("invalid sparse vector: {0}")]
26    InvalidSparseVector(String),
27
28    /// I/O error (wrapped)
29    #[error("I/O error: {0}")]
30    Io(String), // RetrieveError needs to be Clone, std::io::Error isn't. Store string representation.
31
32    /// Out of bounds access
33    #[error("index out of bounds: {0}")]
34    OutOfBounds(usize),
35
36    /// Format error
37    #[error("format error: {0}")]
38    FormatError(String),
39
40    /// Serialization error
41    #[error("serialization error: {0}")]
42    Serialization(String),
43
44    /// Other error (for extensibility).
45    #[error("{0}")]
46    Other(String),
47}
48
49impl From<std::io::Error> for RetrieveError {
50    fn from(err: std::io::Error) -> Self {
51        RetrieveError::Io(err.to_string())
52    }
53}
54
55#[cfg(feature = "qntz")]
56impl From<qntz::VQuantError> for RetrieveError {
57    fn from(err: qntz::VQuantError) -> Self {
58        RetrieveError::Other(err.to_string())
59    }
60}
61
62/// Result type alias for vicinity operations.
63pub type Result<T> = std::result::Result<T, RetrieveError>;