Skip to main content

ruvector_core/
error.rs

1//! Error types for Ruvector
2
3use thiserror::Error;
4
5/// Result type alias for Ruvector operations
6pub type Result<T> = std::result::Result<T, RuvectorError>;
7
8/// Main error type for Ruvector
9#[derive(Error, Debug)]
10pub enum RuvectorError {
11    /// Vector dimension mismatch
12    #[error("Dimension mismatch: expected {expected}, got {actual}")]
13    DimensionMismatch {
14        /// Expected dimension
15        expected: usize,
16        /// Actual dimension
17        actual: usize,
18    },
19
20    /// Vector not found
21    #[error("Vector not found: {0}")]
22    VectorNotFound(String),
23
24    /// Invalid parameter
25    #[error("Invalid parameter: {0}")]
26    InvalidParameter(String),
27
28    /// Invalid input
29    #[error("Invalid input: {0}")]
30    InvalidInput(String),
31
32    /// Invalid dimension
33    #[error("Invalid dimension: {0}")]
34    InvalidDimension(String),
35
36    /// Storage error
37    #[error("Storage error: {0}")]
38    StorageError(String),
39
40    /// Model loading error
41    #[error("Model loading error: {0}")]
42    ModelLoadError(String),
43
44    /// Model inference error
45    #[error("Model inference error: {0}")]
46    ModelInferenceError(String),
47
48    /// The loaded embedding provider cannot serve the requested retrieval role.
49    #[error("Embedding role unsupported: {0}")]
50    EmbeddingRoleUnsupported(String),
51
52    /// The active provider and persisted corpus use different embedding spaces.
53    #[error("Embedding space mismatch: stored {stored}, active {active}")]
54    EmbeddingSpaceMismatch {
55        /// Deterministic identity persisted by the store.
56        stored: String,
57        /// Deterministic identity of the active provider.
58        active: String,
59    },
60
61    /// Index error
62    #[error("Index error: {0}")]
63    IndexError(String),
64
65    /// Serialization error
66    #[error("Serialization error: {0}")]
67    SerializationError(String),
68
69    /// IO error
70    #[error("IO error: {0}")]
71    IoError(#[from] std::io::Error),
72
73    /// Database error
74    #[error("Database error: {0}")]
75    DatabaseError(String),
76
77    /// Invalid path error
78    #[error("Invalid path: {0}")]
79    InvalidPath(String),
80
81    /// Other errors
82    #[error("Internal error: {0}")]
83    Internal(String),
84}
85
86#[cfg(feature = "storage")]
87impl From<redb::Error> for RuvectorError {
88    fn from(err: redb::Error) -> Self {
89        RuvectorError::DatabaseError(err.to_string())
90    }
91}
92
93#[cfg(feature = "storage")]
94impl From<redb::DatabaseError> for RuvectorError {
95    fn from(err: redb::DatabaseError) -> Self {
96        RuvectorError::DatabaseError(err.to_string())
97    }
98}
99
100#[cfg(feature = "storage")]
101impl From<redb::StorageError> for RuvectorError {
102    fn from(err: redb::StorageError) -> Self {
103        RuvectorError::DatabaseError(err.to_string())
104    }
105}
106
107#[cfg(feature = "storage")]
108impl From<redb::TableError> for RuvectorError {
109    fn from(err: redb::TableError) -> Self {
110        RuvectorError::DatabaseError(err.to_string())
111    }
112}
113
114#[cfg(feature = "storage")]
115impl From<redb::TransactionError> for RuvectorError {
116    fn from(err: redb::TransactionError) -> Self {
117        RuvectorError::DatabaseError(err.to_string())
118    }
119}
120
121#[cfg(feature = "storage")]
122impl From<redb::CommitError> for RuvectorError {
123    fn from(err: redb::CommitError) -> Self {
124        RuvectorError::DatabaseError(err.to_string())
125    }
126}