pub struct InMemoryStore { /* private fields */ }Expand description
In-memory vector store using brute-force search.
This is the simplest implementation, suitable for:
- Testing and development
- Small datasets (< 10,000 vectors)
- Prototyping before moving to a production database
§Example
use phago_vectors::{InMemoryStore, VectorStore, VectorRecord};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let store = InMemoryStore::new(3);
// Insert records
store.upsert(vec![
VectorRecord::new("a", vec![1.0, 0.0, 0.0]),
VectorRecord::new("b", vec![0.0, 1.0, 0.0]),
VectorRecord::new("c", vec![0.7, 0.7, 0.0]),
]).await?;
// Search
let results = store.search(&[1.0, 0.0, 0.0], 2).await?;
assert_eq!(results[0].id, "a");
Ok(())
}Implementations§
Source§impl InMemoryStore
impl InMemoryStore
Sourcepub fn new(dimension: usize) -> Self
pub fn new(dimension: usize) -> Self
Create a new in-memory store with the specified dimension.
Uses cosine similarity by default.
Sourcepub fn with_config(dimension: usize, metric: DistanceMetric) -> Self
pub fn with_config(dimension: usize, metric: DistanceMetric) -> Self
Create a new in-memory store with a specific distance metric.
Trait Implementations§
Source§impl VectorStore for InMemoryStore
impl VectorStore for InMemoryStore
Source§fn metric(&self) -> DistanceMetric
fn metric(&self) -> DistanceMetric
Get the distance metric.
Source§fn upsert<'life0, 'async_trait>(
&'life0 self,
records: Vec<VectorRecord>,
) -> Pin<Box<dyn Future<Output = VectorResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn upsert<'life0, 'async_trait>(
&'life0 self,
records: Vec<VectorRecord>,
) -> Pin<Box<dyn Future<Output = VectorResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Insert or update records in the store. Read more
Source§fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
vector: &'life1 [f32],
k: usize,
) -> Pin<Box<dyn Future<Output = VectorResult<Vec<SearchResult>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
vector: &'life1 [f32],
k: usize,
) -> Pin<Box<dyn Future<Output = VectorResult<Vec<SearchResult>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Search for similar vectors. Read more
Source§fn search_with_filter<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
vector: &'life1 [f32],
k: usize,
filter: &'life2 HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = VectorResult<Vec<SearchResult>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn search_with_filter<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
vector: &'life1 [f32],
k: usize,
filter: &'life2 HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = VectorResult<Vec<SearchResult>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Search with metadata filter. Read more
Source§fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 str,
) -> Pin<Box<dyn Future<Output = VectorResult<Option<VectorRecord>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 str,
) -> Pin<Box<dyn Future<Output = VectorResult<Option<VectorRecord>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Get a record by ID.
Source§fn get_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ids: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = VectorResult<Vec<VectorRecord>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn get_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ids: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = VectorResult<Vec<VectorRecord>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Get multiple records by ID.
Source§fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 str,
) -> Pin<Box<dyn Future<Output = VectorResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 str,
) -> Pin<Box<dyn Future<Output = VectorResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Delete a record by ID.
Source§fn delete_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ids: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = VectorResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn delete_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ids: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = VectorResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Delete multiple records by ID.
Auto Trait Implementations§
impl !Freeze for InMemoryStore
impl RefUnwindSafe for InMemoryStore
impl Send for InMemoryStore
impl Sync for InMemoryStore
impl Unpin for InMemoryStore
impl UnwindSafe for InMemoryStore
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