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.
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. - 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. - 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”).