# klieo-memory-sqlite

SQLite-backed implementations of klieo-core's memory traits.

Part of the [klieo](https://crates.io/crates/klieo) Rust agent framework.

## Features

- `ShortTermMemory`, `LongTermMemory`, and `EpisodicMemory` on SQLite
- Optional `fastembed` feature for local embedding + `sqlite-vec` for vector recall
- Zero external services required — ideal for local-first deployments

## Cargo features

| Feature | Default | Purpose |
|---|---|---|
| `fastembed` | off | Pulls the `fastembed` ONNX runtime so `MemorySqlite::open_with_embedder` can take a real local embedder instead of `DummyEmbedder`. |
| `sqlite-vec` | off | Loads the `sqlite-vec` extension for fast k-NN recall on the long-term store. |
| `test-utils` | off | Re-exports `FakeEmbedder` from `klieo-embed-common` for downstream test harnesses. |

## Quickstart

```toml
[dependencies]
klieo-memory-sqlite = "2"
```

```rust
use klieo_memory_sqlite::MemorySqlite;

# async fn run() -> Result<(), Box<dyn std::error::Error>> {
// Persistent file (recommended for dev):
let memory = MemorySqlite::open("agent.db").await?;

// In-memory (tests, CI):
let memory = MemorySqlite::open(":memory:").await?;
# let _ = memory;
# Ok(()) }
```

`MemorySqlite::open(path)` bakes in `DummyEmbedder` (zero-vector,
FIFO recall) — paste-and-run with no extra dependency. The returned
`MemorySqlite` exposes `short_term`, `long_term`, `episodic` as
`Arc<dyn …>` ready to drop into [`klieo_core::AgentContext`] or into
`klieo::App` via the `.sqlite()` shortcut.

## Advanced wiring — custom embedder

```rust
use klieo_memory_sqlite::{MemorySqlite, DummyEmbedder};
use std::sync::Arc;

# async fn run() -> Result<(), Box<dyn std::error::Error>> {
// Swap DummyEmbedder for a real one (enable `fastembed` feature for
// `FastEmbedEmbedder`, or implement the `Embedder` trait yourself):
let memory = MemorySqlite::new("agent.db", Arc::new(DummyEmbedder)).await?;
# let _ = memory;
# Ok(()) }
```

Enable real vector recall:

```toml
[dependencies]
klieo-memory-sqlite = { version = "2", features = ["fastembed", "sqlite-vec"] }
```

## Status

`2.x` — stable. SemVer minor bumps are additive; majors only on
trait-shape changes. See [`docs/SEMVER.md`](https://github.com/mohrimic/klieo/blob/main/docs/SEMVER.md).

## License

MIT — see [`LICENSE`](https://github.com/mohrimic/klieo/blob/main/LICENSE).
