pub struct SharedMnemo { /* private fields */ }Expand description
A brain opened in shared mode (12.4): see Mnemo::open_shared.
Every call goes through SharedMnemo::read or SharedMnemo::write,
which give the closure the handle for one window on the file:
let mut brain = Mnemo::open_shared("team.mnemo", "passphrase", SharedOptions::default())?;
let id = brain.write(|db| db.remember(Memory::new("we ship on Fridays", MemoryType::Semantic, vec![0.1, 0.2])))?;
let hits = brain.read(|db| db.recall(&RecallRequest::new(vec![0.1, 0.2]).top_k(5)))?;- A read runs under the shared lock, on a read-only handle. A
recall’s or a cache hit’s access statistics are kept and applied with
this handle’s next write; they’re dropped at
SharedMnemo::close. - A write runs under the exclusive lock and commits before the
window ends. If it fails before the commit point, nothing was stored,
for a closure that doesn’t commit by itself. A closure that does (it
calls
flush, or a method that commits, such ascommit_deltasorrestore_to) and then fails getsMnemoError::MaybeStored, saying part of the window is in the file. If the window’s own commit fails after its commit point, the handle finishes the commit itself and returnsOk, or returnsMnemoError::MaybeStored. If the file was renamed away during the commit,MnemoError::ReplacedDuringWrite. Keep to one engine call per window where you can. - Access statistics a failed write window applied are dropped when its commit fails; they’re statistics, and the next hits count again.
- Settings that act on the whole file (snapshot retention, cache
budgets, the cache flush policy, turn compression) are refused in
v0.14 with
MnemoError::Unsupported, and so isrekeyinside a closure (useSharedMnemo::rekey, which also updates the secret the handle keeps). The page cache’s size, the vector cache budget and the embedder (however it was set) are kept across reloads. - A cancel (
SharedMnemo::set_cancel) reaches only a call that is waiting for a lock; once a call holds the lock it runs to its end.
Implementations§
Sourcepub fn read<R>(&mut self, f: impl FnOnce(&mut Mnemo) -> Result<R>) -> Result<R>
pub fn read<R>(&mut self, f: impl FnOnce(&mut Mnemo) -> Result<R>) -> Result<R>
Run f on the handle under the file’s shared lock, after catching up
with any other process’s commits. The handle is read-only inside;
recall’s default access tracking works and is applied with this
handle’s next write.
Sourcepub fn write<R>(&mut self, f: impl FnOnce(&mut Mnemo) -> Result<R>) -> Result<R>
pub fn write<R>(&mut self, f: impl FnOnce(&mut Mnemo) -> Result<R>) -> Result<R>
Run f on the handle under the file’s exclusive lock, after catching
up, and commit before the lock is released. See SharedMnemo for
what each failure means.
A closure that commits part of its work itself and then fails, or
then changes a setting, gets MnemoError::MaybeStored: the earlier
commit is in the file.
13a: the author stamped as _mnemo.author on each new record (as
Mnemo::set_author), kept across reloads. Writes nothing.
Sourcepub fn hold_presence(&mut self) -> Result<()>
pub fn hold_presence(&mut self) -> Result<()>
13a (13.3): hold this handle’s author’s presence lock for the
handle’s life, in the sidecar directory, so Mnemo::who sees the
agent as alive and its claims may lapse early once its process is
gone. Only a long-lived process should (the MCP server); a hook or a
CLI call never does. It never touches the brain’s own lock. Needs an
author (SharedMnemo::set_author) and a usable sidecar directory.
Sourcepub fn set_embedder<E: Embedder + 'static>(&mut self, embedder: E) -> Result<()>
pub fn set_embedder<E: Embedder + 'static>(&mut self, embedder: E) -> Result<()>
Attach an embedder (as Mnemo::set_embedder). It’s kept across
reloads. When the file already records this embedder’s identity,
this is a read window and writes nothing; otherwise the identity is
recorded in a write window.
Sourcepub fn rekey(&mut self, new_passphrase: &str, kdf: KdfParams) -> Result<()>
pub fn rekey(&mut self, new_passphrase: &str, kdf: KdfParams) -> Result<()>
Change the passphrase (as Mnemo::rekey, in a write window), and
replace the secret the handle keeps once the new one is in force, so
the handle can still follow a compaction or recover the file
afterwards. An error leaves the old secret in force and kept, unless
it says the file may open with either.
Sourcepub fn rekey_with_key(&mut self, new_key: &[u8; 32]) -> Result<()>
pub fn rekey_with_key(&mut self, new_key: &[u8; 32]) -> Result<()>
SharedMnemo::rekey to a raw 256-bit key (as
Mnemo::rekey_with_key).
Sourcepub fn rekey_cleanup_error(&self) -> Option<&str>
pub fn rekey_cleanup_error(&self) -> Option<&str>
After a successful SharedMnemo::rekey, what couldn’t be scrubbed
of the old key wrap (see Mnemo::rekey_cleanup_error).
Sourcepub fn set_cancel(&mut self, token: Option<CancelToken>)
pub fn set_cancel(&mut self, token: Option<CancelToken>)
Give the handle a new cancel token for its later calls, or none
(RB-007.1). A cancelled token stays cancelled, so after a cancel the
handle needs a new one (or None) to wait for a lock again. A cancel
reaches only a call that is waiting for a lock.
Sourcepub fn embedder_arc(&self) -> Option<Arc<dyn Embedder>>
pub fn embedder_arc(&self) -> Option<Arc<dyn Embedder>>
The embedder attached to the handle, if any (shared, so a binding can
embed outside a window and then call SharedMnemo::write).
Sourcepub fn notices(&self) -> &[String]
pub fn notices(&self) -> &[String]
The warnings to show once: a sidecar directory that can’t be used, a synced folder, an allowed network filesystem.
Sourcepub fn options(&self) -> &SharedOptions
pub fn options(&self) -> &SharedOptions
The handle’s options: those it was opened with, and the cancel token
SharedMnemo::set_cancel gave it last.