1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, RuvectorError>;
7
8#[derive(Error, Debug)]
10pub enum RuvectorError {
11 #[error("Dimension mismatch: expected {expected}, got {actual}")]
13 DimensionMismatch {
14 expected: usize,
16 actual: usize,
18 },
19
20 #[error("Vector not found: {0}")]
22 VectorNotFound(String),
23
24 #[error("Invalid parameter: {0}")]
26 InvalidParameter(String),
27
28 #[error("Invalid input: {0}")]
30 InvalidInput(String),
31
32 #[error("Invalid dimension: {0}")]
34 InvalidDimension(String),
35
36 #[error("Storage error: {0}")]
38 StorageError(String),
39
40 #[error("Model loading error: {0}")]
42 ModelLoadError(String),
43
44 #[error("Model inference error: {0}")]
46 ModelInferenceError(String),
47
48 #[error("Embedding role unsupported: {0}")]
50 EmbeddingRoleUnsupported(String),
51
52 #[error("Embedding space mismatch: stored {stored}, active {active}")]
54 EmbeddingSpaceMismatch {
55 stored: String,
57 active: String,
59 },
60
61 #[error("Index error: {0}")]
63 IndexError(String),
64
65 #[error("Serialization error: {0}")]
67 SerializationError(String),
68
69 #[error("IO error: {0}")]
71 IoError(#[from] std::io::Error),
72
73 #[error("Database error: {0}")]
75 DatabaseError(String),
76
77 #[error("Invalid path: {0}")]
79 InvalidPath(String),
80
81 #[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}