mnemo-engine 0.9.1__tar.gz → 0.11.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 (75) hide show
  1. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/PKG-INFO +4 -2
  2. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/README.md +3 -1
  3. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/Cargo.lock +94 -6
  4. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/Cargo.toml +18 -1
  5. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/README.md +2 -2
  6. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/benches/corpus.rs +11 -0
  7. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/examples/ann_recall_grid_v2.rs +99 -6
  8. mnemo_engine-0.11.0/mnemo/examples/device_budget.rs +645 -0
  9. mnemo_engine-0.11.0/mnemo/examples/fmt9_proto.rs +783 -0
  10. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/examples/ranking_v2.rs +46 -7
  11. mnemo_engine-0.11.0/mnemo/examples/thread_profile.rs +284 -0
  12. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/src/bin/mnemo.rs +79 -10
  13. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/src/crypto.rs +15 -1
  14. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/src/error.rs +4 -1
  15. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/src/format.rs +378 -7
  16. mnemo_engine-0.11.0/mnemo/src/freelist.rs +405 -0
  17. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/src/index.rs +397 -23
  18. mnemo_engine-0.11.0/mnemo/src/keyslot.rs +108 -0
  19. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/src/lib.rs +55 -1
  20. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/src/mcp.rs +14 -3
  21. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/src/pager.rs +74 -12
  22. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/src/result_cache.rs +8 -0
  23. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/src/store.rs +4484 -319
  24. mnemo_engine-0.11.0/mnemo/src/text.rs +197 -0
  25. mnemo_engine-0.11.0/mnemo/src/veccol.rs +361 -0
  26. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/src/wal.rs +112 -7
  27. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/tests/cli_smoke.rs +156 -5
  28. mnemo_engine-0.11.0/mnemo/tests/dur1_torn_header.rs +52 -0
  29. mnemo_engine-0.11.0/mnemo/tests/fix1_correctness_sweep.rs +31 -0
  30. mnemo_engine-0.11.0/mnemo/tests/fixtures/v0_10_0_memories.jsonl +240 -0
  31. mnemo_engine-0.11.0/mnemo/tests/fmt9_skeleton.rs +550 -0
  32. mnemo_engine-0.11.0/mnemo/tests/fmt9b_column.rs +518 -0
  33. mnemo_engine-0.11.0/mnemo/tests/fmt9c_commit.rs +351 -0
  34. mnemo_engine-0.11.0/mnemo/tests/fmt9d_bm25.rs +356 -0
  35. mnemo_engine-0.11.0/mnemo/tests/fmt9e_zstd.rs +366 -0
  36. mnemo_engine-0.11.0/mnemo/tests/integration.rs +18 -0
  37. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/tests/proptest_store.proptest-regressions +1 -0
  38. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/tests/proptest_store.rs +143 -0
  39. mnemo_engine-0.11.0/mnemo/tests/sec1_nonce_uniqueness.rs +43 -0
  40. {mnemo_engine-0.9.1/mnemo/tests → mnemo_engine-0.11.0/mnemo/tests/suites}/dur1_torn_header.rs +45 -51
  41. {mnemo_engine-0.9.1/mnemo/tests → mnemo_engine-0.11.0/mnemo/tests/suites}/fix1_correctness_sweep.rs +3 -18
  42. {mnemo_engine-0.9.1/mnemo/tests → mnemo_engine-0.11.0/mnemo/tests/suites}/integration.rs +652 -27
  43. {mnemo_engine-0.9.1/mnemo/tests → mnemo_engine-0.11.0/mnemo/tests/suites}/sec1_nonce_uniqueness.rs +3 -30
  44. mnemo_engine-0.11.0/mnemo/tests/v0_10_fixture.rs +152 -0
  45. mnemo_engine-0.11.0/mnemo/tests/wal_recover_alloc.rs +77 -0
  46. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo-python/Cargo.lock +113 -4
  47. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo-python/Cargo.toml +1 -1
  48. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo-python/README.md +3 -1
  49. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo-python/src/lib.rs +131 -2
  50. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo-python/test_mnemo.py +117 -0
  51. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/pyproject.toml +1 -1
  52. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/.gitignore +0 -0
  53. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/benches/cache.rs +0 -0
  54. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/benches/embed_overhead.rs +0 -0
  55. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/benches/open.rs +0 -0
  56. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/benches/recall.rs +0 -0
  57. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/benches/thread.rs +0 -0
  58. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/benches/write.rs +0 -0
  59. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/deny.toml +0 -0
  60. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/examples/ann_defaults_v0_6_0.rs +0 -0
  61. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/examples/ann_diagnose.rs +0 -0
  62. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/examples/ann_recall_grid.rs +0 -0
  63. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/examples/embedder_server.py +0 -0
  64. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/examples/file_size_breakdown.rs +0 -0
  65. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/examples/open_rss.rs +0 -0
  66. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/examples/quickstart.rs +0 -0
  67. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/examples/session.rs +0 -0
  68. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/src/cache.rs +0 -0
  69. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/src/embed.rs +0 -0
  70. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/src/embed_cmd.rs +0 -0
  71. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/src/memory.rs +0 -0
  72. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/src/session.rs +0 -0
  73. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo/src/transcript.rs +0 -0
  74. {mnemo_engine-0.9.1 → mnemo_engine-0.11.0}/mnemo-python/.gitignore +0 -0
  75. {mnemo_engine-0.9.1 → mnemo_engine-0.11.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.9.1
3
+ Version: 0.11.0
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: License :: OSI Approved :: Apache Software License
@@ -184,12 +184,14 @@ its own agent.
184
184
  | `set_cache_flush_policy(policy, max_dirty=None, max_age_secs=None)` | `policy="strict"` (default; every put durable on return) or `"batched"` (engine auto-flushes at `max_dirty` puts or `max_age_secs` seconds). Under `batched`, `cache_put` and friends no longer force an eager flush — call `db.flush()` yourself if you need it before a specific boundary |
185
185
  | `set_cache_budget(namespace, max_entries, max_bytes)` | Per-namespace LRU cap (defaults 10 000 entries / 64 MiB). On the next `cache_put` the LRU is evicted until both limits are satisfied |
186
186
  | `set_max_snapshots(max)` | Override the snapshot-manifest retention cap (default 256; `0` disables) |
187
+ | `set_vector_cache_budget(bytes)` | v9 files: keep the fp16 vector column in memory while it takes at most `bytes` (default 96 MiB, about 125K vectors at 384 dims); above it recall reads vectors through the page cache (less memory, slower recall). This handle only |
188
+ | `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 |
187
189
  | `memories()` | Enumerate every live (non-deleted, non-expired) memory as a list of dicts |
188
190
  | `dimensions()` | Embedding dimensionality this database was created with (also on `stats()["dimensions"]`) |
189
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 |
190
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 |
191
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`) |
192
- | `recall_text(query, top_k=10, memory_types=None, agent_id=None, track_access=True, n_probe=None, n_rerank=None)` | Embed `query` via the registered embedder and run `recall`. Same return shape and ANN-tuning kwargs as `recall` |
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) |
193
195
  | `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 |
194
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) |
195
197
  | `export_encrypted(dest)` | Copy the (already-encrypted) file elsewhere |
@@ -170,12 +170,14 @@ its own agent.
170
170
  | `set_cache_flush_policy(policy, max_dirty=None, max_age_secs=None)` | `policy="strict"` (default; every put durable on return) or `"batched"` (engine auto-flushes at `max_dirty` puts or `max_age_secs` seconds). Under `batched`, `cache_put` and friends no longer force an eager flush — call `db.flush()` yourself if you need it before a specific boundary |
171
171
  | `set_cache_budget(namespace, max_entries, max_bytes)` | Per-namespace LRU cap (defaults 10 000 entries / 64 MiB). On the next `cache_put` the LRU is evicted until both limits are satisfied |
172
172
  | `set_max_snapshots(max)` | Override the snapshot-manifest retention cap (default 256; `0` disables) |
173
+ | `set_vector_cache_budget(bytes)` | v9 files: keep the fp16 vector column in memory while it takes at most `bytes` (default 96 MiB, about 125K vectors at 384 dims); above it recall reads vectors through the page cache (less memory, slower recall). This handle only |
174
+ | `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 |
173
175
  | `memories()` | Enumerate every live (non-deleted, non-expired) memory as a list of dicts |
174
176
  | `dimensions()` | Embedding dimensionality this database was created with (also on `stats()["dimensions"]`) |
175
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 |
176
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 |
177
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`) |
178
- | `recall_text(query, top_k=10, memory_types=None, agent_id=None, track_access=True, n_probe=None, n_rerank=None)` | Embed `query` via the registered embedder and run `recall`. Same return shape and ANN-tuning kwargs as `recall` |
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) |
179
181
  | `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 |
180
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) |
181
183
  | `export_encrypted(dest)` | Copy the (already-encrypted) file elsewhere |
@@ -190,6 +190,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
190
190
  checksum = "4ff2a8126fff0f8c839080d619675a585e61720bb12d2baceae45769fd66f155"
191
191
  dependencies = [
192
192
  "find-msvc-tools",
193
+ "jobserver",
194
+ "libc",
193
195
  "shlex",
194
196
  ]
195
197
 
@@ -499,6 +501,18 @@ dependencies = [
499
501
  "wasm-bindgen",
500
502
  ]
501
503
 
504
+ [[package]]
505
+ name = "getrandom"
506
+ version = "0.3.4"
507
+ source = "registry+https://github.com/rust-lang/crates.io-index"
508
+ checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"
509
+ dependencies = [
510
+ "cfg-if",
511
+ "libc",
512
+ "r-efi",
513
+ "wasip2",
514
+ ]
515
+
502
516
  [[package]]
503
517
  name = "ghash"
504
518
  version = "0.5.1"
@@ -573,6 +587,16 @@ version = "1.0.18"
573
587
  source = "registry+https://github.com/rust-lang/crates.io-index"
574
588
  checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
575
589
 
590
+ [[package]]
591
+ name = "jobserver"
592
+ version = "0.1.34"
593
+ source = "registry+https://github.com/rust-lang/crates.io-index"
594
+ checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33"
595
+ dependencies = [
596
+ "getrandom 0.3.4",
597
+ "libc",
598
+ ]
599
+
576
600
  [[package]]
577
601
  name = "js-sys"
578
602
  version = "0.3.106"
@@ -627,6 +651,12 @@ version = "0.4.15"
627
651
  source = "registry+https://github.com/rust-lang/crates.io-index"
628
652
  checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab"
629
653
 
654
+ [[package]]
655
+ name = "lz4_flex"
656
+ version = "0.11.6"
657
+ source = "registry+https://github.com/rust-lang/crates.io-index"
658
+ checksum = "373f5eceeeab7925e0c1098212f2fbc4d416adec9d35051a6ab251e824c1854a"
659
+
630
660
  [[package]]
631
661
  name = "memchr"
632
662
  version = "2.8.3"
@@ -644,7 +674,7 @@ dependencies = [
644
674
 
645
675
  [[package]]
646
676
  name = "mnemo-engine"
647
- version = "0.9.1"
677
+ version = "0.11.0"
648
678
  dependencies = [
649
679
  "aes-gcm",
650
680
  "argon2",
@@ -652,6 +682,7 @@ dependencies = [
652
682
  "clap",
653
683
  "criterion",
654
684
  "fs4",
685
+ "lz4_flex",
655
686
  "mimalloc",
656
687
  "proptest",
657
688
  "rand",
@@ -664,12 +695,14 @@ dependencies = [
664
695
  "tempfile",
665
696
  "thiserror",
666
697
  "ulid",
698
+ "unicode-segmentation",
667
699
  "zeroize",
700
+ "zstd",
668
701
  ]
669
702
 
670
703
  [[package]]
671
704
  name = "mnemo-node"
672
- version = "0.9.1"
705
+ version = "0.11.0"
673
706
  dependencies = [
674
707
  "mnemo-engine",
675
708
  "napi",
@@ -791,6 +824,12 @@ version = "0.2.17"
791
824
  source = "registry+https://github.com/rust-lang/crates.io-index"
792
825
  checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
793
826
 
827
+ [[package]]
828
+ name = "pkg-config"
829
+ version = "0.3.34"
830
+ source = "registry+https://github.com/rust-lang/crates.io-index"
831
+ checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548"
832
+
794
833
  [[package]]
795
834
  name = "plotters"
796
835
  version = "0.3.7"
@@ -884,6 +923,12 @@ dependencies = [
884
923
  "proc-macro2",
885
924
  ]
886
925
 
926
+ [[package]]
927
+ name = "r-efi"
928
+ version = "5.3.0"
929
+ source = "registry+https://github.com/rust-lang/crates.io-index"
930
+ checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
931
+
887
932
  [[package]]
888
933
  name = "rand"
889
934
  version = "0.8.6"
@@ -911,7 +956,7 @@ version = "0.6.4"
911
956
  source = "registry+https://github.com/rust-lang/crates.io-index"
912
957
  checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
913
958
  dependencies = [
914
- "getrandom",
959
+ "getrandom 0.2.17",
915
960
  ]
916
961
 
917
962
  [[package]]
@@ -1210,7 +1255,7 @@ version = "1.1.3"
1210
1255
  source = "registry+https://github.com/rust-lang/crates.io-index"
1211
1256
  checksum = "04f903f293d11f31c0c29e4148f6dc0d033a7f80cebc0282bea147611667d289"
1212
1257
  dependencies = [
1213
- "getrandom",
1258
+ "getrandom 0.2.17",
1214
1259
  "rand",
1215
1260
  "serde",
1216
1261
  "web-time",
@@ -1230,9 +1275,9 @@ checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
1230
1275
 
1231
1276
  [[package]]
1232
1277
  name = "unicode-segmentation"
1233
- version = "1.13.3"
1278
+ version = "1.12.0"
1234
1279
  source = "registry+https://github.com/rust-lang/crates.io-index"
1235
- checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8"
1280
+ checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493"
1236
1281
 
1237
1282
  [[package]]
1238
1283
  name = "universal-hash"
@@ -1281,6 +1326,15 @@ version = "0.11.1+wasi-snapshot-preview1"
1281
1326
  source = "registry+https://github.com/rust-lang/crates.io-index"
1282
1327
  checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
1283
1328
 
1329
+ [[package]]
1330
+ name = "wasip2"
1331
+ version = "1.0.4+wasi-0.2.12"
1332
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1333
+ checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487"
1334
+ dependencies = [
1335
+ "wit-bindgen",
1336
+ ]
1337
+
1284
1338
  [[package]]
1285
1339
  name = "wasm-bindgen"
1286
1340
  version = "0.2.129"
@@ -1518,6 +1572,12 @@ version = "0.52.6"
1518
1572
  source = "registry+https://github.com/rust-lang/crates.io-index"
1519
1573
  checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
1520
1574
 
1575
+ [[package]]
1576
+ name = "wit-bindgen"
1577
+ version = "0.57.1"
1578
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1579
+ checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e"
1580
+
1521
1581
  [[package]]
1522
1582
  name = "zerocopy"
1523
1583
  version = "0.8.63"
@@ -1543,3 +1603,31 @@ name = "zeroize"
1543
1603
  version = "1.8.1"
1544
1604
  source = "registry+https://github.com/rust-lang/crates.io-index"
1545
1605
  checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde"
1606
+
1607
+ [[package]]
1608
+ name = "zstd"
1609
+ version = "0.13.4"
1610
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1611
+ checksum = "cdb02c3132d251ab1606e9fc913a7da6c6ed08cc263df15edf082e1dc497d157"
1612
+ dependencies = [
1613
+ "zstd-safe",
1614
+ ]
1615
+
1616
+ [[package]]
1617
+ name = "zstd-safe"
1618
+ version = "7.4.0"
1619
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1620
+ checksum = "1c8ea04668f5de8d8d51051714ba560c9536519cadcdb8829bba4fe2ad159b03"
1621
+ dependencies = [
1622
+ "zstd-sys",
1623
+ ]
1624
+
1625
+ [[package]]
1626
+ name = "zstd-sys"
1627
+ version = "2.1.2+zstd.1.5.7"
1628
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1629
+ checksum = "481ada9c543b2323cbb7bbdbb5249177fbf0188ed959ed2c15e4b22421c84ed3"
1630
+ dependencies = [
1631
+ "cc",
1632
+ "pkg-config",
1633
+ ]
@@ -10,7 +10,7 @@
10
10
  # The CLI binary name stays `mnemo`, so users still invoke `mnemo` on
11
11
  # the command line after `cargo install mnemo-engine`.
12
12
  name = "mnemo-engine"
13
- version = "0.9.1"
13
+ version = "0.11.0"
14
14
  edition = "2021"
15
15
  rust-version = "1.75"
16
16
  # `benches/corpus.rs` is a shared helper module pulled into real benches
@@ -115,6 +115,21 @@ criterion = { version = "=0.5.1", features = ["html_reports"], optional = true }
115
115
  # fields are only honoured on top-level deps, and we need the example
116
116
  # binary (built from this crate) to link against it when requested.
117
117
  mimalloc = { version = "=0.1.43", default-features = false, optional = true }
118
+ # FMT-9d (Phase 2): UAX #29 word segmentation for the BM25 tokenizer
119
+ # (`text.rs`). Pure Rust, no dependencies; pinned so tokens, and so the
120
+ # on-disk index, don't shift under a minor update.
121
+ unicode-segmentation = "=1.12.0"
122
+ # FMT-9e: v9 thread-turn records are zstd-compressed before encryption
123
+ # (`store.rs`, `compress_turn_record`). Required, not optional, since
124
+ # every build must read those records. The engine's first C dependency
125
+ # (`zstd-sys`, built by `cc`); CI cross-builds it for iOS and Android.
126
+ # `cc`'s `parallel` feature pulls `jobserver`, pinned in Cargo.lock to
127
+ # 0.1.34 (rust-version 1.63): 0.1.35 needs Rust 1.85, above our 1.75.
128
+ zstd = { version = "=0.13.4", default-features = false }
129
+ # FMT-9a prototype measurement (`examples/fmt9_proto.rs --part compress`):
130
+ # lz4_flex as the pure-Rust page-compression candidate, compared before
131
+ # the format was frozen. Only built with `--features fmt9_proto`.
132
+ lz4_flex = { version = "=0.11.6", default-features = false, features = ["std", "safe-encode", "safe-decode"], optional = true }
118
133
 
119
134
  [dev-dependencies]
120
135
  tempfile = "=3.10.1"
@@ -173,6 +188,8 @@ benches = ["dep:criterion"]
173
188
  # consumers do not carry the dep. Combine with `--features benches`
174
189
  # to actually build the example.
175
190
  mimalloc_bench = ["dep:mimalloc"]
191
+ # FMT-9a: the compression comparison in examples/fmt9_proto.rs.
192
+ fmt9_proto = ["dep:lz4_flex"]
176
193
 
177
194
  [profile.release]
178
195
  lto = true
@@ -439,7 +439,7 @@ Decrypted page payloads are held in a **bounded LRU cache** so repeated reads
439
439
  skip a decrypt. Eviction targets the least-recently-used *clean* page; a dirty
440
440
  page — the only copy of an un-flushed write — is never evicted, so the cap
441
441
  bounds retained clean pages without ever risking data. The default cap is
442
- 8192 pages (~64 MiB); `Mnemo::set_cache_capacity` tunes it, and
442
+ 1024 pages (~8 MiB; 8192 pages before v0.10.0); `Mnemo::set_cache_capacity` tunes it, and
443
443
  `Mnemo::cache_stats` reports occupancy. The LRU order is an intrusive linked
444
444
  list over a slab of indices, so it stays within the crate's
445
445
  `#![forbid(unsafe_code)]`.
@@ -679,7 +679,7 @@ cargo run --bin mnemo -- <command>
679
679
  | `recall` | Multi-signal ranked retrieval (sim + recency + …) |
680
680
  | `verify` | Decrypt and re-validate every live record |
681
681
  | `rekey` | Re-encrypt the data key under a new passphrase |
682
- | `compact` | Rebuild the file, dropping tombstones and expired |
682
+ | `compact` | Rebuild the file, dropping tombstones and expired; writes v9, which upgrades a v8 file (`--format v8` keeps v8 for one release) |
683
683
  | `snapshots` | List the restorable snapshots (one per flush) |
684
684
  | `restore` | Roll the database back to a past snapshot |
685
685
  | `demo` | Self-contained end-to-end demonstration |
@@ -42,10 +42,21 @@ pub fn fast_kdf_cfg(dimensions: usize) -> MnemoConfig {
42
42
  MnemoConfig {
43
43
  dimensions,
44
44
  kdf: KdfParams::fast(),
45
+ format_version: bench_format(),
45
46
  ..Default::default()
46
47
  }
47
48
  }
48
49
 
50
+ /// FMT-9f: the format bench files are created in: `MNEMO_BENCH_FORMAT=8`
51
+ /// for v8, otherwise the engine default (v9 from v0.11).
52
+ #[allow(dead_code)]
53
+ pub fn bench_format() -> u16 {
54
+ match std::env::var("MNEMO_BENCH_FORMAT").as_deref() {
55
+ Ok("8") => 8,
56
+ _ => 0,
57
+ }
58
+ }
59
+
49
60
  /// Production KDF config — what a real user's file is encrypted with.
50
61
  /// Only used by `open_latency` so we can report the actual cost split.
51
62
  #[allow(dead_code)]
@@ -100,11 +100,22 @@ fn gen_clustered_vectors(n: usize, dims: usize, k_clusters: usize, seed: u64) ->
100
100
  out
101
101
  }
102
102
 
103
+ /// FMT-9f: the file format the corpora are built in: `ANN_GRID_FORMAT=8`
104
+ /// or `9` (the default, as for new files from v0.11).
105
+ fn grid_format() -> u16 {
106
+ std::env::var("ANN_GRID_FORMAT")
107
+ .ok()
108
+ .and_then(|v| v.trim().parse().ok())
109
+ .unwrap_or(9)
110
+ }
111
+
103
112
  fn cached_corpus_path(n: usize) -> PathBuf {
104
113
  let base = std::env::var("CARGO_TARGET_DIR").unwrap_or_else(|_| "target".to_string());
105
- PathBuf::from(base)
106
- .join("benches")
107
- .join(format!("corpus_{n}_{DIMENSIONS}d.mnemo"))
114
+ PathBuf::from(base).join("benches").join(format!(
115
+ "corpus_{n}_{DIMENSIONS}d{}.mnemo",
116
+ // v9 corpora are cached apart from the v8 ones.
117
+ if grid_format() == 9 { "_v9" } else { "" }
118
+ ))
108
119
  }
109
120
 
110
121
  fn ensure_corpus(n: usize) -> PathBuf {
@@ -125,6 +136,7 @@ fn ensure_corpus(n: usize) -> PathBuf {
125
136
  let cfg = MnemoConfig {
126
137
  dimensions: DIMENSIONS,
127
138
  kdf: KdfParams::fast(),
139
+ format_version: grid_format(),
128
140
  ..Default::default()
129
141
  };
130
142
  let mut db = Mnemo::create(&path, PASSPHRASE, cfg).expect("create");
@@ -278,12 +290,93 @@ fn sweep_tier(n: usize) -> Value {
278
290
  })
279
291
  }
280
292
 
281
- fn main() {
282
- let tiers: Vec<Value> = [10_000usize, 100_000]
293
+ /// FMT-9f: the shipped default cell, exactly: the index built with
294
+ /// `IndexConfig::default()` and recalls that pin neither dial, so the
295
+ /// engine's own `n_probe` and rerank depth apply (on v9, at least
296
+ /// `V9_RERANK_PER_HIT` × `top_k`).
297
+ fn defaults_tier(n: usize) -> Value {
298
+ let path = ensure_corpus(n);
299
+ println!(
300
+ "\n[ann-grid-v2] defaults tier={n} (format v{})",
301
+ grid_format()
302
+ );
303
+ let queries = gen_clustered_vectors(QUERY_COUNT, DIMENSIONS, 100, 0xDEAD_BEEF);
304
+ let mut db = Mnemo::open(&path, PASSPHRASE).unwrap();
305
+ let truth: Vec<HashSet<String>> = queries
283
306
  .iter()
284
- .map(|&n| sweep_tier(n))
307
+ .map(|q| {
308
+ db.search(q, TOP_K, Metric::Cosine)
309
+ .unwrap()
310
+ .into_iter()
311
+ .map(|(m, _)| m.id.to_string())
312
+ .collect()
313
+ })
285
314
  .collect();
315
+ db.drop_index();
316
+ db.build_index_with(IndexConfig::default())
317
+ .expect("build index");
318
+ let info = db.stats().unwrap().index.expect("an index");
319
+ let t0 = Instant::now();
320
+ let mut sum = 0f32;
321
+ for (q, truth_ids) in queries.iter().zip(truth.iter()) {
322
+ let req = RecallRequest::new(q.clone())
323
+ .top_k(TOP_K)
324
+ .track_access(false);
325
+ let hits = db.recall(&req).expect("recall");
326
+ let got: HashSet<String> = hits.into_iter().map(|h| h.memory.id.to_string()).collect();
327
+ sum += truth_ids.intersection(&got).count() as f32 / TOP_K as f32;
328
+ }
329
+ let mean_secs = t0.elapsed().as_secs_f64() / QUERY_COUNT as f64;
330
+ let recall = sum / QUERY_COUNT as f32;
331
+ println!(
332
+ " {} partitions, recall@10 {recall:.4}, {:.3} ms/query",
333
+ info.partitions,
334
+ mean_secs * 1e3
335
+ );
336
+ json!({
337
+ "corpus_size": n,
338
+ "format": grid_format(),
339
+ "partitions": info.partitions,
340
+ "recall_at_10": round4(recall as f64),
341
+ "mean_query_secs": round6(mean_secs),
342
+ })
343
+ }
286
344
 
345
+ fn main() {
346
+ // `ANN_GRID_DEFAULTS=1`: only the shipped default cell per tier.
347
+ if std::env::var("ANN_GRID_DEFAULTS").as_deref() == Ok("1") {
348
+ let sizes: Vec<usize> = std::env::var("ANN_GRID_TIERS")
349
+ .ok()
350
+ .map(|v| v.split(',').filter_map(|x| x.trim().parse().ok()).collect())
351
+ .unwrap_or_else(|| vec![20_000, 50_000, 100_000]);
352
+ let tiers: Vec<Value> = sizes.iter().map(|&n| defaults_tier(n)).collect();
353
+ let out = std::env::var("ANN_GRID_OUT")
354
+ .unwrap_or_else(|_| format!("target/ann_grid_defaults_v{}.json", grid_format()));
355
+ fs::write(
356
+ &out,
357
+ serde_json::to_string_pretty(&json!({ "tiers": tiers })).unwrap() + "\n",
358
+ )
359
+ .unwrap();
360
+ println!("\n[ann-grid-v2] wrote {out}");
361
+ return;
362
+ }
363
+
364
+ // `ANN_GRID_TIERS=20000,50000` picks the corpus sizes (FMT-9: the
365
+ // no-ANN threshold check); the default is 10K and 100K.
366
+ let sizes: Vec<usize> = std::env::var("ANN_GRID_TIERS")
367
+ .ok()
368
+ .map(|v| v.split(',').filter_map(|x| x.trim().parse().ok()).collect())
369
+ .unwrap_or_else(|| vec![10_000, 100_000]);
370
+ let tiers: Vec<Value> = sizes.iter().map(|&n| sweep_tier(n)).collect();
371
+
372
+ // `ANN_GRID_OUT=path` writes only this block to `path` (PERF-1 used it
373
+ // to check the recall gate without rewriting the perf JSON).
374
+ if let Ok(alt) = std::env::var("ANN_GRID_OUT") {
375
+ let block = json!({ "tiers": tiers });
376
+ fs::write(&alt, serde_json::to_string_pretty(&block).unwrap() + "\n").unwrap();
377
+ println!("\n[ann-grid-v2] wrote {alt}");
378
+ return;
379
+ }
287
380
  let perf_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
288
381
  .parent()
289
382
  .unwrap()