qdb-rs - Quantum Database
A hybrid quantum-classical database combining traditional key-value storage with quantum state persistence, vector embeddings, and Grover-inspired O(√N) search.
Why QDB?
| Problem | QDB Solution |
|---|---|
| Storing quantum states is expensive | MPS compression: O(n χ²) instead of O(2ⁿ) |
| Classical DBs can't handle quantum data | Native QFT format with fidelity preservation |
| Vector search lacks quantum awareness | Fidelity distance metric for quantum embeddings |
| Space applications need fault tolerance | Golay [23,12,7] error correction + radiation hardening |
| Searching unstructured data is slow | Grover-inspired search: O(√N) complexity |
Key Features
🔮 Quantum State Storage
Store and retrieve quantum states with guaranteed fidelity using the .qft format:
let bell = bell_state?;
db.put_quantum?;
let loaded = db.get_quantum?;
assert!;
📊 Vector Store (Quantum-Optimized)
HNSW-based embedding storage with 6 distance metrics including quantum fidelity:
let mut store = with_dim;
store.put?;
let results = store.search; // O(log N) ANN search
⚡ Grover-Inspired Search
Quadratic speedup for unstructured queries:
let search = new?;
let results = search.search?; // O(√N) vs O(N) classical
🛡️ Fault-Tolerant Storage
- Golay [23,12,7] error correction (3-bit correction, 7-bit detection)
- Radiation hardening modes for space applications
- BLAKE3 checksums for integrity verification
All Features
- Quantum State Storage: Native
.qftformat with MPS compression - Vector Store: HNSW index, 6 distance metrics, namespace isolation
- Grover Search: O(√N) quantum-inspired search algorithm
- ACID Transactions: Entanglement-aware transaction groups
- Multiple Backends: Memory, disk, extensible trait
- Error Correction: Golay codes + radiation hardening
- Concurrent Access: Lock-free reads via DashMap
Installation
[]
= { = "0.1", = ["full"] }
# Required peer dependency
= "1.0"
# Optional: LogosQ integration
= { = "0.2", = true }
Feature Flags
| Feature | Description |
|---|---|
default |
Core functionality |
async |
Tokio-based async I/O |
logosq |
LogosQ MPS bridge methods |
radiation |
Radiation hardening modes |
full |
All features enabled |
Quick Start
use *;
Architecture
┌─────────────────────────────────────────────────────────────┐
│ QDB API Layer │
├─────────────────────────────────────────────────────────────┤
│ Key-Value API │ Document API │ Quantum State API │
├─────────────────────────────────────────────────────────────┤
│ Query Engine │
│ - Grover search (O(√N)) │
│ - Tensor contractions for joins │
│ - Variational optimization │
├─────────────────────────────────────────────────────────────┤
│ Storage Layer │
│ - QFT serialization (MPS tensors) │
│ - Golay error correction │
│ - Adaptive bond dimension │
├─────────────────────────────────────────────────────────────┤
│ Backend Abstraction │
│ Memory │ Disk │ Distributed │ Quantum Hardware │
└─────────────────────────────────────────────────────────────┘
Storage Backends
Memory Backend
Fast, in-memory storage using DashMap for concurrent access:
let db = QDBnew;
Disk Backend
Persistent storage with checksums and Golay protection:
let db = QDBnew;
Quantum Operations
Storing Quantum States
use QftBuilder;
// Create a custom quantum state
let state = new
.bond_dimension
.golay
.metadata
.build?;
db.put_quantum?;
Grover Search
use GroverSearch;
// Search for entries matching a predicate
let search = new;
let candidates = search.search?;
Transactions
Basic Transactions
let manager = new;
let tx = manager.begin;
tx.put?;
tx.put?;
tx.commit?;
Quantum Transactions with Entanglement
let tx = manager.begin;
let qtx = from_transaction;
// Mark keys as entangled - must be committed together
qtx.entangle?;
qtx.put?;
qtx.put?;
qtx.commit?; // Fails if not all entangled keys are written
Query API
use ;
let results = new
.key_prefix
.entry_type
.order_by
.limit
.execute?;
for entry in results.iter
Indexing
use ;
let manager = new;
// Hash index for exact lookups
manager.add_index?;
// B-tree index for range queries
manager.add_index?;
// Quantum index for Grover search
manager.add_index?;
Comparison with Classical Databases
| Aspect | Classical (RocksDB/PostgreSQL) | QDB |
|---|---|---|
| Storage | O(N) | O(n χ²) via MPS |
| Search | O(log N) indexed, O(N) scan | O(√N) Grover |
| Error Correction | Checksums | Golay [23,12,7] |
| Quantum States | Not supported | Native .qft format |
| Entanglement | N/A | Transaction groups |
LogosQ Integration
MPS Bridge Pattern
// Complete LogosQ → qft-rs → qdb-rs data flow
use ;
use UCCSD;
use ;
use *;
// 1. Run VQE in LogosQ
let hamiltonian = from_molecule;
let ansatz = UCCSDnew;
let solver = new;
let result = solver.run?;
// 2. Convert MPS state to QftFile
let mps = result.final_state;
let qft = new
.bond_dimension
.golay
.truncation_threshold
.metadata
.metadata
.metadata
.build?;
// Copy amplitudes from MPS
let amplitudes = mps.to_state_vector;
qft.set_amplitudes?;
// 3. Store in QDB
let db = QDBnew;
db.put_quantum?;
// 4. Later retrieval
let loaded = db.get_quantum?.unwrap;
println!;
Entanglement Transaction Semantics
Quantum transactions extend classical ACID with entanglement groups:
// Entangled keys represent correlated quantum states
// They MUST be committed atomically - partial writes fail
let qtx = from_transaction;
// Mark Alice and Bob's qubits as entangled
qtx.entangle?;
// Both must be written
qtx.put?;
qtx.put?;
// Commit succeeds only if ALL entangled keys are present
qtx.commit?;
Entanglement Representation: Entangled keys share logical correlation tracked in the transaction's write set. On commit, the transaction verifies all members of each entanglement group are present. This models quantum non-locality constraints where measuring one qubit affects its entangled partner.
Failure Model: If any entangled key is missing at commit time, the entire transaction rolls back. This prevents inconsistent states where only part of an entangled system is persisted.
Grover Search Implementation
The GroverSearch implements quantum-inspired amplitude amplification:
// Oracle marks target states, diffusion amplifies their probability
let search = new;
// Optimal iterations: π/4 * √N
let candidates = search.search?;
Complexity: O(√N) vs O(N) classical linear scan
Circuit Depth: ~O(√N) Grover iterations, each with oracle + diffusion
Measurement: Returns indices with highest amplitude after amplification
Vector Store
QDB includes a built-in vector store for embedding storage and similarity search:
use ;
// Create a vector store for 384-dim embeddings
let mut store = with_dim;
// Add documents with embeddings
store.put?;
// Similarity search
let query = new;
let results = store.search;
for result in results
// Filter by namespace
let physics_docs = store.search_namespace;
Distance Metrics
| Metric | Description | Use Case |
|---|---|---|
Cosine |
1 - cosine similarity | Text embeddings (default) |
Euclidean |
L2 distance | Image embeddings |
DotProduct |
Negative dot product | Normalized vectors |
Manhattan |
L1 distance | Sparse vectors |
HNSW Index
The vector index uses an HNSW-inspired algorithm for O(log N) approximate nearest neighbor search:
use ;
let config = VectorIndexConfig ;
let mut index = with_config;
Radiation Hardening (Space Applications)
use QdbConfig;
let config = QdbConfig ;
let db = QDBwith_config;
Benchmarks
| Operation | N=1000 | N=10000 | N=100000 |
|---|---|---|---|
| Put (classical) | 0.8ms | 8ms | 85ms |
| Get (classical) | 0.1ms | 0.1ms | 0.1ms |
| Put (4-qubit) | 1.2ms | 12ms | 125ms |
| Get (4-qubit) | 0.3ms | 0.3ms | 0.3ms |
| Grover search | 2ms | 6ms | 20ms |
| Linear scan | 1ms | 10ms | 100ms |
Benchmarks on Apple M2, MemoryBackend, χ=64
Run benchmarks: cargo bench -p qdb-rs
Examples
Documentation
- Entanglement Semantics - Formal specification of entanglement groups
- Radiation Hardening - SEU mitigation and space deployment guide
Roadmap
v0.2 (Q2 2026)
- Distributed sharding with 2PC for entanglement groups
- Async backend trait (
AsyncBackend) - Query planner with cost-based optimization
- Index::quantum with precomputed Grover oracles
v1.0 (Q4 2026)
- Production-ready stability
- Full LogosQ MPS bridge (
QftFile::from_mps,to_mps) - Quantum hardware backend via logosq-hardware-integrator
- Comprehensive test suite (>90% coverage)
v2.0 (2027)
- PEPS/MERA tensor network support
- Quantum memory backend (trapped ions, superconducting)
- Cross-database entanglement routing
- Quantum consensus for Byzantine fault tolerance
License
MIT OR Apache-2.0
References
- Grover, L. K. (1996). "A fast quantum mechanical algorithm for database search." Proceedings of STOC.
- Peruzzo, A., et al. (2014). "A variational eigenvalue solver on a photonic quantum processor." Nature Communications, 5, 4213.
- LogosQ Paper (2025). arXiv:2512.23183v2. "LogosQ: Compile-Time Safe Quantum Simulation in Rust."
- QFT Specification v1.2.0 - MACROHARD Quantum OS
Contributing
See CONTRIBUTING.md for guidelines.
Acknowledgments
- LogosQ team for MPS backend and variational optimization
- QFT specification contributors
- Redox-QCOS ecosystem developers