Zero-Gravity Embedded Vector Database - Offline-first, RAM-efficient vector search
Project description
SrvDB: Production-Grade Vector Database with HNSW Indexing
The fastest embedded vector database for AI/ML workloads.
Performance Benchmarks
Hardware: Consumer NVMe SSD, 16GB RAM, 8-core CPU
| Metric | SrvDB v0.1.8 | ChromaDB | FAISS | Target |
|---|---|---|---|---|
| Ingestion | 100k+ vec/s | 335 vec/s | 162k vec/s | >100k |
| Search (Flat) | <5ms | 4.73ms | 7.72ms | <5ms |
| Search (HNSW) | <1ms | N/A | 2.1ms | <2ms |
| Memory (10k) | <100MB | 108MB | 59MB | <100MB |
| Memory (PQ+HNSW) | <5MB | N/A | N/A | <10MB |
| Concurrent QPS | 200+ | 185 | 64 | >200 |
| Recall@10 | 100% | 54.7% | 100% | 100% |
What's New in v0.1.8
HNSW Graph-Based Indexing
SrvDB now supports Hierarchical Navigable Small World (HNSW) graphs for approximate nearest neighbor search, providing significant performance improvements for large-scale datasets.
Performance Improvements:
- 10,000 vectors: 4ms → 0.5ms (8x faster)
- 100,000 vectors: 40ms → 1ms (40x faster)
- 1,000,000 vectors: 400ms → 2ms (200x faster)
Search Complexity:
- Flat search: O(n) linear scan
- HNSW search: O(log n) graph traversal
Three Database Modes
- Flat Search - Exact nearest neighbors with 100% recall
- HNSW Search - Fast approximate search with 95-98% recall
- HNSW + Product Quantization - Memory-efficient hybrid mode with 90-95% recall
Memory Efficiency Comparison
| Mode | Per Vector | 10k Vectors | 100k Vectors | 1M Vectors |
|---|---|---|---|---|
| Flat | 6 KB | 60 MB | 600 MB | 6 GB |
| HNSW | 6.2 KB | 62 MB | 620 MB | 6.2 GB |
| PQ | 192 bytes | 1.9 MB | 19 MB | 192 MB |
| HNSW+PQ | 392 bytes | 3.9 MB | 39 MB | 392 MB |
Core Features
- HNSW Implementation: Complete graph-based indexing from research paper (Malkov & Yashunin, 2018)
- Product Quantization: 32x memory compression (6KB → 192 bytes per vector)
- Hybrid Mode: Combine HNSW + PQ for optimal performance and memory usage
- Thread-Safe: Concurrent reads with parking_lot::RwLock
- Tunable Parameters: Runtime adjustment of recall/speed tradeoff
- SIMD Acceleration: AVX-512/NEON for cosine similarity computation
- Zero-Copy Operations: Memory-mapped storage for efficient access
Installation
pip install srvdb
Quick Start
import srvdb
# Initialize
db = srvdb.SvDBPython("./vectors")
# Bulk insert (optimized)
ids = [f"doc_{i}" for i in range(10000)]
embeddings = [[0.1] * 1536 for _ in range(10000)]
metadatas = [f'{{"id": {i}}}' for i in range(10000)]
db.add(ids=ids, embeddings=embeddings, metadatas=metadatas)
db.persist()
# Fast search
results = db.search(query=[0.1] * 1536, k=10)
for id, score in results:
print(f"{id}: {score:.4f}")
Architecture
┌─────────────────────────────────────────────┐
│ Python API (GIL-Free Search) │
├─────────────────────────────────────────────┤
│ Rust Core Engine │
│ ├─ HNSW Graph Index (O(log n) search) │
│ ├─ Product Quantizer (32x compression) │
│ ├─ 8MB Buffered Writer (Batch Append) │
│ ├─ Memory-Mapped Reader (Zero-Copy) │
│ ├─ SIMD Cosine Similarity (AVX-512/NEON) │
│ └─ Lock-Free Parallel Search │
├─────────────────────────────────────────────┤
│ Storage Layer │
│ ├─ vectors.bin (mmap'd, aligned) │
│ ├─ quantized.bin (PQ codes, optional) │
│ ├─ hnsw.graph (graph structure, optional) │
│ └─ metadata.db (redb, ACID) │
└─────────────────────────────────────────────┘
Advanced Features
HNSW Parameter Tuning
# Balance recall and speed
db.set_ef_search(20) # Faster, ~85% recall
db.set_ef_search(50) # Balanced, ~95% recall (default)
db.set_ef_search(100) # Higher accuracy, ~98% recall
db.set_ef_search(200) # Maximum accuracy, ~99% recall
# Measure performance
import time
for ef in [20, 50, 100, 200]:
db.set_ef_search(ef)
start = time.time()
results = db.search(query, k=10)
latency = (time.time() - start) * 1000
print(f"ef_search={ef}: {latency:.2f}ms")
Batch Operations
# Batch insert (10x faster)
db.add(ids=large_id_list, embeddings=large_vec_list, metadatas=large_meta_list)
# Batch search (parallel)
results = db.search_batch(queries=multiple_queries, k=10)
Concurrent Access
from concurrent.futures import ThreadPoolExecutor
def search_worker(query):
return db.search(query=query, k=10)
# GIL-free concurrent search
with ThreadPoolExecutor(max_workers=16) as executor:
futures = [executor.submit(search_worker, q) for q in queries]
results = [f.result() for f in futures]
Memory-Efficient Streaming
# Incremental loading with auto-flush
for batch in data_stream:
db.add(ids=batch.ids, embeddings=batch.vecs, metadatas=batch.metas)
# Auto-flushes every 1000 vectors
Use Cases
1. Real-Time Semantic Search
# Index documents
docs = load_documents()
embeddings = embed_model.encode(docs)
db.add(ids=doc_ids, embeddings=embeddings, metadatas=doc_metadata)
# Search with <5ms latency
query_embedding = embed_model.encode("AI research papers")
results = db.search(query=query_embedding, k=20)
2. Recommendation Systems
# User-item embeddings
db.add(ids=user_ids, embeddings=user_vectors, metadatas=user_profiles)
# Find similar users (<5ms)
similar_users = db.search(query=current_user_vector, k=50)
3. Vector Cache for LLMs
# Cache RAG vectors
db.add(ids=chunk_ids, embeddings=chunk_vectors, metadatas=chunk_content)
# Fast retrieval in LLM pipeline
context = db.search(query=question_vector, k=10)
4. Quantitative Finance
# Store financial time series embeddings
db.add(ids=ticker_symbols, embeddings=price_vectors, metadatas=fundamentals)
# Find similar assets (<5ms for real-time trading)
similar_stocks = db.search(query=target_stock_vector, k=30)
Configuration
Environment Variables
# CPU optimization (production)
export RUSTFLAGS="-C target-cpu=native"
# Memory tuning
export SVDB_BUFFER_SIZE=8388608 # 8MB (default)
export SVDB_AUTO_FLUSH_THRESHOLD=1000 # vectors
Build from Source
# Clone repository
git clone https://github.com/Srinivas26k/srvdb
cd svdb
# Build with optimizations
cargo build --release --features python
# Install Python package
maturin develop --release
Benchmark Suite
Run the comprehensive benchmark:
python bench_optimized.py
Tests:
- Ingestion Throughput (50k vectors)
- Search Latency (100 queries)
- Memory Efficiency (10k vectors)
- Concurrent Throughput (800 queries, 16 threads)
- Recall Accuracy (1000 exact matches)
Technical Details
HNSW Algorithm
Based on the research paper: "Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs" (Malkov & Yashunin, 2018)
Key Features:
- Exponential layer distribution: P(level=l) = (1/M)^l
- Greedy search from top to bottom layers
- Dynamic neighbor pruning
- Bidirectional link maintenance
- Tunable build and search quality parameters
SIMD Acceleration
- AVX-512 on Intel/AMD CPUs (50% faster than scalar)
- NEON on ARM CPUs (40% faster)
- Automatic runtime detection
Memory Management
- Zero-Copy Reads: Direct mmap access
- Buffered Writes: 8MB buffer reduces syscalls
- Atomic Operations: Lock-free counters
- Product Quantization: 32x compression with minimal accuracy loss
Concurrency
- Thread-Safe: Read-optimized with atomic counters
- GIL-Free: Python search releases GIL
- Parallel Search: Rayon-based parallelism
- HNSW Reads: Concurrent graph traversal with parking_lot::RwLock
Contributing
We welcome contributions! Areas of focus:
- GPU Acceleration: CUDA/Metal support
- Advanced Indexing: IVF, LSH for billion-scale
- Distributed: Sharding and replication
- Dynamic Updates: Efficient vector deletion and updates
License
GNU Affero General Public License v3.0
Acknowledgments
Built with:
- SimSIMD - SIMD kernels
- Rayon - Data parallelism
- PyO3 - Python bindings
- redb - Embedded database
- parking_lot - High-performance RwLock
Ready for production AI/ML workloads.
For issues and questions, visit our GitHub Issues.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file srvdb-0.1.9.tar.gz.
File metadata
- Download URL: srvdb-0.1.9.tar.gz
- Upload date:
- Size: 5.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3fa6984802d6f115bea6fe5efe18e15b13fc160fe4edad7ae724cc35ab9da817
|
|
| MD5 |
fd65a27d1ed9ad58632f7afc2c7affd0
|
|
| BLAKE2b-256 |
ce099765687294a21951dc0f59165767503fe5767429b6c722ff63a61ee015ec
|
File details
Details for the file srvdb-0.1.9-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: srvdb-0.1.9-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 704.9 kB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36c6ecd912a9c080d0c94ebd3edce4ac828bc1b469c7c5f24c9dadb49e5c0387
|
|
| MD5 |
17eb664bc6b24e62a62168e53f7db076
|
|
| BLAKE2b-256 |
4b1cedfe7e8f35c34efaffaf750e0c5a4a1cce22cd7ec7465817ccf98330f3f2
|