bkndb
An embedded, zero-daemon hybrid graph-relational-vector database engine with ACID transactions, written in Rust.
bkndb unifies relational tables (with secondary indexes and prefix matching), a property graph engine (with sub-millisecond graph traversal), full-text search (BM25), and vector similarity search (HNSW ANN) into a single, unified storage layer with atomic transactions and native single-file .bkndb container persistence.
Designed for AI agents, GraphRAG, code intelligence, local-first desktop/mobile applications, and embedded analytics.
Key Features
- Embedded & Zero-Daemon: Runs directly inside your application process (like SQLite/DuckDB). No server setup, no port configuration, zero network latency.
- Unified Hybrid ACID Transactions: Read and write relational rows and property graph nodes/edges in a single atomic transaction with snapshot isolation (
db.write_tx/db.read_tx). - High-Performance Native Storage (.bkndb): Single-file container powered by
redbas the default copy-on-write B-tree ACID engine, alongside an optional append-only LSM architecture with memory-mapped zero-copy reading (memmap2) and WAL crash durability. - Sub-Millisecond Graph Traversal: Built-in BFS shortest path, Dijkstra weighted shortest path, multi-hop radius traversal (blast radius), in-degree centrality (top hubs), and cascading node deletion.
- Integrated Full-Text & Vector Search: Native BM25 inverted index and HNSW (Hierarchical Navigable Small World) vector index for fast semantic similarity search in the same database.
- Relational Indexing & Hybrid Joins: Secondary indexing, fast prefix search, and zero-cost joining of graph node traversals with relational metadata tables.
- High-Volume Bulk Ingestion: Batch synchronization API (
SyncBatch) capable of ingesting 100,000+ nodes, edges, and rows in under a second. - Cross-Platform: Pure Rust core, with UniFFI mobile bindings (Android Kotlin AAR with 16KB page size compliance & iOS Swift XCFramework) and Python bindings (
pip install bkndb).
Performance Highlights
In real-world code intelligence workloads (call graph traversal & AST storage) comparing bkndb (native .bkndb LSM engine) against SQLite (WAL mode):
| Operation | bkndb (Native LSM) |
SQLite (WAL mode) | Speedup |
|---|---|---|---|
| BFS Shortest Path (Call Graph) | 81.7 µs | 2,912.0 µs | 35.6x faster |
| Blast Radius / Impact Traversal | 41.8 µs | 994.9 µs | 23.8x faster |
| Symbol Prefix Search | 120.6 µs | 180.7 µs | 1.50x faster |
| AST Batch Sync (10,000 items) | 123.4 ms | 133.2 ms | 1.08x faster |
| HNSW Vector Search (100k vectors, 128d) | ~5.1 ms | ~117.0 ms (Linear Scan) | 22.9x faster |
Installation
Add bkndb to your Cargo.toml:
[]
= "0.2"
Cargo Feature Flags
| Feature | Default | Description |
|---|---|---|
redb-backend |
Yes | Default robust single-file ACID storage backend powered by redb. |
mem-backend |
Yes | High-throughput in-memory storage engine. |
graph |
Yes | Property graph layer, traversal algorithms, and Cypher MATCH queries. |
relational-layer |
Yes | Relational tables, primary keys, secondary indices, and prefix queries. |
search |
Yes | Full-text search (BM25) and exact / HNSW vector similarity search. |
lsm-backend |
No | Optional append-only single-file LSM storage engine with zero-copy mmap. |
Example for a minimal in-memory graph-only build:
= { = "0.2", = false, = ["mem-backend", "graph"] }
Quick Start Guide
1. Opening a Database
use BknDb;
// Persistent single-file database (.bkndb)
let db = open?;
// Or in-memory database for fast testing or caching
let mem_db = in_memory;
2. Defining Schemas and Relational Tables
use ;
let schema = builder
.column
.column
.column
.column
.primary_key
.auto_increment
.index
.build?;
db.relational.create_table?;
3. Unified ACID Write Transactions
Mutate relational rows and property graph entities atomically in a single transaction:
use Properties;
use PropValue;
db.write_tx?;
4. Graph Traversals & Graph Algorithms
use ;
let g = db.graph;
// Outgoing neighbors
let colleagues = g.neighbors?;
println!;
// Shortest Path (BFS)
if let Some = g.find_shortest_path?
// Impact / Blast Radius Traversal
let impacted = g.traversal.start.incoming.max_depth.run?;
println!;
// Centrality (Top Hubs)
let hubs = g.top_hubs?;
for hub in hubs
// Recursive Cascading Node Deletion
let cleanup_stats = g.cascade_delete?;
println!;
5. Declarative Query Languages (SQL & MATCH)
SQL Execution
let res = db.relational.sql?;
for row in res.rows
Cypher MATCH Execution
let res = db.graph.query?;
for row in res.rows
6. Full-Text (BM25) and Vector Search (HNSW)
use ;
let mut rel = db.relational;
// Full-Text Search (BM25)
rel.create_fulltext_index?;
let text_hits = rel.search_text?;
for hit in text_hits
// HNSW Vector Indexing & Search
rel.create_vector_index?;
let query_vec = vec!;
let vec_hits = rel.search_vector?;
for hit in vec_hits
7. Zero-Cost Hybrid Joins
Join graph traversal results directly with relational table metadata in a single read transaction:
let nodes = vec!;
let joined = db.join_nodes_with_table?;
for item in joined
8. High-Performance Bulk Synchronization (SyncBatch)
Ingest hundreds of thousands of records in a single atomic transaction:
use ;
let mut batch = new;
let n0 = batch.add_node;
let n1 = batch.add_node;
batch.add_edge;
batch.add_row;
let result = db.sync_batch?;
println!;
9. Storage Maintenance & Operations
// Force SSTable compaction to reclaim dead space
db.compact?;
// Online hot backup
db.backup_to?;
// Verify checksums of all blocks
let report = db.verify_integrity?;
assert!;
// Inspect disk metrics
let stats = db.storage_stats?;
println!;
Detailed Documentation
For exhaustive API documentation, performance recipes, and advanced patterns, refer to:
- wiki-rust.md: Complete Rust user guide (1,400+ lines).
- wiki-py.md: Complete Python user guide.
License
Licensed under the Apache License, Version 2.0 (see LICENSE).