Skip to main content

xz_embed/
error.rs

1use std::fmt::Debug;
2
3/// 嵌入模型错误
4#[derive(Debug, thiserror::Error)]
5pub enum EmbedError {
6    #[error("嵌入模型错误: {0}")]
7    Model(String),
8
9    #[error("批次大小超限: {actual} > {limit}")]
10    BatchSizeExceeded { actual: usize, limit: usize },
11
12    #[error("输入超长: token 数 {actual} > {limit}")]
13    InputTooLong { actual: usize, limit: usize },
14
15    #[error("维度不匹配: expected {expected}, got {actual}")]
16    DimensionMismatch { expected: usize, actual: usize },
17
18    #[error("网络错误: {0}")]
19    Network(String),
20
21    #[error("限流: {retry_after_ms}ms 后重试")]
22    RateLimit { retry_after_ms: u64 },
23
24    #[error("认证失败: {0}")]
25    Auth(String),
26
27    #[error("配置错误: {0}")]
28    Config(String),
29
30    #[error("批次为空")]
31    EmptyBatch,
32}
33
34impl EmbedError {
35    pub fn is_retryable(&self) -> bool {
36        matches!(self, EmbedError::Network(_) | EmbedError::RateLimit { .. })
37    }
38}
39
40/// 向量存储错误
41#[derive(Debug, thiserror::Error)]
42pub enum StoreError {
43    #[error("数据库错误: {0}")]
44    Database(String),
45
46    #[error("维度不匹配: expected {expected}, got {actual}")]
47    DimensionMismatch { expected: usize, actual: usize },
48
49    #[error("条目未找到: {0}")]
50    NotFound(String),
51
52    #[error("存储已关闭")]
53    Closed,
54
55    #[error("序列化错误: {0}")]
56    Serialization(String),
57
58    #[error("索引重建中")]
59    Indexing,
60
61    #[error("存储已满: {used}/{capacity} bytes")]
62    Full { used: u64, capacity: u64 },
63}