claw-core 0.1.0

Embedded local database engine for ClawDB โ€” an agent-native cognitive database
Documentation

claw-core

Embedded local database engine for ClawDB โ€” an agent-native cognitive database.

Crates.io docs.rs CI License: Apache-2.0

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

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

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

Operation Target
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.

  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.