pub use lumosai_vector_core::prelude::*;
pub use lumosai_vector_core as core;
#[cfg(feature = "memory")]
pub use lumosai_vector_memory as memory;
#[cfg(feature = "qdrant")]
pub use lumosai_vector_qdrant as qdrant;
#[cfg(feature = "weaviate")]
pub use lumosai_vector_weaviate as weaviate;
#[cfg(feature = "postgres")]
pub use lumosai_vector_postgres as postgres;
#[cfg(feature = "fastembed")]
pub use lumosai_vector_fastembed as fastembed;
#[cfg(feature = "lancedb")]
pub use lumosai_vector_lancedb as lancedb;
pub mod prelude {
pub use lumosai_vector_core::prelude::*;
#[cfg(feature = "memory")]
pub use crate::memory::MemoryVectorStorage;
#[cfg(feature = "qdrant")]
pub use crate::qdrant::QdrantVectorStorage;
#[cfg(feature = "weaviate")]
pub use crate::weaviate::WeaviateVectorStorage;
#[cfg(feature = "postgres")]
pub use crate::postgres::PostgresVectorStorage;
}
pub mod utils {
use crate::prelude::*;
#[cfg(feature = "memory")]
pub async fn create_memory_storage() -> Result<crate::memory::MemoryVectorStorage> {
crate::memory::MemoryVectorStorage::new().await
}
#[cfg(feature = "qdrant")]
pub async fn create_qdrant_storage(url: &str) -> Result<crate::qdrant::QdrantVectorStorage> {
crate::qdrant::QdrantVectorStorage::new(url).await
}
#[cfg(feature = "weaviate")]
pub async fn create_weaviate_storage(url: &str) -> Result<crate::weaviate::WeaviateVectorStorage> {
crate::weaviate::WeaviateVectorStorage::new(url).await
}
#[cfg(feature = "postgres")]
pub async fn create_postgres_storage(database_url: &str) -> Result<crate::postgres::PostgresVectorStorage> {
crate::postgres::PostgresVectorStorage::new(database_url).await
}
#[cfg(feature = "memory")]
pub async fn create_auto_storage() -> Result<crate::memory::MemoryVectorStorage> {
create_memory_storage().await
}
#[cfg(any(feature = "memory", feature = "postgres"))]
pub async fn create_best_available_storage() -> Result<Box<dyn std::any::Any + Send + Sync>> {
#[cfg(feature = "postgres")]
{
if let Ok(database_url) = std::env::var("DATABASE_URL") {
if let Ok(storage) = create_postgres_storage(&database_url).await {
return Ok(Box::new(storage));
}
}
}
#[cfg(feature = "qdrant")]
{
if let Ok(qdrant_url) = std::env::var("QDRANT_URL") {
if let Ok(storage) = create_qdrant_storage(&qdrant_url).await {
return Ok(Box::new(storage));
}
}
}
#[cfg(feature = "weaviate")]
{
if let Ok(weaviate_url) = std::env::var("WEAVIATE_URL") {
if let Ok(storage) = create_weaviate_storage(&weaviate_url).await {
return Ok(Box::new(storage));
}
}
}
#[cfg(feature = "memory")]
{
let storage = create_memory_storage().await?;
return Ok(Box::new(storage));
}
#[cfg(not(feature = "memory"))]
{
Err(VectorError::NotSupported("No storage backends available".to_string()))
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_memory_storage_integration() {
let storage = utils::create_memory_storage().await.unwrap();
let config = IndexConfig::new("test", 3)
.with_metric(SimilarityMetric::Cosine);
storage.create_index(config).await.unwrap();
let doc = Document::new("test1", "test content")
.with_embedding(vec![1.0, 0.0, 0.0])
.with_metadata("category", "test");
storage.upsert_documents("test", vec![doc]).await.unwrap();
let request = SearchRequest::new("test", vec![1.0, 0.0, 0.0])
.with_top_k(1);
let results = storage.search(request).await.unwrap();
assert_eq!(results.results.len(), 1);
assert_eq!(results.results[0].id, "test1");
}
#[tokio::test]
#[cfg(feature = "memory")]
async fn test_auto_storage_creation() {
let storage = utils::create_auto_storage().await.unwrap();
let info = storage.backend_info();
assert!(!info.name.is_empty());
assert!(!info.version.is_empty());
}
}