| Crates.io | opendb |
| lib.rs | opendb |
| version | 0.0.0 |
| created_at | 2025-10-28 15:42:53.194131+00 |
| updated_at | 2025-10-28 15:42:53.194131+00 |
| description | A high-performance hybrid embedded database in pure Rust with KV, records, graph, and vector support |
| homepage | https://muhammad-fiaz.github.io/OpenDB |
| repository | https://github.com/muhammad-fiaz/OpenDB |
| max_upload_size | |
| id | 1904988 |
| size | 345,512 |
OpenDB is a high-performance, pure Rust hybrid embedded database combining:
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.
Option 1: Using Cargo (Recommended)
Add OpenDB to your Cargo.toml:
[dependencies]
opendb = "0.1"
Or use cargo-add:
cargo add opendb
Option 2: Pre-built Binaries
Download platform-specific builds from GitHub Releases:
opendb-linux-x86_64.tar.gzopendb-linux-aarch64.tar.gzopendb-macos-x86_64.tar.gzopendb-macos-aarch64.tar.gzopendb-windows-x86_64.zipSee the Manual Installation section below for detailed instructions.
Option 3: Build from Source
git clone https://github.com/muhammad-fiaz/opendb.git
cd opendb
cargo build --release --all-features
Build Requirements:
sudo apt-get install clang llvmbrew install llvmchoco install llvmuse opendb::{OpenDB, Memory};
use uuid::Uuid;
// Open database (creates a folder at ./data with multiple files)
let db = OpenDB::open("./data")?;
// Store a memory
let memory = Memory {
id: Uuid::new_v4().to_string(),
content: "Hello, OpenDB!".to_string(),
embedding: vec![0.1, 0.2, 0.3], // 384-dim in production
importance: 0.8,
metadata: serde_json::json!({"type": "greeting"}),
created_at: chrono::Utc::now(),
};
db.insert_memory(&memory)?;
// Retrieve by ID
let retrieved = db.get_memory(&memory.id)?;
// Search by similarity
let query_embedding = vec![0.15, 0.25, 0.35];
let similar = db.search_similar(&query_embedding, 10)?;
// Create relationships
db.link_memories(&memory.id, &other_id, "relates_to")?;
let related = db.get_related(&memory.id)?;
// Simple KV operations
db.put(b"user:1", b"Alice")?;
let value = db.get(b"user:1")?;
// Prefix scanning
for (key, value) in db.scan_prefix(b"user:")? {
println!("{:?}: {:?}", key, value);
}
// Begin transaction
let txn = db.begin_transaction()?;
// Transactional operations
txn.put(b"balance", b"1000")?;
txn.put(b"updated_at", current_time.as_bytes())?;
// Commit atomically
db.commit_transaction(txn)?;
OpenDB supports flexible configuration including custom storage locations, cache sizes, and vector dimensions:
use opendb::{OpenDB, OpenDBOptions};
// Customize all settings with method chaining
let options = OpenDBOptions::new()
.with_storage_path("./my_custom_db") // Custom storage location
.with_kv_cache_size(5000) // Larger KV cache
.with_record_cache_size(3000) // Larger record cache
.dimension(768); // Larger embeddings (e.g., OpenAI)
let db = OpenDB::open_with_options("./data", 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 = std::env::var("OPENDB_PATH")
.unwrap_or_else(|_| "./data/prod_db".to_string());
let prod_options = OpenDBOptions::with_dimension(768)
.with_kv_cache_size(10000)
.with_record_cache_size(5000);
let db = OpenDB::open_with_options(&db_path, prod_options)?;
// Multi-tenant pattern
for tenant_id in &["tenant_a", "tenant_b", "tenant_c"] {
let tenant_path = format!("./data/tenants/{}", tenant_id);
let db = OpenDB::open(&tenant_path)?;
// Each tenant has isolated database
}
See the custom_storage example for comprehensive configuration patterns.
Run it with:
cargo run --example custom_storage
OpenDB provides built-in support for multimodal file processing, perfect for AI agents, RAG systems, and document Q&A:
use opendb::{OpenDB, MultimodalDocument, DocumentChunk, FileType};
let db = OpenDB::open("./ai_agent")?;
// Process a PDF document
let mut pdf_doc = MultimodalDocument::new(
"research_001",
"paper.pdf",
FileType::Pdf,
1024 * 500, // 500 KB
"Extracted text from PDF...",
generate_embedding("paper content"), // Use sentence-transformers
)
.with_metadata("author", "Dr. Smith")
.with_metadata("pages", "15");
// Add chunks for large documents
pdf_doc.add_chunk(DocumentChunk::new(
"chunk_0",
"Introduction section...",
generate_embedding("introduction"),
0,
1000,
));
// Supports: PDF, DOCX, TXT, MP3, MP4, WAV, JPG, PNG, and more
let file_type = FileType::from_extension("mp3");
println!("{}", file_type.description()); // "Audio file"
See the multimodal_agent example for a complete demo of:
Run it with:
cargo run --example multimodal_agent
OpenDB is built with a modular architecture:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ OpenDB Core API โ
โโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโค
โ KV โ Records โ Graph โ Vector โ
โโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโค
โ Transaction Layer โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ LRU Cache Layer โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ RocksDB Storage Backend โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
See the Architecture Documentation for details.
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 timeBenefits of folder-based design:
Important notes:
Check the OPENDB_INFO, README.md, and .opendb_config.json files in any database folder for detailed information.
cargo add opendb
git clone https://github.com/muhammad-fiaz/OpenDB.git
cd OpenDB
cargo build --release
OpenDB includes comprehensive examples:
# Basic quickstart
cargo run --example quickstart
# AI agent memory system with colored output
cargo run --example memory_agent
# Graph relationship traversal
cargo run --example graph_relations
# Multimodal AI/LLM application (PDF, audio, video, text)
cargo run --example multimodal_agent
# Custom storage configuration patterns
cargo run --example custom_storage
All examples feature:
See the examples/ directory for more.
OpenDB delivers excellent performance across all operations:
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:
Reproduce benchmarks on your system:
Run the benchmarks using the benches/benchmark.rs file:
cargo bench --bench benchmark
For detailed results with plots and statistical analysis:
cargo install cargo-criterion
cargo criterion --bench benchmark
The benchmark file (benches/benchmark.rs) includes comprehensive tests for:
Run benchmarks yourself:
cargo bench --bench benchmark
See Performance Guide for tuning.
Download pre-built binaries from GitHub Releases for your platform:
# Download and extract
wget https://github.com/muhammad-fiaz/opendb/releases/latest/download/opendb-linux-x86_64.tar.gz
tar -xzf opendb-linux-x86_64.tar.gz
# System-wide installation (requires sudo)
sudo cp libopendb.so /usr/local/lib/
sudo ldconfig
# Or copy to your project
cp libopendb.* /path/to/your/project/lib/
wget https://github.com/muhammad-fiaz/opendb/releases/latest/download/opendb-linux-aarch64.tar.gz
tar -xzf opendb-linux-aarch64.tar.gz
sudo cp libopendb.so /usr/local/lib/
sudo ldconfig
curl -L https://github.com/muhammad-fiaz/opendb/releases/latest/download/opendb-macos-x86_64.tar.gz -o opendb-macos-x86_64.tar.gz
tar -xzf opendb-macos-x86_64.tar.gz
sudo cp libopendb.dylib /usr/local/lib/
curl -L https://github.com/muhammad-fiaz/opendb/releases/latest/download/opendb-macos-aarch64.tar.gz -o opendb-macos-aarch64.tar.gz
tar -xzf opendb-macos-aarch64.tar.gz
sudo cp libopendb.dylib /usr/local/lib/
# 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
If building from source or using the library, ensure you have:
sudo apt-get install clang llvmbrew install llvmchoco install llvmFor Alpine Linux (musl libc), use the bindgen-static feature:
[dependencies.opendb]
default-features = false
features = ["bindgen-static"]
For Windows /MT runtime, use the mt_static feature:
[dependencies.opendb]
features = ["mt_static"]
See the GitHub Releases page for version history and changelog.
Contributions are welcome! See CONTRIBUTING.md for guidelines.
Licensed under the Apache License, Version 2.0 (LICENSE or http://www.apache.org/licenses/LICENSE-2.0).
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.
OpenDB - High-performance hybrid embedded database for Rust ๐ฆ