use alloc::sync::Arc;
use thiserror::Error;
use crate::types::VectorId;
#[non_exhaustive]
#[derive(Debug, Error, Clone, PartialEq, Eq)]
pub enum CodecError {
#[error("bit_width must be one of [2, 4, 8], got {got}")]
UnsupportedBitWidth {
got: u8,
},
#[error("dimension must be > 0, got {got}")]
InvalidDimension {
got: u32,
},
#[error("vector length {got} does not match config dimension {expected}")]
DimensionMismatch {
expected: u32,
got: u32,
},
#[error("codebook bit_width {got} does not match config bit_width {expected}")]
CodebookIncompatible {
expected: u8,
got: u8,
},
#[error("compressed config_hash {got:?} does not match config hash {expected:?}")]
ConfigMismatch {
expected: Arc<str>,
got: Arc<str>,
},
#[error("codebook must have {expected} entries for bit_width={bit_width}, got {got}")]
CodebookEntryCount {
expected: u32,
got: u32,
bit_width: u8,
},
#[error("codebook entries must be sorted ascending")]
CodebookNotSorted,
#[error("codebook must contain {expected} distinct values, got {got}")]
CodebookDuplicate {
expected: u32,
got: u32,
},
#[error("insufficient training data for {expected} distinct entries")]
InsufficientTrainingData {
expected: u32,
},
#[error("index {index} is out of range [0, {bound})")]
IndexOutOfRange {
index: u8,
bound: u32,
},
#[error("input and output lengths disagree: {left} vs {right}")]
LengthMismatch {
left: usize,
right: usize,
},
#[error("invalid residual flag: expected 0x00 or 0x01, got {got:#04x}")]
InvalidResidualFlag {
got: u8,
},
}
#[non_exhaustive]
#[derive(Debug, Error, Clone, PartialEq, Eq)]
pub enum CorpusError {
#[error("codec error: {0}")]
Codec(
#[from]
#[source]
CodecError,
),
#[error("duplicate vector_id {id:?}")]
DuplicateVectorId {
id: VectorId,
},
#[error("unknown vector_id {id:?}")]
UnknownVectorId {
id: VectorId,
},
#[error("compression policy is immutable once set")]
PolicyImmutable,
#[error("dimension mismatch: expected {expected}, got {got}")]
DimensionMismatch {
expected: u32,
got: u32,
},
#[error("batch atomicity failure at index {index}: {source}")]
BatchAtomicityFailure {
index: usize,
source: alloc::boxed::Box<CorpusError>,
},
}
#[non_exhaustive]
#[derive(Debug, Error, Clone)]
pub enum BackendError {
#[error("backend is empty")]
Empty,
#[error("top_k must be > 0")]
InvalidTopK,
#[error("adapter error: {0}")]
Adapter(Arc<str>),
}