Skip to main content

xz_rag/
error.rs

1/// RAG engine errors.
2#[derive(Debug, thiserror::Error)]
3pub enum RagError {
4    /// Retrieval operation failed.
5    #[error("Retrieval error: {0}")]
6    Retrieve(String),
7
8    /// LLM generation failed.
9    #[error("Generation error: {0}")]
10    Generation(String),
11
12    /// Context window exceeded available token budget.
13    #[error("Context overflow: {used}/{max} tokens")]
14    ContextOverflow {
15        /// Number of tokens used.
16        used: usize,
17        /// Maximum allowed tokens.
18        max: usize,
19    },
20
21    /// No matching results found for the query.
22    #[error("No results found for query: {0}")]
23    NoResults(String),
24
25    /// Embedding generation failed.
26    #[error("Embedding error: {0}")]
27    Embedding(String),
28
29    /// Vector/metadata store operation failed.
30    #[error("Store error: {0}")]
31    Store(String),
32
33    /// Reranking operation failed.
34    #[error("Rerank error: {0}")]
35    Rerank(String),
36
37    /// Document chunking failed.
38    #[error("Chunking error: {0}")]
39    Chunking(String),
40
41    /// Query preprocessing (HYDE, expansion) failed.
42    #[error("Query preprocessing error: {0}")]
43    QueryPreprocessing(String),
44
45    /// Invalid or missing configuration.
46    #[error("Configuration error: {0}")]
47    Config(String),
48
49    /// LLM provider error.
50    #[error("Provider error: {0}")]
51    Provider(String),
52
53    /// Requested prompt template not found.
54    #[error("Template not found: {0}")]
55    TemplateNotFound(String),
56
57    /// Requested namespace not found in the store.
58    #[error("Namespace not found: {0}")]
59    NamespaceNotFound(String),
60}
61
62impl RagError {
63    /// Returns `true` if the error is transient and the operation can be retried.
64    pub fn is_retryable(&self) -> bool {
65        matches!(self, RagError::Retrieve(_) | RagError::Generation(_) | RagError::Store(_))
66    }
67}