1 stable release
| 1.1.11 | Nov 23, 2025 |
|---|
#1732 in Database interfaces
600KB
13K
SLoC
Hanzo DB - Multi-Backend Database Abstraction
A unified database abstraction layer for Hanzo Node that supports multiple backend databases, each optimized for different workloads.
Supported Backends
| Backend | Best For | Features |
|---|---|---|
| LanceDB | Vector Search, AI/ML | • Native vector operations • Multimodal storage • Columnar format • Fast similarity search |
| DuckDB | Analytics, OLAP | • In-process analytical database • SQL support • Columnar storage • Fast aggregations |
| PostgreSQL | Transactional, OLTP | • ACID compliance • Rich SQL features • Extensions (pgvector) • Battle-tested |
| Redis | Caching, Real-time | • In-memory storage • Pub/sub support • TTL/expiration • Extremely fast |
| SQLite | Embedded, Lightweight | • Zero-configuration • Single file • Serverless • Wide compatibility |
Usage
use hanzo_db::{connect, HanzoDbConfig, DatabaseBackend, WorkloadType};
// Automatically select backend based on workload
let config = HanzoDbConfig {
backend: DatabaseBackend::for_workload(WorkloadType::VectorSearch),
..Default::default()
};
// Or explicitly choose a backend
let config = HanzoDbConfig {
backend: DatabaseBackend::LanceDB,
path: Some("./data/vectors".into()),
..Default::default()
};
let db = connect(config).await?;
// Use unified interface regardless of backend
db.create_table("embeddings", schema).await?;
db.insert("embeddings", &records).await?;
let results = db.vector_search(query).await?;
Features
- Unified Interface: Same API across all backends
- Automatic Backend Selection: Choose optimal backend based on workload
- Migration Support: Move data between backends
- Connection Pooling: Efficient resource management
- Transaction Support: ACID guarantees where supported
- Vector Operations: Native support in LanceDB, extension support in PostgreSQL
Configuration
Environment Variables
# Select default backend
HANZO_DB_BACKEND=lancedb # lancedb, duckdb, postgresql, redis, sqlite
# Backend-specific configuration
HANZO_DB_PATH=./storage/hanzo-db
HANZO_DB_URL=postgresql://user:pass@localhost/hanzo
HANZO_REDIS_URL=redis://localhost:6379
Feature Flags
[dependencies]
hanzo_db = { version = "1.0", features = ["lancedb", "duckdb", "postgres"] }
Migration
Migrate from one backend to another:
# From SQLite to LanceDB
hanzo-migrate --from sqlite://old.db --to lancedb://./vectors
# From LanceDB to PostgreSQL
hanzo-migrate --from lancedb://./vectors --to postgresql://localhost/hanzo
Performance Characteristics
| Operation | LanceDB | DuckDB | PostgreSQL | Redis | SQLite |
|---|---|---|---|---|---|
| Vector Search | ⭐⭐⭐⭐⭐ | ⭐⭐ | ⭐⭐⭐ | ⭐ | ⭐ |
| Analytics | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐ | ⭐⭐ |
| Transactions | ⭐⭐⭐ | ⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐ | ⭐⭐⭐⭐ |
| Caching | ⭐⭐ | ⭐ | ⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ |
| Embedded | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐ | ⭐ | ⭐⭐⭐⭐⭐ |
License
Apache 2.0
Dependencies
~20–84MB
~1.5M SLoC