vector-index 0.1.0

Generic HNSW vector index with pluggable distance metrics.
Documentation
//! Error types for the vector index.

use thiserror::Error;

/// Result alias for operations on a [`HnswIndex`](crate::HnswIndex).
pub type IndexResult<T> = core::result::Result<T, IndexError>;

/// Errors returned by index operations.
#[derive(Debug, Error)]
pub enum IndexError {
    /// Attempted to insert a point with an ID that already exists.
    #[error("duplicate point id: {0}")]
    DuplicateId(crate::PointId),

    /// Attempted to access a point ID that is not in the index.
    #[error("unknown point id: {0}")]
    UnknownId(crate::PointId),

    /// The index is empty and the requested operation is not defined.
    #[error("operation requires a non-empty index")]
    Empty,

    /// Configuration parameter out of valid range.
    #[error("invalid config: {0}")]
    InvalidConfig(&'static str),

    /// A point's dimension does not match the index's dimension.
    ///
    /// Only raised by metrics that enforce a fixed dimension at runtime.
    #[error("dimension mismatch: expected {expected}, got {actual}")]
    DimensionMismatch {
        /// Dimension declared at index construction.
        expected: usize,
        /// Dimension of the offending point.
        actual: usize,
    },
}