lumosai_vector_weaviate/lib.rs
1//! # Lumos Vector Weaviate
2//!
3//! Weaviate vector database implementation for the lumos-vector-core architecture.
4//!
5//! This crate provides a high-performance Weaviate backend for vector storage,
6//! implementing the unified VectorStorage trait from lumos-vector-core.
7//!
8//! ## Features
9//!
10//! - **Semantic Search**: Leverages Weaviate's semantic search capabilities
11//! - **Schema Management**: Automatic schema creation and management
12//! - **Rich Filtering**: Advanced metadata filtering with GraphQL
13//! - **Batch Operations**: Efficient bulk insert and update operations
14//! - **Multi-tenancy**: Support for Weaviate's multi-tenant features
15//!
16//! ## Example
17//!
18//! ```rust
19//! use lumos_vector_weaviate::WeaviateVectorStorage;
20//! use lumos_vector_core::prelude::*;
21//!
22//! #[tokio::main]
23//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
24//! // Create Weaviate storage
25//! let storage = WeaviateVectorStorage::new("http://localhost:8080").await?;
26//!
27//! // Create an index (class in Weaviate)
28//! let config = IndexConfig::new("Documents", 384)
29//! .with_metric(SimilarityMetric::Cosine);
30//! storage.create_index(config).await?;
31//!
32//! // Insert documents
33//! let docs = vec![
34//! Document::new("doc1", "Hello world")
35//! .with_embedding(vec![0.1; 384])
36//! .with_metadata("type", "greeting"),
37//! ];
38//! storage.upsert_documents("Documents", docs).await?;
39//!
40//! // Search
41//! let request = SearchRequest::new("Documents", vec![0.1; 384])
42//! .with_top_k(5);
43//! let results = storage.search(request).await?;
44//!
45//! Ok(())
46//! }
47//! ```
48
49pub mod storage;
50pub mod config;
51pub mod filter;
52pub mod error;
53pub mod schema;
54
55pub use storage::WeaviateVectorStorage;
56pub use config::WeaviateConfig;
57pub use error::WeaviateError;
58
59// Re-export core types for convenience
60pub use lumosai_vector_core::prelude::*;
61
62/// Create a new Weaviate vector storage instance
63pub async fn create_weaviate_storage(url: &str) -> Result<WeaviateVectorStorage> {
64 WeaviateVectorStorage::new(url).await
65}
66
67/// Create a new Weaviate vector storage instance with configuration
68pub async fn create_weaviate_storage_with_config(config: WeaviateConfig) -> Result<WeaviateVectorStorage> {
69 WeaviateVectorStorage::with_config(config).await
70}
71
72#[cfg(test)]
73mod tests {
74 use super::*;
75
76 #[tokio::test]
77 async fn test_create_storage() {
78 // This test requires a running Weaviate instance
79 // Skip if not available
80 if std::env::var("WEAVIATE_URL").is_err() {
81 return;
82 }
83
84 let url = std::env::var("WEAVIATE_URL").unwrap_or_else(|_| "http://localhost:8080".to_string());
85 let storage = create_weaviate_storage(&url).await;
86
87 // Should either succeed or fail with connection error
88 match storage {
89 Ok(_) => println!("Successfully connected to Weaviate"),
90 Err(e) => println!("Failed to connect to Weaviate: {}", e),
91 }
92 }
93}