1use nodedb_mem::MemError;
6
7#[derive(Debug, thiserror::Error)]
9#[non_exhaustive]
10pub enum VectorError {
11 #[error("memory budget exhausted: {0}")]
12 BudgetExhausted(#[from] MemError),
13 #[error("vector dimension mismatch: expected {expected}, got {got}")]
17 DimensionMismatch { expected: usize, got: usize },
18 #[error("stored vector data has dimension {got}, index expects {expected}")]
22 StoredDimensionMismatch { expected: usize, got: usize },
23 #[error("vector search filter bitmap does not decode: {detail}")]
26 InvalidFilterBitmap { detail: String },
27 #[error("invalid vector index input: {detail}")]
30 InvalidInput { detail: String },
31 #[error(
39 "vector for node {id} is unavailable: node storage is empty and no \
40 segment backing provides it (graph-only checkpoint without backing?)"
41 )]
42 VectorUnavailable { id: u32 },
43 #[error("vector decode failed for node {id}: {detail}")]
45 VectorDecodeFailed { id: u32, detail: String },
46 #[error("unsupported HNSW checkpoint version {found}; expected {expected}")]
47 UnsupportedVersion { found: u8, expected: u8 },
48 #[error("invalid PQ codec magic bytes")]
49 InvalidMagic,
50 #[error("PQ codec deserialization failed: {0}")]
51 DeserializationFailed(String),
52 #[error(
54 "vector checkpoint is encrypted but no encryption key was provided; \
55 cannot load plaintext from an encrypted checkpoint"
56 )]
57 CheckpointEncryptedNoKey,
58 #[error(
60 "vector checkpoint is plaintext but an encryption key is configured; \
61 refusing to load an unencrypted checkpoint when encryption is required"
62 )]
63 CheckpointPlaintextKeyRequired,
64 #[error("vector checkpoint encryption error: {detail}")]
66 CheckpointEncryptionError { detail: String },
67 #[error("vector checkpoint serialization error: {detail}")]
69 CheckpointSerializationError { detail: String },
70 #[error("vector checkpoint deserialization error: {detail}")]
72 CheckpointDeserializationError { detail: String },
73 #[error("vector segment I/O error: {0}")]
75 SegmentIo(#[from] std::io::Error),
76}
77
78pub fn check_dim(expected: usize, got: usize) -> Result<(), VectorError> {
81 if expected == got {
82 Ok(())
83 } else {
84 Err(VectorError::DimensionMismatch { expected, got })
85 }
86}