Skip to main content

SimpleVectorBackend

Struct SimpleVectorBackend 

Source
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

Source

pub fn new(provider: Arc<dyn EmbeddingProvider>) -> Self

Create a new empty simple vector backend.

Source

pub fn add_documents(&mut self, documents: Vec<EmbeddedDocument>)

Add documents to the backend.

Source

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.

Source

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.

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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,

Execute a vector similarity search. Read more
Source§

fn name(&self) -> &str

Get the backend name for diagnostics.
Source§

fn document_count(&self) -> Result<usize>

Get the number of indexed documents.
Source§

fn is_ready(&self) -> bool

Check if the backend is ready to handle queries.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.