oxibonsai_rag/error.rs
1//! Error types for the OxiBonsai RAG pipeline.
2
3use std::io;
4
5use thiserror::Error;
6
7/// Errors that can occur in the RAG pipeline.
8///
9/// The enum is marked `#[non_exhaustive]` so that new variants can be added
10/// in patch releases without breaking downstream pattern-matching. Callers
11/// should always include a wildcard (`_ => ...`) arm when exhaustively
12/// matching on [`RagError`].
13#[derive(Debug, Error)]
14#[non_exhaustive]
15pub enum RagError {
16 /// Input document was empty (no text to index).
17 #[error("document is empty")]
18 EmptyDocument,
19
20 /// Query string was empty.
21 #[error("query is empty")]
22 EmptyQuery,
23
24 /// Retrieval was attempted before any documents were indexed.
25 #[error("no documents have been indexed yet")]
26 NoDocumentsIndexed,
27
28 /// The embedding backend failed to produce a vector.
29 #[error("embedding failed: {0}")]
30 EmbeddingFailed(String),
31
32 /// A vector was inserted with a dimensionality that does not match the
33 /// store's dimension.
34 #[error("dimension mismatch: expected {expected}, got {got}")]
35 DimensionMismatch {
36 /// The dimensionality the store was configured with.
37 expected: usize,
38 /// The dimensionality of the offending vector.
39 got: usize,
40 },
41
42 /// A persistence operation (save, load, schema-version check) failed.
43 #[error("persistence error: {0}")]
44 Persistence(String),
45
46 /// A vector or scalar input contained `NaN` or `±∞`. Distance metrics
47 /// reject non-finite inputs eagerly rather than silently propagating
48 /// poison values through downstream arithmetic.
49 #[error("non-finite value in input (NaN or infinity)")]
50 NonFinite,
51
52 /// A metadata filter was ill-formed (e.g. empty key, empty `In` list).
53 #[error("invalid metadata filter: {0}")]
54 InvalidFilter(String),
55
56 /// I/O error (wraps [`std::io::Error`]).
57 #[error("I/O error: {0}")]
58 Io(#[from] io::Error),
59}