manifoldb_vector/error/
mod.rs

1//! Error types for the vector crate.
2
3use thiserror::Error;
4
5/// Errors that can occur in vector operations.
6#[derive(Debug, Error)]
7pub enum VectorError {
8    /// Dimension mismatch between vectors or embedding spaces.
9    #[error("dimension mismatch: expected {expected}, got {actual}")]
10    DimensionMismatch {
11        /// The expected dimension.
12        expected: usize,
13        /// The actual dimension.
14        actual: usize,
15    },
16
17    /// Invalid dimension (e.g., zero).
18    #[error("invalid dimension: expected at least {expected}, got {actual}")]
19    InvalidDimension {
20        /// The minimum expected dimension.
21        expected: usize,
22        /// The actual dimension.
23        actual: usize,
24    },
25
26    /// Index out of bounds.
27    #[error("index out of bounds: {index} >= {max}")]
28    IndexOutOfBounds {
29        /// The index that was out of bounds.
30        index: usize,
31        /// The maximum valid index (exclusive).
32        max: usize,
33    },
34
35    /// Invalid value in a vector (NaN, Infinity).
36    #[error("invalid value at index {index}: {value} - {reason}")]
37    InvalidValue {
38        /// The index of the invalid value.
39        index: usize,
40        /// The invalid value.
41        value: f32,
42        /// The reason the value is invalid.
43        reason: &'static str,
44    },
45
46    /// Invalid embedding name.
47    #[error("invalid embedding name: {0}")]
48    InvalidName(String),
49
50    /// Embedding space not found.
51    #[error("embedding space not found: {0}")]
52    SpaceNotFound(String),
53
54    /// Embedding not found for entity.
55    #[error("embedding not found for entity {entity_id} in space '{space}'")]
56    EmbeddingNotFound {
57        /// The entity ID.
58        entity_id: u64,
59        /// The embedding space name.
60        space: String,
61    },
62
63    /// Encoding/decoding error.
64    #[error("encoding error: {0}")]
65    Encoding(String),
66
67    /// Storage backend error.
68    #[error("storage error: {0}")]
69    Storage(#[from] manifoldb_storage::StorageError),
70
71    /// Lock poisoned - indicates concurrent panic corrupted the data structure.
72    ///
73    /// This error is unrecoverable - the index must be dropped and recreated.
74    #[error("index corrupted: lock poisoned due to prior panic in another thread")]
75    LockPoisoned,
76
77    /// Node not found in the graph.
78    ///
79    /// This typically indicates an internal inconsistency in the index structure.
80    #[error("node not found in graph: entity {0}")]
81    NodeNotFound(manifoldb_core::EntityId),
82
83    /// Invalid graph state - internal invariant violation.
84    ///
85    /// This typically indicates an internal bug where expected graph state is missing.
86    #[error("invalid graph state: {0}")]
87    InvalidGraphState(&'static str),
88}