weavatrix_search_vector/
error.rs1use std::fmt;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum SearchError {
7 InvalidConfig(&'static str),
9 DimensionMismatch {
11 expected: usize,
13 actual: usize,
15 vector: Option<usize>,
17 },
18 NonFiniteValue {
20 vector: Option<usize>,
22 dimension: usize,
24 },
25 ZeroVector {
27 vector: Option<usize>,
29 },
30 DuplicateKey(u64),
32 DuplicateVectorId { key: u64, vector_id: u64 },
34 CapacityOverflow,
36 AllocationFailed,
38 WorkerPanic,
40 Storage {
42 operation: &'static str,
44 kind: std::io::ErrorKind,
46 },
47 CorruptSnapshot(&'static str),
49 UnsupportedSnapshotVersion(u32),
51 MissingKey(u64),
53 EmbeddingFailed(String),
55 ShardFailed {
57 shard: usize,
59 message: String,
61 },
62 MutationConflict,
64}
65
66impl SearchError {
67 pub(crate) fn storage(operation: &'static str, error: &std::io::Error) -> Self {
68 Self::Storage {
69 operation,
70 kind: error.kind(),
71 }
72 }
73}
74
75impl fmt::Display for SearchError {
76 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
77 match self {
78 Self::InvalidConfig(message) => write!(formatter, "invalid index config: {message}"),
79 Self::DimensionMismatch {
80 expected,
81 actual,
82 vector,
83 } => match vector {
84 Some(vector) => write!(
85 formatter,
86 "vector {vector} has {actual} dimensions; expected {expected}"
87 ),
88 None => write!(
89 formatter,
90 "query has {actual} dimensions; expected {expected}"
91 ),
92 },
93 Self::NonFiniteValue { vector, dimension } => match vector {
94 Some(vector) => {
95 write!(
96 formatter,
97 "vector {vector} has a non-finite value at dimension {dimension}"
98 )
99 }
100 None => write!(
101 formatter,
102 "query has a non-finite value at dimension {dimension}"
103 ),
104 },
105 Self::ZeroVector {
106 vector: Some(vector),
107 } => {
108 write!(formatter, "vector {vector} has zero magnitude")
109 }
110 Self::ZeroVector { vector: None } => formatter.write_str("query has zero magnitude"),
111 Self::DuplicateKey(key) => write!(formatter, "duplicate vector key {key}"),
112 Self::DuplicateVectorId { key, vector_id } => {
113 write!(formatter, "duplicate vector id {vector_id} for key {key}")
114 }
115 Self::CapacityOverflow => formatter.write_str("index capacity arithmetic overflowed"),
116 Self::AllocationFailed => formatter.write_str("index allocation failed"),
117 Self::WorkerPanic => formatter.write_str("a bounded vector-search worker panicked"),
118 Self::Storage { operation, kind } => {
119 write!(
120 formatter,
121 "index storage operation {operation} failed: {kind}"
122 )
123 }
124 Self::CorruptSnapshot(message) => {
125 write!(formatter, "corrupt vector-index snapshot: {message}")
126 }
127 Self::UnsupportedSnapshotVersion(version) => {
128 write!(
129 formatter,
130 "unsupported vector-index snapshot version {version}"
131 )
132 }
133 Self::MissingKey(key) => write!(formatter, "vector key {key} was not found"),
134 Self::EmbeddingFailed(message) => {
135 write!(formatter, "embedding provider failed: {message}")
136 }
137 Self::ShardFailed { shard, message } => {
138 write!(formatter, "vector-search shard {shard} failed: {message}")
139 }
140 Self::MutationConflict => {
141 formatter.write_str("mutable index changed repeatedly during compaction")
142 }
143 }
144 }
145}
146
147impl std::error::Error for SearchError {}