Skip to main content

semantic_memory/
error.rs

1/// Error types for the semantic-memory crate.
2///
3/// All errors flow through [`MemoryError`], using `#[from]` for automatic
4/// conversion from rusqlite and reqwest errors.
5#[derive(Debug, thiserror::Error)]
6pub enum MemoryError {
7    /// SQLite / rusqlite error.
8    #[error("Database error: {0}")]
9    Database(#[from] rusqlite::Error),
10
11    /// HTTP error from the embedding provider.
12    #[error("Embedding request failed: {0}")]
13    EmbeddingRequest(#[from] reqwest::Error),
14
15    /// Embedding vector has wrong number of dimensions.
16    #[error("Embedding provider returned {actual} dimensions, expected {expected}")]
17    DimensionMismatch { expected: usize, actual: usize },
18
19    /// Raw BLOB data is not a valid embedding.
20    #[error("Invalid embedding data: expected {expected_bytes} bytes, got {actual_bytes}")]
21    InvalidEmbedding {
22        expected_bytes: usize,
23        actual_bytes: usize,
24    },
25
26    /// Database was created with a different embedding model.
27    #[error("Embedding model mismatch: database has '{stored}', config specifies '{configured}'")]
28    ModelMismatch { stored: String, configured: String },
29
30    /// Session with the given ID does not exist.
31    #[error("Session not found: {0}")]
32    SessionNotFound(String),
33
34    /// Fact with the given ID does not exist.
35    #[error("Fact not found: {0}")]
36    FactNotFound(String),
37
38    /// Document with the given ID does not exist.
39    #[error("Document not found: {0}")]
40    DocumentNotFound(String),
41
42    /// Embedding provider is unreachable or misconfigured.
43    #[error("Embedding provider unavailable: {0}")]
44    EmbedderUnavailable(String),
45
46    /// Database migration failed.
47    #[error("Migration failed at version {version}: {reason}")]
48    MigrationFailed { version: u32, reason: String },
49
50    /// HNSW index error.
51    #[error("HNSW index error: {0}")]
52    HnswError(String),
53
54    /// Invalid HNSW key format.
55    #[error("Invalid HNSW key format: {0}")]
56    InvalidKey(String),
57
58    /// Quantization error.
59    #[error("Quantization error: {0}")]
60    QuantizationError(String),
61
62    /// Storage path error.
63    #[error("Storage path error: {0}")]
64    StorageError(String),
65
66    /// Index integrity check failed.
67    #[error("Index integrity check failed: {in_sqlite_not_hnsw} items in SQLite but not HNSW, {in_hnsw_not_sqlite} items in HNSW but not SQLite")]
68    IntegrityError {
69        in_sqlite_not_hnsw: usize,
70        in_hnsw_not_sqlite: usize,
71    },
72
73    /// Catch-all for other errors.
74    #[error("{0}")]
75    Other(String),
76}