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#![allow(missing_docs)]
29#![warn(clippy::all)]
30#![allow(clippy::incompatible_msrv)]
31
32pub mod advanced_features;
33
34// AgenticDB requires storage feature
35#[cfg(feature = "storage")]
36pub mod agenticdb;
37
38pub mod distance;
39pub mod embeddings;
40pub mod error;
41pub mod index;
42pub mod quantization;
43
44// Storage backends - conditional compilation based on features
45#[cfg(feature = "storage")]
46pub mod storage;
47
48#[cfg(not(feature = "storage"))]
49pub mod storage_memory;
50
51#[cfg(not(feature = "storage"))]
52pub use storage_memory as storage;
53
54pub mod types;
55pub mod vector_db;
56
57// Performance optimization modules
58pub mod arena;
59pub mod cache_optimized;
60#[cfg(all(feature = "parallel", not(target_arch = "wasm32")))]
61pub mod lockfree;
62pub mod simd_intrinsics;
63
64/// Unified Memory Pool and Paging System (ADR-006)
65///
66/// High-performance paged memory management for LLM inference:
67/// - 2MB page-granular allocation with best-fit strategy
68/// - Reference-counted pinning with RAII guards
69/// - LRU eviction with hysteresis for thrash prevention
70/// - Multi-tenant isolation with Hot/Warm/Cold residency tiers
71pub mod memory;
72
73/// Advanced techniques: hypergraphs, learned indexes, neural hashing, TDA (Phase 6)
74pub mod advanced;
75
76// Re-exports
77pub use advanced_features::{
78    ConformalConfig, ConformalPredictor, EnhancedPQ, FilterExpression, FilterStrategy,
79    FilteredSearch, HybridConfig, HybridSearch, MMRConfig, MMRSearch, PQConfig, PredictionSet,
80    BM25,
81};
82
83#[cfg(feature = "storage")]
84pub use agenticdb::{
85    AgenticDB, PolicyAction, PolicyEntry, PolicyMemoryStore, SessionStateIndex, SessionTurn,
86    WitnessEntry, WitnessLog,
87};
88
89#[cfg(feature = "api-embeddings")]
90pub use embeddings::ApiEmbedding;
91pub use embeddings::{BoxedEmbeddingProvider, EmbeddingProvider, HashEmbedding};
92
93#[cfg(feature = "real-embeddings")]
94pub use embeddings::CandleEmbedding;
95
96// Compile-time warning about AgenticDB limitations
97#[cfg(feature = "storage")]
98#[allow(deprecated, clippy::let_unit_value)]
99const _: () = {
100    #[deprecated(
101        since = "0.1.0",
102        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."
103    )]
104    const AGENTICDB_EMBEDDING_WARNING: () = ();
105    let _ = AGENTICDB_EMBEDDING_WARNING;
106};
107
108pub use error::{Result, RuvectorError};
109pub use types::{DistanceMetric, SearchQuery, SearchResult, VectorEntry, VectorId};
110pub use vector_db::VectorDB;
111
112// Quantization types (ADR-001)
113pub use quantization::{
114    BinaryQuantized, Int4Quantized, ProductQuantized, QuantizedVector, ScalarQuantized,
115};
116
117// Memory management types (ADR-001)
118pub use arena::{Arena, ArenaVec, BatchVectorAllocator, CacheAlignedVec, CACHE_LINE_SIZE};
119
120// Lock-free structures (requires parallel feature)
121#[cfg(all(feature = "parallel", not(target_arch = "wasm32")))]
122pub use lockfree::{
123    AtomicVectorPool, BatchItem, BatchResult, LockFreeBatchProcessor, LockFreeCounter,
124    LockFreeStats, LockFreeWorkQueue, ObjectPool, PooledObject, PooledVector, StatsSnapshot,
125    VectorPoolStats,
126};
127
128// Cache-optimized storage
129pub use cache_optimized::SoAVectorStorage;
130
131#[cfg(test)]
132mod tests {
133    use super::*;
134
135    #[test]
136    fn test_version() {
137        // Verify version matches workspace - use dynamic check instead of hardcoded value
138        let version = env!("CARGO_PKG_VERSION");
139        assert!(!version.is_empty(), "Version should not be empty");
140        assert!(version.starts_with("0.1."), "Version should be 0.1.x");
141    }
142}