Skip to main content

ruvector_core/
lib.rs

1//! # Ruvector Core
2//!
3//! High-performance Rust-native vector database with HNSW indexing and SIMD-optimized operations.
4//!
5//! ## Working Features (Tested & Benchmarked)
6//!
7//! - **HNSW Indexing**: Approximate nearest neighbor search with O(log n) complexity
8//! - **SIMD Distance**: SimSIMD-powered distance calculations (~16M ops/sec for 512-dim)
9//! - **Quantization**: Scalar (4x), Int4 (8x), Product (8-16x), and binary (32x) compression with distance support
10//! - **Persistence**: REDB-based storage with config persistence
11//! - **Search**: ~2.5K queries/sec on 10K vectors (benchmarked)
12//!
13//! ## ⚠️ Experimental/Incomplete Features - READ BEFORE USE
14//!
15//! - **AgenticDB**: ⚠️⚠️⚠️ **CRITICAL WARNING** ⚠️⚠️⚠️
16//!   - Uses PLACEHOLDER hash-based embeddings, NOT real semantic embeddings
17//!   - "dog" and "cat" will NOT be similar (different characters)
18//!   - "dog" and "god" WILL be similar (same characters) - **This is wrong!**
19//!   - **MUST integrate real embedding model for production** (ONNX, Candle, or API)
20//!   - See [`agenticdb`] module docs and `/examples/onnx-embeddings` for integration
21//! - **Advanced Features**: Conformal prediction, hybrid search - functional but less tested
22//!
23//! ## What This Is NOT
24//!
25//! - This is NOT a complete RAG solution - you need external embedding models
26//! - Examples use mock embeddings for demonstration only
27
28#![warn(missing_docs)]
29#![warn(clippy::all)]
30
31pub mod advanced_features;
32
33// AgenticDB requires storage feature
34#[cfg(feature = "storage")]
35pub mod agenticdb;
36
37pub mod distance;
38pub mod embeddings;
39pub mod error;
40pub mod index;
41pub mod quantization;
42
43// Storage backends - conditional compilation based on features
44#[cfg(feature = "storage")]
45pub mod storage;
46
47#[cfg(not(feature = "storage"))]
48pub mod storage_memory;
49
50#[cfg(not(feature = "storage"))]
51pub use storage_memory as storage;
52
53pub mod types;
54pub mod vector_db;
55
56// Performance optimization modules
57pub mod arena;
58pub mod cache_optimized;
59#[cfg(all(feature = "parallel", not(target_arch = "wasm32")))]
60pub mod lockfree;
61pub mod simd_intrinsics;
62
63/// Unified Memory Pool and Paging System (ADR-006)
64///
65/// High-performance paged memory management for LLM inference:
66/// - 2MB page-granular allocation with best-fit strategy
67/// - Reference-counted pinning with RAII guards
68/// - LRU eviction with hysteresis for thrash prevention
69/// - Multi-tenant isolation with Hot/Warm/Cold residency tiers
70pub mod memory;
71
72/// Advanced techniques: hypergraphs, learned indexes, neural hashing, TDA (Phase 6)
73pub mod advanced;
74
75// Re-exports
76pub use advanced_features::{
77    ConformalConfig, ConformalPredictor, EnhancedPQ, FilterExpression, FilterStrategy,
78    FilteredSearch, HybridConfig, HybridSearch, MMRConfig, MMRSearch, PQConfig, PredictionSet,
79    BM25,
80};
81
82#[cfg(feature = "storage")]
83pub use agenticdb::{
84    AgenticDB, PolicyAction, PolicyEntry, PolicyMemoryStore, SessionStateIndex, SessionTurn,
85    WitnessEntry, WitnessLog,
86};
87
88#[cfg(feature = "api-embeddings")]
89pub use embeddings::ApiEmbedding;
90pub use embeddings::{BoxedEmbeddingProvider, EmbeddingProvider, HashEmbedding};
91
92#[cfg(feature = "real-embeddings")]
93pub use embeddings::CandleEmbedding;
94
95// Compile-time warning about AgenticDB limitations
96#[cfg(feature = "storage")]
97const _: () = {
98    // This will appear in cargo build output as a note
99    #[deprecated(
100        since = "0.1.0",
101        note = "AgenticDB uses placeholder hash-based embeddings. For semantic search, integrate a real embedding model (ONNX, Candle, or API). See /examples/onnx-embeddings for production setup."
102    )]
103    const AGENTICDB_EMBEDDING_WARNING: () = ();
104    let _ = AGENTICDB_EMBEDDING_WARNING;
105};
106
107pub use error::{Result, RuvectorError};
108pub use types::{DistanceMetric, SearchQuery, SearchResult, VectorEntry, VectorId};
109pub use vector_db::VectorDB;
110
111// Quantization types (ADR-001)
112pub use quantization::{
113    BinaryQuantized, Int4Quantized, ProductQuantized, QuantizedVector, ScalarQuantized,
114};
115
116// Memory management types (ADR-001)
117pub use arena::{Arena, ArenaVec, BatchVectorAllocator, CacheAlignedVec, CACHE_LINE_SIZE};
118
119// Lock-free structures (requires parallel feature)
120#[cfg(all(feature = "parallel", not(target_arch = "wasm32")))]
121pub use lockfree::{
122    AtomicVectorPool, BatchItem, BatchResult, LockFreeBatchProcessor, LockFreeCounter,
123    LockFreeStats, LockFreeWorkQueue, ObjectPool, PooledObject, PooledVector, StatsSnapshot,
124    VectorPoolStats,
125};
126
127// Cache-optimized storage
128pub use cache_optimized::SoAVectorStorage;
129
130#[cfg(test)]
131mod tests {
132    use super::*;
133
134    #[test]
135    fn test_version() {
136        // Verify version matches workspace - use dynamic check instead of hardcoded value
137        let version = env!("CARGO_PKG_VERSION");
138        assert!(!version.is_empty(), "Version should not be empty");
139        assert!(version.starts_with("0.1."), "Version should be 0.1.x");
140    }
141}