manifold_vectors/
integration.rs

1//! Integration traits for external vector index libraries.
2
3use crate::dense::{VectorGuard, VectorIter};
4use manifold::StorageError;
5use uuid::Uuid;
6
7/// Trait for vector sources consumable by index builders
8///
9/// This trait enables external indexing libraries (HNSW, FAISS, etc.)
10/// to efficiently iterate over vectors with zero-copy access.
11pub trait VectorSource<const DIM: usize> {
12    /// Iterator type over vectors with zero-copy access
13    type Iter<'a>: Iterator<Item = Result<(Uuid, VectorGuard<'a, DIM>), StorageError>>
14    where
15        Self: 'a;
16
17    /// Returns an iterator over all vectors
18    ///
19    /// The iterator provides zero-copy access to vector data through guards.
20    fn all_vectors(&self) -> Result<Self::Iter<'_>, StorageError>;
21
22    /// Returns the number of vectors
23    fn len(&self) -> Result<u64, StorageError>;
24
25    /// Returns true if empty
26    fn is_empty(&self) -> Result<bool, StorageError> {
27        Ok(self.len()? == 0)
28    }
29}
30
31impl<const DIM: usize> VectorSource<DIM> for crate::dense::VectorTableRead<DIM> {
32    type Iter<'a>
33        = VectorIter<'a, DIM>
34    where
35        Self: 'a;
36
37    fn all_vectors(&self) -> Result<Self::Iter<'_>, StorageError> {
38        self.all_vectors()
39    }
40
41    fn len(&self) -> Result<u64, StorageError> {
42        self.len()
43    }
44}