SynaDB
An AI-native embedded database.
An embedded, log-structured, columnar-mapped database engine written in Rust. Syna combines the embedded simplicity of SQLite, the columnar analytical speed of DuckDB, and the schema flexibility of MongoDB.
Features
- Append-only log structure - Fast sequential writes, immutable history
- Schema-free - Store heterogeneous data types without migrations
- AI/ML optimized - Extract time-series data as contiguous tensors for PyTorch/TensorFlow
- C-ABI interface - Use from Python, Node.js, C++, or any FFI-capable language
- Delta & LZ4 compression - Minimize storage for time-series data
- Crash recovery - Automatic index rebuild on open
- Thread-safe - Concurrent read/write access with mutex-protected writes
Installation
Building from Source
# Clone the repository
# Build release version
# Run tests
The compiled library will be at:
- Linux:
target/release/libsynadb.so - macOS:
target/release/libsynadb.dylib - Windows:
target/release/synadb.dll
Adding as a Dependency
[]
= "0.1.0"
Quick Start
Rust Usage
use ;
Python Usage (ctypes)
# Load the library
= # or .dylib/.dll
# Define function signatures
=
=
=
=
=
=
=
=
=
=
=
= None
=
=
# Usage
= b
# Open database
=
assert == 1, f
# Write float values
# Read latest value
=
=
# Get history as numpy-compatible array
=
=
# Convert to Python list (or use numpy.ctypeslib for zero-copy)
=
# Free the tensor memory
# Close database
C/C++ Usage
int
Compile with:
Data Types
Syna supports five atomic data types:
| Type | Rust | C/FFI | Description |
|---|---|---|---|
| Null | Atom::Null |
N/A | Absence of value |
| Float | Atom::Float(f64) |
syna_put_float |
64-bit floating point |
| Int | Atom::Int(i64) |
syna_put_int |
64-bit signed integer |
| Text | Atom::Text(String) |
syna_put_text |
UTF-8 string |
| Bytes | Atom::Bytes(Vec<u8>) |
syna_put_bytes |
Raw byte array |
Configuration
use ;
let config = DbConfig ;
let db = with_config?;
Error Codes (FFI)
| Code | Constant | Meaning |
|---|---|---|
| 1 | ERR_SUCCESS |
Operation successful |
| 0 | ERR_GENERIC |
Generic error |
| -1 | ERR_DB_NOT_FOUND |
Database not in registry |
| -2 | ERR_INVALID_PATH |
Invalid path or UTF-8 |
| -3 | ERR_IO |
I/O error |
| -4 | ERR_SERIALIZATION |
Serialization error |
| -5 | ERR_KEY_NOT_FOUND |
Key not found |
| -6 | ERR_TYPE_MISMATCH |
Type mismatch on read |
| -100 | ERR_INTERNAL_PANIC |
Internal panic |
Architecture
Syna uses an append-only log structure inspired by the "physics of time" principle:
┌─────────────────────────────────────────────────────────────┐
│ Entry 0 │
├──────────────┬──────────────────┬───────────────────────────┤
│ LogHeader │ Key (UTF-8) │ Value (bincode) │
│ (15 bytes) │ (key_len bytes) │ (val_len bytes) │
├──────────────┴──────────────────┴───────────────────────────┤
│ Entry 1 ... │
└─────────────────────────────────────────────────────────────┘
- Writes: Always append to end of file (sequential I/O)
- Reads: Use in-memory index for O(1) key lookup
- Recovery: Scan file on open to rebuild index
- Compaction: Rewrite file with only latest values
Contributing
See CONTRIBUTING.md for guidelines.
License
MIT License - see LICENSE for details.