Skip to main content

plugmem_host/
lib.rs

1#![doc = include_str!("../README.md")]
2//! Native host layer for the plugmem engine: file-backed storage with
3//! exclusive locking, a thread-safe database handle with a maintenance
4//! policy, and embedding providers.
5//!
6//! This crate is the "point it at a file and go" Rust experience:
7//!
8//! ```no_run
9//! use plugmem_host::{Config, Database, RecallQuery, RememberInput};
10//!
11//! let (db, _report) = Database::open("agent.plugmem", Config::default())?;
12//! db.remember(RememberInput::text(1_784_000_000_000, "prefers tokio"))?;
13//! let out = db.recall(RecallQuery::text(1_784_000_100_000, "runtime?"))?;
14//! println!("{}", out.rendered);
15//! # Ok::<(), plugmem_host::HostError>(())
16//! ```
17//!
18//! Concurrency model: one local database has one owning process —
19//! a second open is refused with [`HostError::Locked`]; within the
20//! process, clone the [`Database`] handle across threads and agents;
21//! different files are fully independent. Embedding calls run outside
22//! the database lock.
23//!
24//! With the default `config` feature, the host also accepts the shared
25//! `config.toml` format through [`Settings::load`] and [`read_config`]. The
26//! `SETTINGS.md` file is the reference documentation for that format, not an
27//! input file. Disable the feature with `default-features = false` when a
28//! caller wants only programmatic [`Config`] construction.
29
30mod db;
31mod embedder;
32mod error;
33mod paths;
34mod readonly;
35#[cfg(feature = "config")]
36mod settings;
37#[cfg(feature = "config")]
38mod settings_help;
39mod storage;
40mod workspace;
41
42pub use db::{
43    DEFAULT_REEMBED_BATCH_SIZE, Database, DatabaseBuilder, ExportPage, ExportedFact, FactSnapshot,
44    RecoverReport,
45};
46pub use embedder::{
47    DEFAULT_EMBED_RETRY_FIRST, DEFAULT_EMBED_RETRY_MAX, DEFAULT_EMBED_TIMEOUT, EmbedErrorPolicy,
48    EmbedRetry, Embedded, EmbeddedBatch, Embedder, EmbedderGate, EmbedderState, NullEmbedder,
49    OpenAiCompatEmbedder, SharedEmbedder,
50};
51pub use error::HostError;
52pub use paths::{default_config_dir, default_config_path, default_data_dir, default_database_path};
53pub use readonly::{ReadOnlyDatabase, Scrub};
54#[cfg(feature = "config")]
55pub use settings::{Settings, SettingsError, WorkspaceSettings, read_config};
56#[cfg(feature = "config")]
57pub use settings_help::{SettingDoc, SettingScope, SettingWarning, SettingsHelp, settings_help};
58pub use storage::{FileScratch, FileStorage, FsyncPolicy};
59pub use workspace::{
60    ARCHIVED_TAG, DEFAULT_IDLE_TIMEOUT_MS, DEFAULT_MAX_OPEN, DbEntry, DbName, Description,
61    ENTRY_TAG, IfMissing, MAX_DB_NAME, MAX_OPEN_CEILING, NameProblem, Opener, ReindexReport,
62    SELF_ENTITY, Workspace, WorkspaceError, WorkspaceIssue, WorkspaceLayout, WorkspaceLease,
63    WorkspaceLimits,
64};
65
66// The engine types a host caller works with, re-exported so simple
67// embedders need only this crate.
68pub use plugmem_core::snapshot::{DEFAULT_SCRUB_BUDGET, ScrubProgress};
69pub use plugmem_core::{
70    Config, DEFAULT_TAG_PAGE_LIMIT, EdgeId, EntityId, Error, FactId, FactRecord,
71    GuardedRememberOutcome, LinkInput, MAX_TAG_PAGE_LIMIT, MaintainReport, MaintenanceMode,
72    MaintenanceOptions, OpenReport, RecallQuery, RecallResult, RecallScratch, RecalledEdge,
73    RecalledFact, ReembedReport, RememberInput, RememberOutcome, RemoveTagReport, ShardLayout,
74    Similar, SimilarReason, Stats, TagPage, TagQuery, TagSummary, UnlinkInput, VALID_TO_OPEN,
75    fact_flags,
76};
77pub use plugmem_core::{MemScratch, Scratch};