xz-rag 0.1.1

Multi-channel Retrieval-Augmented Generation engine
Documentation
/// RAG engine errors.
#[derive(Debug, thiserror::Error)]
pub enum RagError {
    /// Retrieval operation failed.
    #[error("Retrieval error: {0}")]
    Retrieve(String),

    /// LLM generation failed.
    #[error("Generation error: {0}")]
    Generation(String),

    /// Context window exceeded available token budget.
    #[error("Context overflow: {used}/{max} tokens")]
    ContextOverflow {
        /// Number of tokens used.
        used: usize,
        /// Maximum allowed tokens.
        max: usize,
    },

    /// No matching results found for the query.
    #[error("No results found for query: {0}")]
    NoResults(String),

    /// Embedding generation failed.
    #[error("Embedding error: {0}")]
    Embedding(String),

    /// Vector/metadata store operation failed.
    #[error("Store error: {0}")]
    Store(String),

    /// Reranking operation failed.
    #[error("Rerank error: {0}")]
    Rerank(String),

    /// Document chunking failed.
    #[error("Chunking error: {0}")]
    Chunking(String),

    /// Query preprocessing (HYDE, expansion) failed.
    #[error("Query preprocessing error: {0}")]
    QueryPreprocessing(String),

    /// Invalid or missing configuration.
    #[error("Configuration error: {0}")]
    Config(String),

    /// LLM provider error.
    #[error("Provider error: {0}")]
    Provider(String),

    /// Requested prompt template not found.
    #[error("Template not found: {0}")]
    TemplateNotFound(String),

    /// Requested namespace not found in the store.
    #[error("Namespace not found: {0}")]
    NamespaceNotFound(String),
}

impl RagError {
    /// Returns `true` if the error is transient and the operation can be retried.
    pub fn is_retryable(&self) -> bool {
        matches!(self, RagError::Retrieve(_) | RagError::Generation(_) | RagError::Store(_))
    }
}