Skip to main content

abu_rag/vectordb/storage/
mod.rs

1#[cfg(feature = "sqlite")]
2pub mod sqlite;
3
4mod memory;
5pub use memory::*;
6
7use std::borrow::Cow;
8use super::VectorId;
9
10#[allow(async_fn_in_trait)]
11pub trait VectorStorage: Send + Sync {
12    type Payload: Clone + 'static + Send + Sync;
13    type Error: std::error::Error + 'static + Send + Sync;
14
15    async fn add(&mut self, id: VectorId, payload: Self::Payload) -> Result<(), Self::Error>;
16    async fn add_batch<IS, PS>(&mut self, ids: IS, payloads: PS) -> Result<(), Self::Error>
17    where 
18        IS: IntoIterator<Item = VectorId>,
19        PS: IntoIterator<Item = Self::Payload>,
20    {
21        for (id, payload) in ids.into_iter().zip(payloads.into_iter()) {
22            self.add(id, payload).await?;
23        }
24        Ok(())
25    }
26
27    async fn delete(&mut self, id: VectorId) -> Result<(), Self::Error>;
28    async fn delete_batch<IS>(&mut self, ids: IS) -> Result<(), Self::Error> 
29    where 
30        IS: IntoIterator<Item = VectorId>,
31    {
32        for id in ids {
33            self.delete(id).await?;
34        }
35        Ok(())
36    }
37    
38    async fn get(&self, id: VectorId) -> Result<Option<Cow<Self::Payload>>, Self::Error>;
39
40    async fn clear(&mut self) -> Result<(), Self::Error>;
41}