mem0_rust/vector_stores/
mod.rs

1//! Vector store backends for mem0-rust.
2//!
3//! This module provides various vector storage backends:
4//! - Memory (in-memory, for testing and development)
5//! - Qdrant (production vector database)
6//! - PostgreSQL with pgvector
7//! - Redis with vector search
8
9mod memory;
10mod traits;
11
12pub use memory::InMemoryStore;
13pub use traits::VectorStore;
14
15#[cfg(feature = "qdrant")]
16mod qdrant;
17#[cfg(feature = "qdrant")]
18pub use qdrant::QdrantStore;
19
20#[cfg(feature = "postgres")]
21mod postgres;
22#[cfg(feature = "postgres")]
23pub use postgres::PostgresStore;
24
25#[cfg(feature = "redis")]
26mod redis;
27#[cfg(feature = "redis")]
28pub use self::redis::RedisStore;
29
30use crate::config::VectorStoreConfig;
31use crate::errors::VectorStoreError;
32use std::sync::Arc;
33
34/// Create a vector store from configuration
35pub async fn create_vector_store(
36    config: &VectorStoreConfig,
37    collection_name: &str,
38    dimensions: usize,
39) -> Result<Arc<dyn VectorStore>, VectorStoreError> {
40    match config {
41        VectorStoreConfig::Memory(_) => {
42            let _ = (collection_name, dimensions);
43            Ok(Arc::new(InMemoryStore::new()))
44        }
45
46        #[cfg(feature = "qdrant")]
47        VectorStoreConfig::Qdrant(cfg) => {
48            let store = QdrantStore::new(cfg.clone(), collection_name, dimensions).await?;
49            Ok(Arc::new(store))
50        }
51
52        #[cfg(feature = "postgres")]
53        VectorStoreConfig::Postgres(cfg) => {
54            let store = PostgresStore::new(cfg.clone(), collection_name, dimensions).await?;
55            Ok(Arc::new(store))
56        }
57
58        #[cfg(feature = "redis")]
59        VectorStoreConfig::Redis(cfg) => {
60            let store = RedisStore::new(cfg.clone(), collection_name, dimensions).await?;
61            Ok(Arc::new(store))
62        }
63    }
64}