๐ OpenDB
High-Performance Hybrid Embedded Database for Rust
OpenDB is a high-performance, pure Rust hybrid embedded database combining:
- Key-Value Store: Fast, persistent KV operations
- Structured Records: Schema-free JSON-like memory storage
- Graph Relationships: Bidirectional edges with typed relations
- Vector Embeddings: Semantic similarity search
- ACID Transactions: Full transaction support with snapshot isolation
- In-Memory Caching: LRU cache for hot data
- Multimodal Support: PDF, DOCX, audio, video, and text file processing for AI/LLM applications
Built on RocksDB for exceptional throughput and performance, OpenDB is designed for AI agent memory systems, knowledge graphs, semantic search, and multimodal RAG (Retrieval Augmented Generation) applications.
Features
- ๐ High Performance: Built on RocksDB with optimized LSM tree storage
- ๐ ACID Transactions: Full transactional support with snapshot isolation
- ๐ง Semantic Search: Vector similarity search for embeddings
- ๐ Graph Database: Bidirectional relationship tracking with typed edges
- ๐พ Persistent Storage: Durable RocksDB backend with write-ahead logging
- โก In-Memory Cache: LRU caching for frequently accessed data
- ๐ง Zero-Copy Serialization: Fast encoding/decoding with rkyv
- ๐ฆ Pure Rust: Memory-safe, concurrent, and type-safe
- ๐ Key-Value Store: Fast point lookups and prefix scans
- ๐ Structured Records: Schema-free JSON-like memory storage with metadata
- ๐ Graph Relationships: Bidirectional edges with custom relation types
- ๐ฏ Vector Embeddings: Support for high-dimensional embeddings (384/768/1536-dim)
- ๐ Column Families: Data isolation with separate column families for KV, records, graph, and vectors
- ๐ Optimistic Locking: Compare-and-swap operations for conflict handling
- ๐ฆ Batch Operations: Efficient bulk inserts and updates
- ๐ Performance Tuning: Configurable write buffers, block cache, and compression
- ๐ฌ Multimodal File Support: Built-in types for PDF, DOCX, audio, video, and text processing
- ๐ค AI/LLM Ready: Designed for agent memory, document Q&A, and multimodal RAG pipelines
- ๐ฆ Document Chunking: Split large files into processable chunks with per-chunk embeddings
- โ๏ธ Customizable Storage: Configure database location, cache sizes, and vector dimensions
- ๐จ Colored Console Output: Beautiful, emoji-rich terminal output for examples and debugging
Quick Start
Installation
Option 1: Using Cargo (Recommended)
Add OpenDB to your Cargo.toml:
[]
= "0.1"
Or use cargo-add:
Option 2: Pre-built Binaries
Download platform-specific builds from GitHub Releases:
- Linux x86_64:
opendb-linux-x86_64.tar.gz - Linux ARM64:
opendb-linux-aarch64.tar.gz - macOS Intel:
opendb-macos-x86_64.tar.gz - macOS Apple Silicon:
opendb-macos-aarch64.tar.gz - Windows x86_64:
opendb-windows-x86_64.zip
See the Manual Installation section below for detailed instructions.
Option 3: Build from Source
Build Requirements:
- Rust 2021 edition or later
- Clang and LLVM (for RocksDB)
- Linux:
sudo apt-get install clang llvm - macOS:
brew install llvm - Windows:
choco install llvm
- Linux:
Basic Usage
use ;
use Uuid;
// Open database (creates a folder at ./data with multiple files)
let db = open?;
// Store a memory
let memory = Memory ;
db.insert_memory?;
// Retrieve by ID
let retrieved = db.get_memory?;
// Search by similarity
let query_embedding = vec!;
let similar = db.search_similar?;
// Create relationships
db.link_memories?;
let related = db.get_related?;
Key-Value Operations
// Simple KV operations
db.put?;
let value = db.get?;
// Prefix scanning
for in db.scan_prefix?
Transactions
// Begin transaction
let txn = db.begin_transaction?;
// Transactional operations
txn.put?;
txn.put?;
// Commit atomically
db.commit_transaction?;
Configuration & Custom Storage
OpenDB supports flexible configuration including custom storage locations, cache sizes, and vector dimensions:
use ;
// Customize all settings with method chaining
let options = new
.with_storage_path // Custom storage location
.with_kv_cache_size // Larger KV cache
.with_record_cache_size // Larger record cache
.dimension; // Larger embeddings (e.g., OpenAI)
let db = open_with_options?;
Configuration Options:
with_storage_path(): Custom database directory (useful for multi-tenant or production deployments)with_kv_cache_size(): Number of KV entries to cache (default: 1000)with_record_cache_size(): Number of memory records to cache (default: 500)dimension(): Embedding vector dimension (default: 384 for sentence-transformers)
Production Examples:
// Environment-based configuration
let db_path = var
.unwrap_or_else;
let prod_options = with_dimension
.with_kv_cache_size
.with_record_cache_size;
let db = open_with_options?;
// Multi-tenant pattern
for tenant_id in &
See the custom_storage example for comprehensive configuration patterns.
Run it with:
Multimodal AI Applications
OpenDB provides built-in support for multimodal file processing, perfect for AI agents, RAG systems, and document Q&A:
use ;
let db = open?;
// Process a PDF document
let mut pdf_doc = new
.with_metadata
.with_metadata;
// Add chunks for large documents
pdf_doc.add_chunk;
// Supports: PDF, DOCX, TXT, MP3, MP4, WAV, JPG, PNG, and more
let file_type = from_extension;
println!; // "Audio file"
See the multimodal_agent example for a complete demo of:
- PDF, DOCX, and text document processing
- Audio transcription workflows (with whisper-rs)
- Video caption extraction (with ffmpeg)
- Document chunking strategies
- Embedding generation patterns
- Production RAG pipelines
Run it with:
Architecture
OpenDB is built with a modular architecture:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ OpenDB Core API โ
โโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโค
โ KV โ Records โ Graph โ Vector โ
โโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโค
โ Transaction Layer โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ LRU Cache Layer โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ RocksDB Storage Backend โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- Storage Layer: RocksDB with column families for data isolation
- Caching Layer: Write-through LRU cache with RocksDB block cache
- Transaction Layer: Snapshot isolation with optimistic locking
- API Layer: Type-safe Rust APIs for all operations
See the Architecture Documentation for details.
Database Structure
OpenDB Database Folder
OpenDB uses a folder-based architecture with multiple files for high performance:
./my_database/ # Your database folder
โโโ OPENDB_INFO # OpenDB metadata (identifies this as OpenDB)
โโโ README.md # Database-specific documentation
โโโ .opendb_config.json # Database configuration
โโโ CURRENT # Points to current MANIFEST file
โโโ IDENTITY # Database UUID
โโโ LOCK # Prevents concurrent access
โโโ MANIFEST-* # Database metadata and file list
โโโ OPTIONS-* # RocksDB configuration
โโโ *.log # Write-Ahead Log (WAL) for durability
โโโ *.sst # Sorted String Tables (actual data)
Key Files:
OPENDB_INFO: OpenDB metadata explaining format and featuresREADME.md: Database-specific documentation and backup instructions.opendb_config.json: Machine-readable database configuration*.log: Write-Ahead Log ensures durability (changes written here first)*.sst: Sorted String Table files store the actual data (compressed)MANIFEST: Tracks which SST files are activeLOCK: Ensures only one process accesses the database at a time
Benefits of folder-based design:
- โ Higher write throughput: WAL allows fast sequential writes
- โ Better compression: Data is compressed in SST files
- โ Efficient compaction: Background merging of files
- โ Crash recovery: WAL enables reliable recovery
Important notes:
- โ ๏ธ Always backup the entire folder (not individual files)
- โ ๏ธ Do NOT manually edit files in the database folder
- โ ๏ธ Only one process can open a database at a time (enforced by LOCK file)
Check the OPENDB_INFO, README.md, and .opendb_config.json files in any database folder for detailed information.
Installation
Prerequisites
- Rust 1.70+: Install Rust
- RocksDB dependencies (handled automatically by cargo)
From crates.io
From source
Examples
OpenDB includes comprehensive examples:
# Basic quickstart
# AI agent memory system with colored output
# Graph relationship traversal
# Multimodal AI/LLM application (PDF, audio, video, text)
# Custom storage configuration patterns
All examples feature:
- โจ Colorful console output with emojis for better readability
- ๐ Detailed progress indicators showing what's happening
- ๐ก Best practices and production-ready patterns
- ๐ฏ Complete workflows from data ingestion to query
See the examples/ directory for more.
Documentation
- ๐ User Guide: Complete documentation
- ๐ API Reference: Detailed API docs
- ๐๏ธ Architecture: Design and internals
- โก Performance Tuning: Optimization guide
Performance
OpenDB delivers excellent performance across all operations:
Benchmarks
All benchmarks run on a single thread (no parallelism) to show baseline performance:
| Operation | Throughput | Latency (avg) | Description |
|---|---|---|---|
| KV Put | ~136K ops/sec | 7.36 ยตs | Write key-value pair to storage |
| KV Get | ~10.2M ops/sec | 97.8 ns | Read key-value pair (cached) |
| Memory Insert | ~39K ops/sec | 25.5 ยตs | Insert Memory record with embedding |
| Memory Get | ~4.7M ops/sec | 213 ns | Retrieve Memory record by ID |
| Vector Search (100) | ~22.7K ops/sec | 44.1 ยตs | k-NN search across 100 vectors (384-dim) |
| Vector Search (500) | ~5.1K ops/sec | 197.6 ยตs | k-NN search across 500 vectors (384-dim) |
| Vector Search (1000) | ~2.5K ops/sec | 400.2 ยตs | k-NN search across 1000 vectors (384-dim) |
| Graph Link | ~54K ops/sec | 18.5 ยตs | Create bidirectional edge |
| Graph Get Related | ~68.3K ops/sec | 14.6 ยตs | Retrieve outgoing edges |
| Transaction Commit | ~129K ops/sec | 7.75 ยตs | Commit 2-write transaction |
Notes:
- Vector search uses brute-force k-NN (linear scan) with euclidean distance
- All operations include full persistence to RocksDB (WAL + LSM writes)
- Benchmarks run with default RocksDB settings
- Memory operations include rkyv serialization/deserialization
- Graph operations maintain bidirectional indices
- โ ๏ธ Performance varies by system: These benchmarks were run on a specific hardware configuration. Your performance may differ based on your OS, platform, processor, RAM, and storage type (SSD vs HDD).
Reproduce benchmarks on your system:
Run the benchmarks using the benches/benchmark.rs file:
For detailed results with plots and statistical analysis:
The benchmark file (benches/benchmark.rs) includes comprehensive tests for:
- Key-value operations (put, get)
- Memory operations (insert, get)
- Vector search (100, 500, 1000 vectors)
- Graph operations (link, get_related)
- Transaction operations (commit)
Run benchmarks yourself:
Performance Characteristics
- KV Operations: Sub-microsecond reads with LRU cache, single-digit ยตs writes
- Vector Search: Sub-millisecond for datasets up to 1K vectors (384-dim)
- Graph Traversal: Constant-time relationship lookups via indices
- Transactions: Full ACID with minimal overhead (~7-8 ยตs commit time)
- Serialization: Zero-copy deserialization with rkyv for optimal performance
See Performance Guide for tuning.
Manual Installation
Download pre-built binaries from GitHub Releases for your platform:
Linux x86_64
# Download and extract
# System-wide installation (requires sudo)
# Or copy to your project
Linux ARM64 (aarch64)
macOS x86_64 (Intel)
macOS ARM64 (Apple Silicon)
Windows x86_64
# Download and extract
Invoke-WebRequest -Uri "https://github.com/muhammad-fiaz/opendb/releases/latest/download/opendb-windows-x86_64.zip" -OutFile "opendb-windows-x86_64.zip"
Expand-Archive -Path opendb-windows-x86_64.zip -DestinationPath .
# Copy to system PATH or your project directory
Copy-Item opendb.dll C:\Windows\System32\
# Or add to your project directory
Build Dependencies
If building from source or using the library, ensure you have:
- Clang and LLVM (required for RocksDB bindings)
- Linux:
sudo apt-get install clang llvm - macOS:
brew install llvm - Windows:
choco install llvm
- Linux:
For Alpine Linux (musl libc), use the bindgen-static feature:
[]
= false
= ["bindgen-static"]
For Windows /MT runtime, use the mt_static feature:
[]
= ["mt_static"]
Use Cases
- AI Agent Memory: Persistent memory for AI agents with semantic search
- Knowledge Graphs: Store entities and relationships with vector embeddings
- Semantic Search: Fast similarity search over document embeddings
- Graph Analytics: Relationship analysis and traversal
- Embedded Database: Lightweight, embedded storage for Rust applications
Changelog
See the GitHub Releases page for version history and changelog.
Contributing
Contributions are welcome! See CONTRIBUTING.md for guidelines.
- ๐ Bug Reports: Open an issue
- โจ Feature Requests: Suggest a feature
- ๐ Pull Requests: Submit a PR
License
Licensed under the Apache License, Version 2.0 (LICENSE or http://www.apache.org/licenses/LICENSE-2.0).
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be licensed under the Apache License, Version 2.0, without any additional terms or conditions.
Contact
- Author: Muhammad Fiaz
- Email: contact@muhammadfiaz.com
- GitHub: @muhammad-fiaz
- Repository: muhammad-fiaz/opendb
OpenDB - High-performance hybrid embedded database for Rust ๐ฆ