claw-core
Embedded local storage engine for ClawDB. It provides an async, SQLite-backed core optimized for agent memory workloads: low-latency reads, FTS5 search, transactional consistency, snapshots, and migration-driven schema evolution.
Why claw-core
- Local-first durability with SQLite WAL mode by default
- Async API built for tokio applications
- Full-text retrieval via SQLite FTS5 (
memories_fts) - Indexed tag lookup using normalized
memory_tags - Snapshot + restore support with checksum manifest
- Explicit transactions with deferred staged writes
- Built-in pagination primitives for large datasets
Installation
[]
= "0.1.1"
Optional encryption feature:
[]
= { = "0.1.1", = ["encryption"] }
Note: the encryption feature expects a SQLCipher-linked SQLite build.
Quick start
use *;
async
Core concepts
Memory records
Each MemoryRecord stores:
- UUID primary key
- textual content
- memory type (
Semantic,Episodic,Working, ...) - tags
- optional TTL
- timestamps (
created_at,updated_at)
Sessions and tool outputs
Session lifecycle is first-class (start_session, end_session, list_sessions) and
tool outputs are tied to sessions for traceability.
Transaction model
ClawTransaction stages writes first, then applies all staged operations on commit in
one SQLite transaction. This keeps memories, memories_fts, and memory_tags
consistent.
Search and retrieval
fts_search(query): FTS5 query across memory contentsearch_by_tag(tag): indexed join throughmemory_tagsget_memory(id): cache-aware retrieval path
Pagination
Use keyset pagination via ListOptions:
use ;
# async
Snapshots and restore
snapshot_create()performsPRAGMA wal_checkpoint(FULL)before copy- metadata includes path, timestamp, size, and BLAKE3 checksum
- manifest persisted at
<snapshot_dir>/manifest.json restore(path)validates SQLite magic bytes before replacement
Runtime stats
engine.stats() returns:
- total memory count
- rolling cache hit rate (last 1000 lookups)
- last snapshot timestamp (in-process)
- db and WAL file sizes
Configuration
use ;
let config = builder
.db_path
.max_connections
.cache_size_mb
.journal_mode
.snapshot_dir
.auto_migrate
.build
.expect;
Benchmarks
Included benchmark suites cover:
- FTS5 search at 1k/10k/100k corpus sizes
- tag index query latency
- cache hit vs miss read paths
- snapshot creation timing
- concurrent insert throughput (4 writers)
Run with:
Development
License
Licensed under MIT. See LICENSE.