mnemo-engine 0.13.2__tar.gz → 0.15.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/PKG-INFO +52 -9
  2. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/README.md +51 -8
  3. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/Cargo.lock +1612 -121
  4. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/Cargo.toml +98 -10
  5. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/README.md +313 -12
  6. mnemo_engine-0.15.0/mnemo/build.rs +32 -0
  7. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/deny.toml +27 -1
  8. mnemo_engine-0.15.0/mnemo/examples/candle_hard.rs +206 -0
  9. mnemo_engine-0.15.0/mnemo/examples/shared_bench.rs +595 -0
  10. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/examples/thread_profile.rs +1 -0
  11. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/bin/mnemo/inspect.rs +26 -35
  12. mnemo_engine-0.15.0/mnemo/src/bin/mnemo/mcp_install.rs +712 -0
  13. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/bin/mnemo.rs +1435 -262
  14. mnemo_engine-0.15.0/mnemo/src/builtin.rs +710 -0
  15. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/crypto.rs +63 -0
  16. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/embed.rs +129 -14
  17. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/embed_cmd.rs +46 -4
  18. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/error.rs +113 -10
  19. mnemo_engine-0.15.0/mnemo/src/ident.rs +204 -0
  20. mnemo_engine-0.15.0/mnemo/src/keys/display.rs +132 -0
  21. mnemo_engine-0.15.0/mnemo/src/keys/mod.rs +994 -0
  22. mnemo_engine-0.15.0/mnemo/src/keys/os_store.rs +120 -0
  23. mnemo_engine-0.15.0/mnemo/src/keys/recovery.rs +259 -0
  24. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/lib.rs +263 -5
  25. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/mcp.rs +572 -38
  26. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/memory.rs +1 -1
  27. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/pager.rs +101 -19
  28. mnemo_engine-0.15.0/mnemo/src/shared/call.rs +190 -0
  29. mnemo_engine-0.15.0/mnemo/src/shared/fscheck.rs +172 -0
  30. mnemo_engine-0.15.0/mnemo/src/shared/lock.rs +665 -0
  31. mnemo_engine-0.15.0/mnemo/src/shared/mod.rs +28 -0
  32. mnemo_engine-0.15.0/mnemo/src/shared/sidecar.rs +370 -0
  33. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/store/cache_api.rs +8 -0
  34. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/store/crud.rs +45 -15
  35. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/store/flush.rs +16 -1
  36. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/store/hooks.rs +64 -0
  37. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/store/keyed.rs +158 -0
  38. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/store/load.rs +278 -6
  39. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/store/maintenance.rs +615 -59
  40. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/store/mod.rs +142 -17
  41. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/store/open.rs +363 -53
  42. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/store/recall.rs +43 -6
  43. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/store/records.rs +76 -4
  44. mnemo_engine-0.15.0/mnemo/src/store/shared.rs +755 -0
  45. mnemo_engine-0.15.0/mnemo/src/text.rs +597 -0
  46. mnemo_engine-0.15.0/mnemo-python/Cargo.lock +2920 -0
  47. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo-python/Cargo.toml +13 -2
  48. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo-python/README.md +51 -8
  49. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo-python/src/lib.rs +865 -223
  50. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo-python/test_mnemo.py +533 -0
  51. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/pyproject.toml +1 -1
  52. mnemo_engine-0.13.2/mnemo/src/text.rs +0 -268
  53. mnemo_engine-0.13.2/mnemo-python/Cargo.lock +0 -1203
  54. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/.gitignore +0 -0
  55. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/benches/corpus.rs +0 -0
  56. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/examples/ann_defaults_v0_6_0.rs +0 -0
  57. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/examples/ann_diagnose.rs +0 -0
  58. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/examples/ann_recall_grid.rs +0 -0
  59. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/examples/ann_recall_grid_v2.rs +0 -0
  60. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/examples/embedder_server.py +0 -0
  61. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/examples/file_size_breakdown.rs +0 -0
  62. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/examples/open_rss.rs +0 -0
  63. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/examples/quickstart.rs +0 -0
  64. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/examples/ranking_v2.rs +0 -0
  65. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/examples/session.rs +0 -0
  66. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/bin/mnemo/export.rs +0 -0
  67. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/bin/mnemo/inspect.html +0 -0
  68. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/cache.rs +0 -0
  69. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/format.rs +0 -0
  70. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/freelist.rs +0 -0
  71. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/index.rs +0 -0
  72. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/keyslot.rs +0 -0
  73. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/result_cache.rs +0 -0
  74. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/session.rs +0 -0
  75. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/store/ann.rs +0 -0
  76. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/store/continuation.rs +0 -0
  77. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/store/essence.rs +0 -0
  78. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/store/header_graft_tests.rs +0 -0
  79. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/store/snapshots.rs +0 -0
  80. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/store/threads.rs +0 -0
  81. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/transcript.rs +0 -0
  82. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/veccol.rs +0 -0
  83. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo/src/wal.rs +0 -0
  84. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/mnemo-python/.gitignore +0 -0
  85. {mnemo_engine-0.13.2 → mnemo_engine-0.15.0}/python/mnemo_engine/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mnemo-engine
3
- Version: 0.13.2
3
+ Version: 0.15.0
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: License :: OSI Approved :: Apache Software License
@@ -156,13 +156,43 @@ its own agent.
156
156
 
157
157
  ## API
158
158
 
159
- `mnemo.open(path, passphrase, dimensions=None) -> Mnemo`
159
+ `mnemo.open(path, passphrase=None, dimensions=None, read_only=False, *, shared=False, wait=10.0, allow_network_fs=False, cancel=None) -> Mnemo`
160
+
161
+ **No passphrase** (v0.15, 12.3): `mnemo.open(path)` opens an existing file
162
+ through the key-source chain, by the file's kind. A key comes from
163
+ `MNEMO_KEY`, `MNEMO_KEY_FILE`, `MNEMO_KEY_COMMAND` or the OS keychain (a
164
+ brain made by `mnemo init`, or kept there by `mnemo unlock`); a passphrase
165
+ from `MNEMO_PASSPHRASE` or the keychain. It never prompts. A missing file
166
+ raises `ValueError` (create one with `mnemo init`), and so does a file no
167
+ source has a secret for. It works with `read_only=True` and `shared=True`,
168
+ and one process can hold a keychain brain and a `MNEMO_PASSPHRASE` brain at
169
+ once. The released wheels carry the keychain; a wheel built from source
170
+ needs `--features keychain`.
171
+
172
+ **Shared mode** (v0.14, `shared=True`): several processes and sessions use
173
+ one file at once. The handle takes the file's lock for each call and holds
174
+ nothing between calls; every method below is one read or one write, and
175
+ each write commits before it returns (`flush()` does nothing). `wait` is how
176
+ long one call may wait for the lock, in seconds, before `LockedError`. The
177
+ file must already exist, and `shared=True` can't be combined with
178
+ `read_only=True`. Network and synced folders are refused unless
179
+ `allow_network_fs=True`. The handle keeps its passphrase in memory until it
180
+ closes. File-wide settings (`set_max_snapshots`, `set_cache_budget`,
181
+ `set_cache_flush_policy`, `set_turn_compress_after`) raise
182
+ `UnsupportedError`. Update every `mnemo-engine` that opens the file first.
183
+ See `docs/shared-mode.md` in the repository.
184
+
185
+ ```python
186
+ db = mnemo.open("team.mnemo", passphrase, shared=True) # in each process
187
+ db.remember("we ship on Fridays", "semantic", vector) # committed on return
188
+ db.notices() # what the handle warns about (also raised as UserWarning at open)
189
+ ```
160
190
 
161
191
  `Mnemo` methods:
162
192
 
163
193
  | Method | Purpose |
164
194
  |---|---|
165
- | `remember(content, memory_type, vector, *, agent_id, importance, session_id, ttl_secs, shared, metadata)` | Store a memory; returns its id |
195
+ | `remember(content, memory_type, vector, *, agent_id, importance, session_id, ttl_secs, shared, metadata, key, supersedes)` | Store a memory; returns its id. With `key`, a keyed write that supersedes the key's live record (returns `{"id", "outcome"}`). **`supersedes` (v0.15, with `key`):** the id of a memory written without a key, which becomes the key's first version and is superseded; matching content adopts it as is (`"updated"`) |
166
196
  | `recall(query, top_k=10, memory_types=None, agent_id=None, track_access=True, n_probe=None, n_rerank=None)` | Multi-signal ranked retrieval. `track_access=False` skips access-stat updates (fully read-only recall). `n_probe` / `n_rerank` (PR ANN-1): per-query ANN tuning — `None` uses the index's build-time defaults (ANN-1 auto-formulas: `(partitions+1)/2` and `500`) |
167
197
  | `search(query, top_k=10)` | Exact nearest-neighbour search |
168
198
  | `get(id)` / `delete(id)` | Fetch / soft-delete by id |
@@ -188,21 +218,29 @@ its own agent.
188
218
  | `set_turn_compress_after(secs)` | v9 files: compress thread turns once they're older than `secs` (default 7 days; `0` compresses at write). This handle only |
189
219
  | `memories()` | Enumerate every live (non-deleted, non-expired) memory as a list of dicts |
190
220
  | `dimensions()` | Embedding dimensionality this database was created with (also on `stats()["dimensions"]`) |
191
- | `rekey(new_passphrase, fast=False)` | Change the passphrase. Re-derives the KEK and re-wraps the DEK; encrypted pages are not rewritten (O(1) in db size). `fast=True` uses the cheap-Argon2 test params — omit for production. If it raises, the old passphrase is still in force (the one exception is an error that says the file may open with either). If it returns but couldn't scrub every copy of the old key wrap, it emits a `RuntimeWarning`: the call succeeded and the new passphrase is in force (where warnings are errors, it goes to `sys.unraisablehook` and the call still returns) |
192
- | `set_embedder(fn, *, name, dimensions, normalize=True)` | Register a Python callable `embed(texts: list[str]) -> list[list[float]]` as this handle's text embedder (Phase 3). Dimension-checks against the database's width; identity-checks against (and on first use upserts) the scaffold manifest's `embedder_name` / `embedder_dimensions` / `embedder_normalize` keys, so swapping embedders between opens fails loudly |
193
- | `remember_text(content, memory_type, **kwargs)` | Embed `content` via the registered embedder and `remember` the result. Accepts the same per-memory kwargs as `remember` (`agent_id`, `importance`, `session_id`, `ttl_secs`, `shared`, `metadata`) |
194
- | `recall_text(query, top_k=10, memory_types=None, agent_id=None, track_access=True, n_probe=None, n_rerank=None, filter=None, max_bytes=None, keywords=None, keyword_weight=None)` | Embed `query` via the registered embedder and run `recall`. Same return shape and kwargs as `recall`. `keywords` (v9 files): identifiers or exact terms to match (a version, a PR number, a function name), not the question; their BM25 score is added with weight `keyword_weight` (default 0.5) |
221
+ | `rekey(new_passphrase, fast=False)` | Change the passphrase. Re-derives the KEK and re-wraps the DEK; encrypted pages are not rewritten (O(1) in db size). `fast=True` uses the cheap-Argon2 test params — omit for production. Without it the new passphrase keeps the file's KDF parameters and never gets less than `KdfParams::secure()`, even on a file made with `open_with_key` (v0.15). If it raises, the old passphrase is still in force (the one exception is an error that says the file may open with either). If it returns but couldn't scrub every copy of the old key wrap, it emits a `RuntimeWarning`: the call succeeded and the new passphrase is in force (where warnings are errors, it goes to `sys.unraisablehook` and the call still returns) |
222
+ | `rekey_cleanup_error()` | After a successful `rekey` / `rekey_with_key`: what couldn't be scrubbed of the old key wrap, or `None`. The same report as the `RuntimeWarning`, for code that filters warnings. Compact the file to be sure the old secret opens nothing |
223
+ | `use_builtin_embedder(*, model_dir=None)` | **v0.15:** register the built-in embedder (snowflake-arctic-embed-xs on candle, 384 dimensions) instead of a callable. Its model (91.0 MB) is fetched into the cache directory on first use, said on stderr, and each file's SHA-256 is checked before it loads; `model_dir` loads the three files from a directory of your own and never downloads. With it, `recall_text` is identifier-aware: the question's plain words aren't matched by keyword and its identifiers (`snapshot_list`, `store.rs`, `--features`) are, unless you pass `keywords`. Raises `RuntimeError` offline or in a build without it |
224
+ | `set_embedder(fn, *, name, dimensions, normalize=True, query_fn=None, query_convention=None)` | Register a Python callable `embed(texts: list[str]) -> list[list[float]]` as this handle's text embedder (Phase 3). Dimension-checks against the database's width; identity-checks against (and on first use records) the file's embedder identity, so swapping embedders between opens fails loudly. **`query_fn` and `query_convention` (v0.15)**, both or neither: a callable of `fn`'s shape that embeds `recall_text`'s queries, for a model that embeds queries differently, and a short name for the difference (`"bge-query-instruction"`), which becomes part of the identity |
225
+ | `remember_text(content, memory_type, **kwargs)` | Embed `content` via the registered embedder and `remember` the result. Accepts the same per-memory kwargs as `remember` (`agent_id`, `importance`, `session_id`, `ttl_secs`, `shared`, `metadata`, `key`, `supersedes`) |
226
+ | `recall_text(query, top_k=10, memory_types=None, agent_id=None, track_access=True, n_probe=None, n_rerank=None, filter=None, max_bytes=None, keywords=None, keyword_weight=None)` | Embed `query` via the registered embedder and run `recall`. Same return shape and kwargs as `recall`. **Hybrid by default since v0.15** (v9 files): `query` itself is also matched by keyword (BM25) with weight 0.25. `keywords`: identifiers or exact terms the question doesn't contain (a version, a PR number, a function name), which replace the query for that score, with weight 0.5; `keyword_weight` sets either. `keywords=""` is vector-only. The query goes through `query_fn` when `set_embedder` was given one |
195
227
  | `cache_get_semantic_text(namespace, text, threshold=0.97)` | Text-side semantic cache lookup; uses the embedder's `name` as the semantic cache's `model` component |
196
- | `stats()` | Summary statistics — includes `fsyncs_last_flush` (count of `sync_all` the most recent `flush()` on this handle issued; `0` on a fresh handle before any flush — Phase 6 instrumentation) and `recall_mode` (`"exact_resident"`: the live facts' vectors fit the vector cache budget and recall scans them in memory; `"exact_paged"`: over the budget, or a v8 file, so recall reads them from the file; `"indexed"`: an IVF+PQ index shortlists). Since v0.13 also `snapshots_retained`, `oldest_restorable_at` (unix seconds, or `None`) and `snapshot_pinned_bytes`: what a restore can reach now, which under churn can be far less than the retention policy |
228
+ | `stats()` | Summary statistics — includes `fsyncs_last_flush` (count of `sync_all` the most recent `flush()` on this handle issued; `0` on a fresh handle before any flush — Phase 6 instrumentation) and `recall_mode` (`"exact_resident"`: the live facts' vectors fit the vector cache budget and recall scans them in memory; `"exact_paged"`: over the budget, or a v8 file, so recall reads them from the file; `"indexed"`: an IVF+PQ index shortlists). Since v0.13 also `snapshots_retained`, `oldest_restorable_at` (unix seconds, or `None`) and `snapshot_pinned_bytes`: what a restore can reach now, which under churn can be far less than the retention policy. Since v0.15 `keyword_tokenizer`: `"2"` (whole words and their parts, a file v0.15 made or rebuilt), `"1"` (whole words, an older file until `mnemo compact`), `"mixed"` (a build before v0.15 wrote to it), or `None` on v8 |
197
229
  | `export_encrypted(dest)` | Copy the (already-encrypted) file elsewhere |
198
230
  | `len(db)` | Live memory count |
231
+ | `shared` | `True` for a handle opened with `shared=True` |
232
+ | `notices()` | What the handle warns about once; each is also raised as a `UserWarning` at open. Shared mode: a sidecar directory it can't use, a synced folder, an allowed network filesystem. Any handle (v0.15): a passphrase on raw-key KDF parameters, with the fix (`mnemo rekey` or `mnemo compact`) |
233
+ | `set_cancel(token)` | Shared mode: give the handle a new `CancelToken` (or `None`) for its later calls, after a cancel |
199
234
 
200
235
  Plus two module-level functions:
201
236
 
202
237
  | Function | Purpose |
203
238
  |---|---|
204
- | `mnemo.compact_file(path, passphrase)` | Rewrite the file out-of-place, dropping tombstoned and expired memories and reclaiming stale pages. Caller's own handle must be closed first. Returns `{"before": int, "after": int}` |
239
+ | `mnemo.compact_file(path, passphrase)` | Rewrite the file out-of-place, dropping tombstoned and expired memories and reclaiming stale pages. Caller's own plain handle must be closed first; since v0.14 it waits up to 10 s for shared handles' calls. Returns `{"before": int, "after": int}` |
205
240
  | `mnemo.compact_file_with_key(path, key)` | The same for a raw-key file (`key`: 32 bytes, as from `generate_key()`), under the same key; converts a v8 file to v9 (since v0.13.1) |
241
+ | `mnemo.CancelToken()` | Shared mode: `token.cancel()` from another thread cancels a call that is waiting for the file's lock (`CancelledError`; nothing changes). Pass it as `open(..., cancel=token)`. A cancelled token stays cancelled |
242
+ | `mnemo.install_builtin_embedder()` | **v0.15:** fetch the built-in embedder's model (91.0 MB) into the cache directory, checking each file's SHA-256, and return the directory; nothing is fetched when it's there. The size and the place are said on stderr first. `MNEMO_CACHE_DIR` moves the cache, `MNEMO_MODEL_URL` points at a mirror |
243
+ | `mnemo.builtin_embedder_info()` | **v0.15:** `{"available": bool}`, and when the wheel has the built-in embedder, `model`, `revision`, `identity`, `dimensions`, `cache_dir`, `installed` and `download_bytes` |
206
244
  | `mnemo.build_info()` | Returns `{"version", "target", "aes_backend", "polyval_backend"}` for the installed wheel. Lets you verify an ARM wheel picked up the hardware AES path — `aes_backend` should read `"armv8 hardware"` on Apple Silicon / Graviton (anything else, like `"armv8 software (constant-time fallback)"`, means the compile missed the fix). PR 11.0, v0.5.1+ |
207
245
 
208
246
  `Session` methods: `add_turn(turn)`, `recall(query, top_k=10, memory_types=None)`,
@@ -233,6 +271,11 @@ before the engine sees them, are still `ValueError`):
233
271
  | `UnsupportedVersionError` | a file from a newer engine | upgrade `mnemo-engine` |
234
272
  | `NotAMnemoFileError` | not a `.mnemo` file | check the path |
235
273
  | `CorruptError` | a page or the header failed its integrity check: corrupt or tampered | restore from a backup or an export |
274
+ | `CancelledError` | shared mode: the call was cancelled while it waited for the lock; nothing changed | |
275
+ | `UnsupportedError` | shared mode isn't available here (a network or synced folder, an old Windows build), or a file-wide setting on a shared handle | pass `allow_network_fs=True` if you know the lock works there; drop the setting |
276
+ | `MaybeStoredError` | shared mode: a write failed after its commit point; it may be in the file | check whether it's there before retrying |
277
+ | `ReplacedDuringWriteError` | shared mode: another file was renamed over the path during the write (an older `mnemo compact`); the write isn't in the file at the path now | update every `mnemo` that opens the file, then write again |
278
+ | `ReplacedError` | the file at the path is no longer the one the handle opened: another file was renamed over it, or it was moved or removed; nothing was written. `shared` is `True` in a shared-mode write (an older `mnemo compact` renamed over the path just before the commit) | `shared` true: call again, and the call follows the new file. Otherwise reopen the path, or move a moved brain back |
236
279
  | `MnemoError` (only) | I/O, cryptography, key derivation or serialization | the message says which |
237
280
 
238
281
  ```python
@@ -142,13 +142,43 @@ its own agent.
142
142
 
143
143
  ## API
144
144
 
145
- `mnemo.open(path, passphrase, dimensions=None) -> Mnemo`
145
+ `mnemo.open(path, passphrase=None, dimensions=None, read_only=False, *, shared=False, wait=10.0, allow_network_fs=False, cancel=None) -> Mnemo`
146
+
147
+ **No passphrase** (v0.15, 12.3): `mnemo.open(path)` opens an existing file
148
+ through the key-source chain, by the file's kind. A key comes from
149
+ `MNEMO_KEY`, `MNEMO_KEY_FILE`, `MNEMO_KEY_COMMAND` or the OS keychain (a
150
+ brain made by `mnemo init`, or kept there by `mnemo unlock`); a passphrase
151
+ from `MNEMO_PASSPHRASE` or the keychain. It never prompts. A missing file
152
+ raises `ValueError` (create one with `mnemo init`), and so does a file no
153
+ source has a secret for. It works with `read_only=True` and `shared=True`,
154
+ and one process can hold a keychain brain and a `MNEMO_PASSPHRASE` brain at
155
+ once. The released wheels carry the keychain; a wheel built from source
156
+ needs `--features keychain`.
157
+
158
+ **Shared mode** (v0.14, `shared=True`): several processes and sessions use
159
+ one file at once. The handle takes the file's lock for each call and holds
160
+ nothing between calls; every method below is one read or one write, and
161
+ each write commits before it returns (`flush()` does nothing). `wait` is how
162
+ long one call may wait for the lock, in seconds, before `LockedError`. The
163
+ file must already exist, and `shared=True` can't be combined with
164
+ `read_only=True`. Network and synced folders are refused unless
165
+ `allow_network_fs=True`. The handle keeps its passphrase in memory until it
166
+ closes. File-wide settings (`set_max_snapshots`, `set_cache_budget`,
167
+ `set_cache_flush_policy`, `set_turn_compress_after`) raise
168
+ `UnsupportedError`. Update every `mnemo-engine` that opens the file first.
169
+ See `docs/shared-mode.md` in the repository.
170
+
171
+ ```python
172
+ db = mnemo.open("team.mnemo", passphrase, shared=True) # in each process
173
+ db.remember("we ship on Fridays", "semantic", vector) # committed on return
174
+ db.notices() # what the handle warns about (also raised as UserWarning at open)
175
+ ```
146
176
 
147
177
  `Mnemo` methods:
148
178
 
149
179
  | Method | Purpose |
150
180
  |---|---|
151
- | `remember(content, memory_type, vector, *, agent_id, importance, session_id, ttl_secs, shared, metadata)` | Store a memory; returns its id |
181
+ | `remember(content, memory_type, vector, *, agent_id, importance, session_id, ttl_secs, shared, metadata, key, supersedes)` | Store a memory; returns its id. With `key`, a keyed write that supersedes the key's live record (returns `{"id", "outcome"}`). **`supersedes` (v0.15, with `key`):** the id of a memory written without a key, which becomes the key's first version and is superseded; matching content adopts it as is (`"updated"`) |
152
182
  | `recall(query, top_k=10, memory_types=None, agent_id=None, track_access=True, n_probe=None, n_rerank=None)` | Multi-signal ranked retrieval. `track_access=False` skips access-stat updates (fully read-only recall). `n_probe` / `n_rerank` (PR ANN-1): per-query ANN tuning — `None` uses the index's build-time defaults (ANN-1 auto-formulas: `(partitions+1)/2` and `500`) |
153
183
  | `search(query, top_k=10)` | Exact nearest-neighbour search |
154
184
  | `get(id)` / `delete(id)` | Fetch / soft-delete by id |
@@ -174,21 +204,29 @@ its own agent.
174
204
  | `set_turn_compress_after(secs)` | v9 files: compress thread turns once they're older than `secs` (default 7 days; `0` compresses at write). This handle only |
175
205
  | `memories()` | Enumerate every live (non-deleted, non-expired) memory as a list of dicts |
176
206
  | `dimensions()` | Embedding dimensionality this database was created with (also on `stats()["dimensions"]`) |
177
- | `rekey(new_passphrase, fast=False)` | Change the passphrase. Re-derives the KEK and re-wraps the DEK; encrypted pages are not rewritten (O(1) in db size). `fast=True` uses the cheap-Argon2 test params — omit for production. If it raises, the old passphrase is still in force (the one exception is an error that says the file may open with either). If it returns but couldn't scrub every copy of the old key wrap, it emits a `RuntimeWarning`: the call succeeded and the new passphrase is in force (where warnings are errors, it goes to `sys.unraisablehook` and the call still returns) |
178
- | `set_embedder(fn, *, name, dimensions, normalize=True)` | Register a Python callable `embed(texts: list[str]) -> list[list[float]]` as this handle's text embedder (Phase 3). Dimension-checks against the database's width; identity-checks against (and on first use upserts) the scaffold manifest's `embedder_name` / `embedder_dimensions` / `embedder_normalize` keys, so swapping embedders between opens fails loudly |
179
- | `remember_text(content, memory_type, **kwargs)` | Embed `content` via the registered embedder and `remember` the result. Accepts the same per-memory kwargs as `remember` (`agent_id`, `importance`, `session_id`, `ttl_secs`, `shared`, `metadata`) |
180
- | `recall_text(query, top_k=10, memory_types=None, agent_id=None, track_access=True, n_probe=None, n_rerank=None, filter=None, max_bytes=None, keywords=None, keyword_weight=None)` | Embed `query` via the registered embedder and run `recall`. Same return shape and kwargs as `recall`. `keywords` (v9 files): identifiers or exact terms to match (a version, a PR number, a function name), not the question; their BM25 score is added with weight `keyword_weight` (default 0.5) |
207
+ | `rekey(new_passphrase, fast=False)` | Change the passphrase. Re-derives the KEK and re-wraps the DEK; encrypted pages are not rewritten (O(1) in db size). `fast=True` uses the cheap-Argon2 test params — omit for production. Without it the new passphrase keeps the file's KDF parameters and never gets less than `KdfParams::secure()`, even on a file made with `open_with_key` (v0.15). If it raises, the old passphrase is still in force (the one exception is an error that says the file may open with either). If it returns but couldn't scrub every copy of the old key wrap, it emits a `RuntimeWarning`: the call succeeded and the new passphrase is in force (where warnings are errors, it goes to `sys.unraisablehook` and the call still returns) |
208
+ | `rekey_cleanup_error()` | After a successful `rekey` / `rekey_with_key`: what couldn't be scrubbed of the old key wrap, or `None`. The same report as the `RuntimeWarning`, for code that filters warnings. Compact the file to be sure the old secret opens nothing |
209
+ | `use_builtin_embedder(*, model_dir=None)` | **v0.15:** register the built-in embedder (snowflake-arctic-embed-xs on candle, 384 dimensions) instead of a callable. Its model (91.0 MB) is fetched into the cache directory on first use, said on stderr, and each file's SHA-256 is checked before it loads; `model_dir` loads the three files from a directory of your own and never downloads. With it, `recall_text` is identifier-aware: the question's plain words aren't matched by keyword and its identifiers (`snapshot_list`, `store.rs`, `--features`) are, unless you pass `keywords`. Raises `RuntimeError` offline or in a build without it |
210
+ | `set_embedder(fn, *, name, dimensions, normalize=True, query_fn=None, query_convention=None)` | Register a Python callable `embed(texts: list[str]) -> list[list[float]]` as this handle's text embedder (Phase 3). Dimension-checks against the database's width; identity-checks against (and on first use records) the file's embedder identity, so swapping embedders between opens fails loudly. **`query_fn` and `query_convention` (v0.15)**, both or neither: a callable of `fn`'s shape that embeds `recall_text`'s queries, for a model that embeds queries differently, and a short name for the difference (`"bge-query-instruction"`), which becomes part of the identity |
211
+ | `remember_text(content, memory_type, **kwargs)` | Embed `content` via the registered embedder and `remember` the result. Accepts the same per-memory kwargs as `remember` (`agent_id`, `importance`, `session_id`, `ttl_secs`, `shared`, `metadata`, `key`, `supersedes`) |
212
+ | `recall_text(query, top_k=10, memory_types=None, agent_id=None, track_access=True, n_probe=None, n_rerank=None, filter=None, max_bytes=None, keywords=None, keyword_weight=None)` | Embed `query` via the registered embedder and run `recall`. Same return shape and kwargs as `recall`. **Hybrid by default since v0.15** (v9 files): `query` itself is also matched by keyword (BM25) with weight 0.25. `keywords`: identifiers or exact terms the question doesn't contain (a version, a PR number, a function name), which replace the query for that score, with weight 0.5; `keyword_weight` sets either. `keywords=""` is vector-only. The query goes through `query_fn` when `set_embedder` was given one |
181
213
  | `cache_get_semantic_text(namespace, text, threshold=0.97)` | Text-side semantic cache lookup; uses the embedder's `name` as the semantic cache's `model` component |
182
- | `stats()` | Summary statistics — includes `fsyncs_last_flush` (count of `sync_all` the most recent `flush()` on this handle issued; `0` on a fresh handle before any flush — Phase 6 instrumentation) and `recall_mode` (`"exact_resident"`: the live facts' vectors fit the vector cache budget and recall scans them in memory; `"exact_paged"`: over the budget, or a v8 file, so recall reads them from the file; `"indexed"`: an IVF+PQ index shortlists). Since v0.13 also `snapshots_retained`, `oldest_restorable_at` (unix seconds, or `None`) and `snapshot_pinned_bytes`: what a restore can reach now, which under churn can be far less than the retention policy |
214
+ | `stats()` | Summary statistics — includes `fsyncs_last_flush` (count of `sync_all` the most recent `flush()` on this handle issued; `0` on a fresh handle before any flush — Phase 6 instrumentation) and `recall_mode` (`"exact_resident"`: the live facts' vectors fit the vector cache budget and recall scans them in memory; `"exact_paged"`: over the budget, or a v8 file, so recall reads them from the file; `"indexed"`: an IVF+PQ index shortlists). Since v0.13 also `snapshots_retained`, `oldest_restorable_at` (unix seconds, or `None`) and `snapshot_pinned_bytes`: what a restore can reach now, which under churn can be far less than the retention policy. Since v0.15 `keyword_tokenizer`: `"2"` (whole words and their parts, a file v0.15 made or rebuilt), `"1"` (whole words, an older file until `mnemo compact`), `"mixed"` (a build before v0.15 wrote to it), or `None` on v8 |
183
215
  | `export_encrypted(dest)` | Copy the (already-encrypted) file elsewhere |
184
216
  | `len(db)` | Live memory count |
217
+ | `shared` | `True` for a handle opened with `shared=True` |
218
+ | `notices()` | What the handle warns about once; each is also raised as a `UserWarning` at open. Shared mode: a sidecar directory it can't use, a synced folder, an allowed network filesystem. Any handle (v0.15): a passphrase on raw-key KDF parameters, with the fix (`mnemo rekey` or `mnemo compact`) |
219
+ | `set_cancel(token)` | Shared mode: give the handle a new `CancelToken` (or `None`) for its later calls, after a cancel |
185
220
 
186
221
  Plus two module-level functions:
187
222
 
188
223
  | Function | Purpose |
189
224
  |---|---|
190
- | `mnemo.compact_file(path, passphrase)` | Rewrite the file out-of-place, dropping tombstoned and expired memories and reclaiming stale pages. Caller's own handle must be closed first. Returns `{"before": int, "after": int}` |
225
+ | `mnemo.compact_file(path, passphrase)` | Rewrite the file out-of-place, dropping tombstoned and expired memories and reclaiming stale pages. Caller's own plain handle must be closed first; since v0.14 it waits up to 10 s for shared handles' calls. Returns `{"before": int, "after": int}` |
191
226
  | `mnemo.compact_file_with_key(path, key)` | The same for a raw-key file (`key`: 32 bytes, as from `generate_key()`), under the same key; converts a v8 file to v9 (since v0.13.1) |
227
+ | `mnemo.CancelToken()` | Shared mode: `token.cancel()` from another thread cancels a call that is waiting for the file's lock (`CancelledError`; nothing changes). Pass it as `open(..., cancel=token)`. A cancelled token stays cancelled |
228
+ | `mnemo.install_builtin_embedder()` | **v0.15:** fetch the built-in embedder's model (91.0 MB) into the cache directory, checking each file's SHA-256, and return the directory; nothing is fetched when it's there. The size and the place are said on stderr first. `MNEMO_CACHE_DIR` moves the cache, `MNEMO_MODEL_URL` points at a mirror |
229
+ | `mnemo.builtin_embedder_info()` | **v0.15:** `{"available": bool}`, and when the wheel has the built-in embedder, `model`, `revision`, `identity`, `dimensions`, `cache_dir`, `installed` and `download_bytes` |
192
230
  | `mnemo.build_info()` | Returns `{"version", "target", "aes_backend", "polyval_backend"}` for the installed wheel. Lets you verify an ARM wheel picked up the hardware AES path — `aes_backend` should read `"armv8 hardware"` on Apple Silicon / Graviton (anything else, like `"armv8 software (constant-time fallback)"`, means the compile missed the fix). PR 11.0, v0.5.1+ |
193
231
 
194
232
  `Session` methods: `add_turn(turn)`, `recall(query, top_k=10, memory_types=None)`,
@@ -219,6 +257,11 @@ before the engine sees them, are still `ValueError`):
219
257
  | `UnsupportedVersionError` | a file from a newer engine | upgrade `mnemo-engine` |
220
258
  | `NotAMnemoFileError` | not a `.mnemo` file | check the path |
221
259
  | `CorruptError` | a page or the header failed its integrity check: corrupt or tampered | restore from a backup or an export |
260
+ | `CancelledError` | shared mode: the call was cancelled while it waited for the lock; nothing changed | |
261
+ | `UnsupportedError` | shared mode isn't available here (a network or synced folder, an old Windows build), or a file-wide setting on a shared handle | pass `allow_network_fs=True` if you know the lock works there; drop the setting |
262
+ | `MaybeStoredError` | shared mode: a write failed after its commit point; it may be in the file | check whether it's there before retrying |
263
+ | `ReplacedDuringWriteError` | shared mode: another file was renamed over the path during the write (an older `mnemo compact`); the write isn't in the file at the path now | update every `mnemo` that opens the file, then write again |
264
+ | `ReplacedError` | the file at the path is no longer the one the handle opened: another file was renamed over it, or it was moved or removed; nothing was written. `shared` is `True` in a shared-mode write (an older `mnemo compact` renamed over the path just before the commit) | `shared` true: call again, and the call follows the new file. Otherwise reopen the path, or move a moved brain back |
222
265
  | `MnemoError` (only) | I/O, cryptography, key derivation or serialization | the message says which |
223
266
 
224
267
  ```python