Expand description
Native host layer for the plugmem engine: file-backed storage with exclusive locking, a thread-safe database handle with a maintenance policy, and embedding providers.
This crate is the “point it at a file and go” Rust experience:
use plugmem_host::{Config, Database, RecallQuery, RememberInput};
let (db, _report) = Database::open("agent.plugmem", Config::default())?;
db.remember(RememberInput::text(1_784_000_000_000, "prefers tokio"))?;
let out = db.recall(RecallQuery::text(1_784_000_100_000, "runtime?"))?;
println!("{}", out.rendered);Concurrency model: one file has one owning process —
a second open is refused with HostError::Locked; within the
process, clone the Database handle across threads and agents;
different files are fully independent. Embedding calls run outside
the database lock.
With the default config feature, the host also accepts the shared
config.toml format through Settings::load and read_config. The
SETTINGS.md file is the reference documentation for that format, not an
input file. Disable the feature with default-features = false when a
caller wants only programmatic Config construction.
Modules§
- fact_
flags - Bit flags of
FactRecord::flags.
Structs§
- Config
- Full engine configuration with the defaults.
- Database
- A clonable, thread-safe handle to one database file. See the module docs for the concurrency model.
- Database
Builder - Tuning knobs of a
Database. Construct throughDatabase::builder. - Entity
Id - Identifier of an entity — a graph node created lazily on first mention.
- Exported
Fact - One exported fact — the human-readable, id-free shape
Database::exportdumps and an importer re-remembers. Internal ids andrecorded_atare the engine’s bookkeeping and are not preserved across a round-trip; the knowledge itself (text, subject name, tags, validity start) is. - FactId
- Identifier of a fact — the unit of memory.
- Fact
Record - The unit of memory: one fact (48-byte slot, Uniform arena).
- Fact
Snapshot - An owned view of one fact —
Memory::getreturns borrows that cannot cross the lock, so the database hands out copies. - File
Scratch - A host
Scratchover a temp file (milestone H): sequential appends go through a buffered writer;freezeflushes and memory-maps the file, so the staged pool is read (randomly and sequentially) straight from the map instead of RAM. Dropping it unmaps and deletes the temp file. - File
Storage - File-backed
Storageholding an advisory lock on its database. - Link
Input - Input of
link. - Maintain
Report - Report of a
maintainpass. - MemScratch
- In-memory
Scratch: a growable buffer that “freezes” to a borrow of itself. The reference implementation — it backs tests, and because it drives the streaming path with no files it is the vehicle for thedisk_first == in_memoryproperty test. It stages in RAM, so it does not save RAM; a hostScratchover a temp file is what bounds RAM in practice. - Null
Embedder - The no-op embedder: dimension 0, never called by the database (a structural-only memory).
- Open
AiCompat Embedder - An
/v1/embeddingsclient for any OpenAI-compatible server. - Open
Report - Report of an
open: what the journal replay found. - Read
Only Database - A read-only database handle backed by a memory-mapped snapshot
See the module docs.
Send + Sync— share it across threads behind a reference or anArc. - Recall
Query - A recall request.
Default-like construction viaRecallQuery::textplus field overrides. - Recall
Result - A recall response. Reusable: pass to
Memory::recall_intorepeatedly and the buffers are recycled. - Recall
Scratch - Reusable recall scratch — caller-owned, so
Memory::recallandMemory::recall_intotake&self: many readers can recall the same engine at once, each threading its own scratch (the host wraps one per thread). Carries every buffer a recall mutates — the query-side term/score vectors, the fusion map, and its own tokenizer and name-normalization buffer — so a recall never touches the engine’s write-side scratches. Reused across calls it upholds the zero-alloc invariant. - Recalled
Edge - One edge the graph source walked (: agents want the relations, not only the facts).
- Recalled
Fact - One recalled fact.
- Recover
Report - The outcome of a
Database::recoversalvage. - Remember
Input - Input of
rememberandrevise. - Remember
Outcome - Result of
remember/revise. - Scrub
- A resumable, byte-level container scrub over a memory-mapped snapshot
(— the ZFS-scrub model). Obtained from
ReadOnlyDatabase::scrub. - Scrub
Progress - Progress of an in-flight
ScrubCursorscan. - Setting
Doc - Documentation for one supported config.toml key.
- Settings
- Resolved runtime settings: the engine config, an optional embedder, and the
maintenance policy. The wrapper-specific knobs (
importbatch size, server workers) are read separately from the sameread_configtable. - Settings
Help - Runtime access to the complete config.toml help catalogue.
- Similar
- One similar-fact hint.
- Stats
- Engine size counters. Every field is an O(1) read; the
struct is
#[non_exhaustive]so later stages (database identity markers, HNSW state) can extend it without a breaking change.
Enums§
- Error
- Every way an engine call can fail.
- Fsync
Policy - When journal appends reach the disk.
- Host
Error - Every way the host layer can fail. Engine failures pass through as
HostError::Engine; everything filesystem- or network-shaped is typed here. - Setting
Scope - Which runtime surface owns a setting.
- Settings
Error - A configuration error: malformed TOML, a bad
[engine]value, or an[embedder]section missing a required field. Distinct fromHostError(which covers opening the database once settings are resolved). - Similar
Reason - Why a fact was flagged as similar.
Constants§
- DEFAULT_
SCRUB_ BUDGET - Default number of bytes a
ScrubCursorhashes pernext()slice Thescrubslice-size bench sweeps 64 KiB…64 MiB and finds throughput essentially flat (the scan is xxh3/memory-bandwidth-bound, not per-slice-overhead-bound), so the budget is a pacing quantum, not a throughput knob: 1 MiB is ~sub-millisecond per slice — fine-grained enough to pause, cancel or report progress smoothly, with negligible overhead. - VALID_
TO_ OPEN valid_tovalue of an open fact (“true now”).
Traits§
- Embedder
- Turns texts into embedding vectors. Batched by design — providers price and perform far better on batches.
- Scratch
- An append-only staging area: build it sequentially with
write, thenfreezeit into a readable byte view for random and sequential reads. Dropping it discards the storage.
Functions§
- default_
config_ dir - The platform’s conventional per-user config directory.
- default_
config_ path - The default config file path, when a platform user directory is available.
- default_
data_ dir - The platform’s conventional per-user data directory.
- default_
database_ path - The default persistent per-user database path.
- read_
config - Reads and parses
config.toml, orOk(None)if none applies. An explicitflagpath must exist (a read error is a usage error); otherwise$PLUGMEM_CONFIG, then the platform path fromcrate::default_config_path, are read only if present. Wrappers call this once, then pass the table toSettings::from_tableand also read their own keys (batch size, workers) from it. - settings_
help - Returns the shared settings catalogue used by host, CLI, MCP and NAPI.