pub struct SimpleVectorBackend { /* private fields */ }Expand description
Brute-force vector search backend.
Stores documents in memory and computes cosine similarity for each query. Used as a fallback when LanceDB is not available or for small collections.
§Caching
Supports cache persistence via save_cache and
load_cache. Use is_cache_fresh
to check if a cached index is still valid.
§Limitations
- O(n) search time
- All documents must fit in memory
Implementations§
Source§impl SimpleVectorBackend
impl SimpleVectorBackend
Sourcepub fn new(provider: Arc<dyn EmbeddingProvider>) -> Self
pub fn new(provider: Arc<dyn EmbeddingProvider>) -> Self
Create a new empty simple vector backend.
Sourcepub fn add_documents(&mut self, documents: Vec<EmbeddedDocument>)
pub fn add_documents(&mut self, documents: Vec<EmbeddedDocument>)
Add documents to the backend.
Sourcepub fn save_cache(&self, path: &Path, content_hash: &str) -> Result<()>
pub fn save_cache(&self, path: &Path, content_hash: &str) -> Result<()>
Save the backend’s documents to a cache file.
Stores documents and a content hash for freshness checking. Uses JSON format for simplicity and debuggability.
Sourcepub fn load_cache(
path: &Path,
provider: Arc<dyn EmbeddingProvider>,
) -> Result<Option<Self>>
pub fn load_cache( path: &Path, provider: Arc<dyn EmbeddingProvider>, ) -> Result<Option<Self>>
Load a cached backend from disk.
Returns Ok(Some(backend)) if the cache exists and loaded successfully,
Ok(None) if the cache doesn’t exist, or Err on read/parse errors.
Sourcepub fn is_cache_fresh(path: &Path, content_hash: &str) -> bool
pub fn is_cache_fresh(path: &Path, content_hash: &str) -> bool
Check if the cache is fresh (content hasn’t changed).
Trait Implementations§
Source§impl Debug for SimpleVectorBackend
impl Debug for SimpleVectorBackend
Source§impl VectorBackend for SimpleVectorBackend
impl VectorBackend for SimpleVectorBackend
Source§fn search<'life0, 'async_trait>(
&'life0 self,
params: VectorSearchParams,
) -> Pin<Box<dyn Future<Output = Result<VectorSearchResults>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn search<'life0, 'async_trait>(
&'life0 self,
params: VectorSearchParams,
) -> Pin<Box<dyn Future<Output = Result<VectorSearchResults>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Execute a vector similarity search. Read more
Source§fn document_count(&self) -> Result<usize>
fn document_count(&self) -> Result<usize>
Get the number of indexed documents.
Auto Trait Implementations§
impl Freeze for SimpleVectorBackend
impl !RefUnwindSafe for SimpleVectorBackend
impl Send for SimpleVectorBackend
impl Sync for SimpleVectorBackend
impl Unpin for SimpleVectorBackend
impl UnsafeUnpin for SimpleVectorBackend
impl !UnwindSafe for SimpleVectorBackend
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more