# claw-core
> Embedded local database engine for **ClawDB** โ an agent-native cognitive database.
[](https://crates.io/crates/claw-core)
[](https://docs.rs/claw-core)
[](https://github.com/Claw-DB/claw-core/actions/workflows/ci.yml)
[](LICENSE)
## Features
- ๐ **Local-first** โ all data stays on device; no network dependency
- ๐ **WAL journaling** โ SQLite Write-Ahead Logging for high-concurrency reads
- โก **Async Rust** โ fully async via `tokio` + `sqlx`
- ๐ง **LRU cache** โ configurable in-memory LRU cache reduces DB round-trips
- ๐ **FTS5 search** โ full-text search over memory content using SQLite FTS5
- ๐ธ **Snapshot/restore** โ point-in-time database snapshots
- ๐ **Migration system** โ embedded, versioned SQL migrations via `sqlx::migrate!`
- ๐ **ACID transactions** โ explicit commit/rollback via `ClawTransaction`
## Quick start
```rust
use claw_core::prelude::*;
#[tokio::main]
async fn main() -> claw_core::ClawResult<()> {
// Open (or create) the database with default settings.
let engine = ClawEngine::open_default().await?;
// Insert a memory record.
let record = MemoryRecord::new(
"The capital of France is Paris",
MemoryType::Semantic,
vec!["geography".to_string()],
None, // no TTL
);
let id = engine.insert_memory(&record).await?;
// Full-text search.
let hits = engine.fts_search("France").await?;
println!("{} result(s) found", hits.len());
// Retrieve by ID (cache-aware).
let fetched = engine.get_memory(id).await?;
assert_eq!(fetched.content, "The capital of France is Paris");
engine.close().await;
Ok(())
}
```
## ClawConfig customization
```rust
use claw_core::{ClawConfig, JournalMode};
let config = ClawConfig::builder()
.db_path("/var/data/agent/claw.db")
.max_connections(5)
.cache_size_mb(128)
.journal_mode(JournalMode::WAL)
.snapshot_dir("/var/data/agent/snapshots")
.auto_migrate(true)
.build()
.expect("valid config");
```
## Architecture
```
Caller
โ
โผ
ClawEngine
โโโ LRU Cache (tokio::sync::Mutex<ClawCache>)
โ โโโ MemoryRecord entries (in-memory)
โโโ SqlitePool (sqlx)
โโโ SQLite file (WAL mode)
โโโ memories (+ memories_fts FTS5)
โโโ sessions
โโโ active_memory
โโโ session_state
โโโ tool_output
โโโ context
```
## Performance characteristics
| Cache hit read latency | < 100 ยตs |
| Insert throughput (NVMe) | > 10,000 records/s |
| FTS5 search (10k records) | < 10 ms |
| Tag search (10k records) | < 5 ms |
| WAL checkpoint | < 1 ms (passive) |
> Benchmarks: `cargo bench` (requires `criterion` in dev-dependencies)
## Contributing
Contributions are welcome! Please open an issue or pull request on
[GitHub](https://github.com/Claw-DB/claw-core).
1. Fork the repository
2. Create a feature branch (`git checkout -b feat/my-feature`)
3. Run tests: `cargo test --all-features`
4. Run lints: `cargo clippy -- -D warnings && cargo fmt --check`
5. Submit a pull request
## License
Licensed under the [Apache-2.0](LICENSE) license.