Skip to main content

plugmem_host/
lib.rs

1//! Native host layer for the plugmem engine: file-backed storage with
2//! exclusive locking, a thread-safe database handle with a maintenance
3//! policy, and embedding providers.
4//!
5//! This crate is the "point it at a file and go" Rust experience:
6//!
7//! ```no_run
8//! use plugmem_host::{Config, Database, RecallQuery, RememberInput};
9//!
10//! let (db, _report) = Database::open("agent.plugmem", Config::default())?;
11//! db.remember(RememberInput::text(1_784_000_000_000, "prefers tokio"))?;
12//! let out = db.recall(RecallQuery::text(1_784_000_100_000, "runtime?"))?;
13//! println!("{}", out.rendered);
14//! # Ok::<(), plugmem_host::HostError>(())
15//! ```
16//!
17//! Concurrency model: one file has one owning process —
18//! a second open is refused with [`HostError::Locked`]; within the
19//! process, clone the [`Database`] handle across threads and agents;
20//! different files are fully independent. Embedding calls run outside
21//! the database lock.
22
23mod db;
24mod embedder;
25mod error;
26mod readonly;
27#[cfg(feature = "config")]
28mod settings;
29mod storage;
30
31pub use db::{Database, DatabaseBuilder, ExportedFact, FactSnapshot, RecoverReport};
32pub use embedder::{Embedder, NullEmbedder, OpenAiCompatEmbedder};
33pub use error::HostError;
34pub use readonly::{ReadOnlyDatabase, Scrub};
35#[cfg(feature = "config")]
36pub use settings::{Settings, SettingsError, read_config};
37pub use storage::{FileScratch, FileStorage, FsyncPolicy};
38
39// The engine types a host caller works with, re-exported so simple
40// embedders need only this crate.
41pub use plugmem_core::snapshot::{DEFAULT_SCRUB_BUDGET, ScrubProgress};
42pub use plugmem_core::{
43    Config, EntityId, Error, FactId, FactRecord, LinkInput, MaintainReport, OpenReport,
44    RecallQuery, RecallResult, RecallScratch, RecalledEdge, RecalledFact, RememberInput,
45    RememberOutcome, Similar, SimilarReason, Stats, VALID_TO_OPEN, fact_flags,
46};
47pub use plugmem_core::{MemScratch, Scratch};