1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! Error type for the RAG subsystem.
use std::fmt;
/// The crate-wide result alias.
pub type Result<T> = std::result::Result<T, RagError>;
/// Every fallible operation in the crate surfaces one of these.
#[derive(Debug, thiserror::Error)]
pub enum RagError {
/// Configuration was missing or invalid (bad env var, unknown backend name, …).
#[error("configuration error: {0}")]
Config(String),
/// A document could not be converted to Markdown by `docling.rs`.
#[error("document conversion failed: {0}")]
Conversion(String),
/// An embedding provider (Ollama / Gemini / ONNX / …) failed.
#[error("embedding error: {0}")]
Embedding(String),
/// The vector store / database failed.
#[error("store error: {0}")]
Store(String),
/// The chat/LLM provider (OpenRouter) failed.
#[error("llm error: {0}")]
Llm(String),
/// A document source (folder / FTP / SFTP) failed.
#[error("source error: {0}")]
Source(String),
/// A message queue backend failed.
#[error("queue error: {0}")]
Queue(String),
/// An HTTP request failed.
#[error("http error: {0}")]
Http(String),
/// I/O error.
#[error("io error: {0}")]
Io(#[from] std::io::Error),
/// JSON (de)serialization error.
#[error("json error: {0}")]
Json(#[from] serde_json::Error),
/// A feature-gated backend was requested but the crate was built without it.
#[error("backend '{0}' is not available: rebuild with the '{1}' cargo feature")]
FeatureDisabled(String, String),
}
impl RagError {
/// Helper to build a [`RagError::Config`] from anything printable.
pub fn config(msg: impl fmt::Display) -> Self {
RagError::Config(msg.to_string())
}
}
impl From<reqwest::Error> for RagError {
fn from(e: reqwest::Error) -> Self {
RagError::Http(e.to_string())
}
}
impl From<sqlx::Error> for RagError {
fn from(e: sqlx::Error) -> Self {
RagError::Store(e.to_string())
}
}