klieo_memory_sqlite/lib.rs
1#![deny(missing_docs)]
2#![deny(rust_2018_idioms)]
3
4//! SQLite-backed implementations of the three memory traits in
5//! [`klieo_core::memory`].
6//!
7//! `MemorySqlite::new` opens a SQLite file (or `:memory:` string),
8//! runs migrations for all three trait tables, and returns three
9//! `Arc<dyn …>` handles ready to drop into
10//! [`klieo_core::AgentContext`].
11//!
12//! # Example
13//!
14//! ```no_run
15//! use klieo_memory_sqlite::{MemorySqlite, DummyEmbedder};
16//! use std::sync::Arc;
17//!
18//! async fn example() {
19//! let mem = MemorySqlite::new(":memory:", Arc::new(DummyEmbedder)).await.unwrap();
20//! // mem.short_term, mem.long_term, mem.episodic are
21//! // Arc<dyn …> handles ready for AgentContext.
22//! let _ = mem;
23//! }
24//! ```
25//!
26//! # Features
27//!
28//! - **Default** — three SQLite-backed memory traits + `Embedder`
29//! trait with `DummyEmbedder` (zero-vector). Linear-scan recall.
30//! - **`fastembed`** — adds `FastEmbedEmbedder` (real CPU embeddings
31//! via ONNX runtime). Heavy first compile; model auto-downloads
32//! to OS cache dir on first call.
33//! - **`sqlite-vec`** — adds a vec0 virtual-table index on
34//! `long_term_facts_vec`; `LongTermMemory::recall` uses k-NN MATCH
35//! instead of linear scan.
36//! - **`test-utils`** — exposes `FakeEmbedder` for downstream test
37//! deps.
38//!
39//! # Limitations
40//!
41//! - **Sync SQLite under blocking pool.** All trait methods spawn
42//! `tokio::task::spawn_blocking` so they don't stall the async
43//! runtime; throughput is bounded by the blocking-pool size.
44
45pub(crate) mod connection;
46
47pub mod embedder;
48pub use embedder::{DummyEmbedder, Embedder};
49
50#[cfg(any(test, feature = "test-utils"))]
51pub use embedder::FakeEmbedder;
52
53pub mod short_term;
54pub use short_term::SqliteShortTerm;
55
56pub mod episodic;
57pub use episodic::SqliteEpisodic;
58
59pub mod long_term;
60pub use long_term::SqliteLongTerm;
61
62pub mod factory;
63pub use factory::MemorySqlite;
64
65#[cfg(feature = "fastembed")]
66pub mod fastembed;
67#[cfg(feature = "fastembed")]
68pub use fastembed::{FastEmbedEmbedder, DEFAULT_DIM, DEFAULT_MODEL};