mnemo-engine 0.6.0__tar.gz → 0.6.1__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 (51) hide show
  1. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/PKG-INFO +1 -1
  2. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/Cargo.lock +2 -2
  3. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/Cargo.toml +1 -1
  4. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/src/bin/mnemo.rs +37 -1
  5. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/tests/cli_smoke.rs +85 -0
  6. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo-python/Cargo.lock +2 -2
  7. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo-python/Cargo.toml +1 -1
  8. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo-python/src/lib.rs +23 -0
  9. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo-python/test_mnemo.py +26 -0
  10. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/pyproject.toml +1 -1
  11. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/README.md +0 -0
  12. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/.gitignore +0 -0
  13. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/README.md +0 -0
  14. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/benches/cache.rs +0 -0
  15. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/benches/corpus.rs +0 -0
  16. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/benches/embed_overhead.rs +0 -0
  17. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/benches/open.rs +0 -0
  18. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/benches/recall.rs +0 -0
  19. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/benches/write.rs +0 -0
  20. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/deny.toml +0 -0
  21. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/examples/ann_defaults_v0_6_0.rs +0 -0
  22. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/examples/ann_diagnose.rs +0 -0
  23. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/examples/ann_recall_grid.rs +0 -0
  24. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/examples/ann_recall_grid_v2.rs +0 -0
  25. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/examples/embedder_server.py +0 -0
  26. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/examples/file_size_breakdown.rs +0 -0
  27. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/examples/quickstart.rs +0 -0
  28. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/examples/session.rs +0 -0
  29. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/src/cache.rs +0 -0
  30. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/src/crypto.rs +0 -0
  31. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/src/embed.rs +0 -0
  32. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/src/embed_cmd.rs +0 -0
  33. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/src/error.rs +0 -0
  34. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/src/format.rs +0 -0
  35. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/src/index.rs +0 -0
  36. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/src/lib.rs +0 -0
  37. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/src/mcp.rs +0 -0
  38. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/src/memory.rs +0 -0
  39. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/src/pager.rs +0 -0
  40. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/src/result_cache.rs +0 -0
  41. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/src/session.rs +0 -0
  42. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/src/store.rs +0 -0
  43. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/src/wal.rs +0 -0
  44. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/tests/dur1_torn_header.rs +0 -0
  45. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/tests/fix1_correctness_sweep.rs +0 -0
  46. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/tests/integration.rs +0 -0
  47. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/tests/proptest_store.proptest-regressions +0 -0
  48. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/tests/proptest_store.rs +0 -0
  49. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo/tests/sec1_nonce_uniqueness.rs +0 -0
  50. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo-python/.gitignore +0 -0
  51. {mnemo_engine-0.6.0 → mnemo_engine-0.6.1}/mnemo-python/README.md +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mnemo-engine
3
- Version: 0.6.0
3
+ Version: 0.6.1
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: License :: OSI Approved :: Apache Software License
@@ -610,7 +610,7 @@ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
610
610
 
611
611
  [[package]]
612
612
  name = "mnemo-engine"
613
- version = "0.6.0"
613
+ version = "0.6.1"
614
614
  dependencies = [
615
615
  "aes-gcm",
616
616
  "argon2",
@@ -634,7 +634,7 @@ dependencies = [
634
634
 
635
635
  [[package]]
636
636
  name = "mnemo-node"
637
- version = "0.5.2"
637
+ version = "0.6.1"
638
638
  dependencies = [
639
639
  "mnemo-engine",
640
640
  "napi",
@@ -6,7 +6,7 @@
6
6
  # below stay `mnemo`, so consumers still write `use mnemo::...` and invoke
7
7
  # `mnemo` on the command line after `cargo add mnemo-engine`.
8
8
  name = "mnemo-engine"
9
- version = "0.6.0"
9
+ version = "0.6.1"
10
10
  edition = "2021"
11
11
  rust-version = "1.75"
12
12
  # `benches/corpus.rs` is a shared helper module pulled into real benches
@@ -147,8 +147,19 @@ enum Command {
147
147
  #[arg(long)]
148
148
  passphrase: Option<String>,
149
149
  /// Drop the existing index instead of building one.
150
- #[arg(long)]
150
+ #[arg(long, conflicts_with = "rebuild")]
151
151
  drop: bool,
152
+ /// Rebuild the ANN index from scratch using the auto-defaults
153
+ /// for the current corpus size (re-clusters centroids and
154
+ /// retrains the PQ codebook, undoing the cluster drift that
155
+ /// accumulates as memories are inserted against fixed
156
+ /// centroids). Required to pick up the ANN-1.1 defaults on an
157
+ /// index built by v0.5.x — the shipped BP.1 fix wires this up
158
+ /// so the v0.6.0 upgrade note's `mnemo index --rebuild` /
159
+ /// `rebuild_index()` commands actually exist. Mutually
160
+ /// exclusive with `--drop`.
161
+ #[arg(long, conflicts_with = "drop")]
162
+ rebuild: bool,
152
163
  /// IVF partitions (0 = auto, ~sqrt of memory count).
153
164
  #[arg(long, default_value_t = 0)]
154
165
  partitions: usize,
@@ -1023,6 +1034,7 @@ fn run() -> std::result::Result<(), String> {
1023
1034
  path,
1024
1035
  passphrase: pp,
1025
1036
  drop,
1037
+ rebuild,
1026
1038
  partitions,
1027
1039
  subspaces,
1028
1040
  n_probe,
@@ -1034,6 +1046,30 @@ fn run() -> std::result::Result<(), String> {
1034
1046
  db.drop_index();
1035
1047
  db.flush().map_err(fmt)?;
1036
1048
  println!("dropped ANN index on {path}");
1049
+ } else if rebuild {
1050
+ // BP.1: re-cluster + retrain under the current
1051
+ // `IndexConfig::default()` (the ANN-1.1 auto-formulas).
1052
+ // Explicit `--partitions` / `--subspaces` / `--n-probe`
1053
+ // / `--n-rerank` are rejected here so this flag has one
1054
+ // clear behavior — "give me the shipped defaults for
1055
+ // the file's current size". Users who want custom
1056
+ // parameters should use `mnemo index <file>` (without
1057
+ // --rebuild) with the per-flag overrides.
1058
+ if partitions != 0 || subspaces != 0 || n_probe != 0 || n_rerank != 0 {
1059
+ return Err(fmt(mnemo::MnemoError::Invalid(
1060
+ "--rebuild uses the auto-defaults; drop \
1061
+ --partitions / --subspaces / --n-probe / \
1062
+ --n-rerank, or build without --rebuild to pin \
1063
+ explicit values"
1064
+ .into(),
1065
+ )));
1066
+ }
1067
+ let info = db.rebuild_index().map_err(fmt)?;
1068
+ db.flush().map_err(fmt)?;
1069
+ println!(
1070
+ "rebuilt ANN index on {path}: {} vectors, {} partitions, {} PQ subspaces",
1071
+ info.vectors, info.partitions, info.subspaces
1072
+ );
1037
1073
  } else {
1038
1074
  let cfg = mnemo::IndexConfig {
1039
1075
  n_partitions: partitions,
@@ -1421,3 +1421,88 @@ fn mcp_hang_bounded_and_server_survives_for_next_call() {
1421
1421
  "call id 3 (post-HANG) should have succeeded, not errored: {stdout}"
1422
1422
  );
1423
1423
  }
1424
+
1425
+ // --- BP.1 ---------------------------------------------------------------
1426
+ //
1427
+ // `mnemo index <file> --rebuild` runs `rebuild_index()` on the open
1428
+ // database under the current `IndexConfig::default()` (the ANN-1.1
1429
+ // auto-formulas). Added in v0.6.1 so the v0.6.0 upgrade-note command
1430
+ // actually exists.
1431
+
1432
+ #[test]
1433
+ fn cli_index_rebuild_runs_rebuild_index() {
1434
+ let dir = tempdir().unwrap();
1435
+ let path = dir.path().join("rb.mnemo");
1436
+ let pp = "bp1-pw";
1437
+ {
1438
+ let mut db = Mnemo::create(&path, pp, fast_cfg(4)).unwrap();
1439
+ for i in 0..40 {
1440
+ let v = vec![((i % 4) + 1) as f32, 1.0, 2.0, 3.0];
1441
+ db.remember(Memory::new(format!("m{i}"), MemoryType::Semantic, v))
1442
+ .unwrap();
1443
+ }
1444
+ db.flush().unwrap();
1445
+ db.build_index().unwrap();
1446
+ db.flush().unwrap();
1447
+ db.close().unwrap();
1448
+ }
1449
+
1450
+ let (status, stdout, stderr) = run_cli(&["index", path.to_str().unwrap(), "--rebuild"], pp);
1451
+ assert!(
1452
+ status.success(),
1453
+ "mnemo index --rebuild failed: status={status:?} stdout={stdout} stderr={stderr}"
1454
+ );
1455
+ assert!(
1456
+ stdout.contains("rebuilt ANN index on"),
1457
+ "expected 'rebuilt' prefix in stdout, got: {stdout}"
1458
+ );
1459
+ // Reopen and confirm the index is still usable (rebuild persists).
1460
+ let db = Mnemo::open(&path, pp).unwrap();
1461
+ assert!(db.has_index(), "rebuilt index must persist across reopen");
1462
+ assert_eq!(db.len(), 40);
1463
+ }
1464
+
1465
+ #[test]
1466
+ fn cli_index_rebuild_rejects_tuning_overrides() {
1467
+ // `--rebuild` is the "give me the shipped auto-defaults" shortcut.
1468
+ // Mixing it with explicit tuning knobs is user-visibly ambiguous,
1469
+ // so BP.1 rejects the combination with a clear error.
1470
+ let (_dir, path, pp, _) = seed_db();
1471
+ let (status, _stdout, stderr) = run_cli(
1472
+ &[
1473
+ "index",
1474
+ path.to_str().unwrap(),
1475
+ "--rebuild",
1476
+ "--n-probe",
1477
+ "5",
1478
+ ],
1479
+ pp,
1480
+ );
1481
+ assert!(!status.success(), "expected non-zero exit, got {status:?}");
1482
+ assert!(
1483
+ stderr.contains("--rebuild uses the auto-defaults"),
1484
+ "expected the 'rebuild uses the auto-defaults' error, got: {stderr}"
1485
+ );
1486
+ }
1487
+
1488
+ #[test]
1489
+ fn cli_index_drop_and_rebuild_are_mutually_exclusive() {
1490
+ // clap enforces this via `conflicts_with`; verify the error path
1491
+ // (a wiring regression here would be silent otherwise — one flag
1492
+ // would just win over the other).
1493
+ let (_dir, path, pp, _) = seed_db();
1494
+ let (status, _stdout, stderr) = run_cli(
1495
+ &["index", path.to_str().unwrap(), "--drop", "--rebuild"],
1496
+ pp,
1497
+ );
1498
+ assert!(
1499
+ !status.success(),
1500
+ "clap must reject --drop --rebuild together"
1501
+ );
1502
+ assert!(
1503
+ stderr.contains("cannot be used with")
1504
+ || stderr.contains("conflicts")
1505
+ || stderr.contains("--rebuild") && stderr.contains("--drop"),
1506
+ "expected a clap 'conflicts' message, got: {stderr}"
1507
+ );
1508
+ }
@@ -409,7 +409,7 @@ dependencies = [
409
409
 
410
410
  [[package]]
411
411
  name = "mnemo-engine"
412
- version = "0.6.0"
412
+ version = "0.6.1"
413
413
  dependencies = [
414
414
  "aes-gcm",
415
415
  "argon2",
@@ -430,7 +430,7 @@ dependencies = [
430
430
 
431
431
  [[package]]
432
432
  name = "mnemo-python"
433
- version = "0.6.0"
433
+ version = "0.6.1"
434
434
  dependencies = [
435
435
  "mnemo-engine",
436
436
  "pyo3",
@@ -4,7 +4,7 @@
4
4
  # fields below are still useful for `cargo publish --dry-run` to lint
5
5
  # cleanly and for `cargo doc` to render coherently.
6
6
  name = "mnemo-python"
7
- version = "0.6.0"
7
+ version = "0.6.1"
8
8
  edition = "2021"
9
9
  rust-version = "1.75"
10
10
  description = "Python (PyO3) bindings for the Mnemo encrypted agent-memory engine; built by maturin into the mnemo-engine wheel on PyPI"
@@ -736,6 +736,29 @@ impl Mnemo {
736
736
  .map_err(to_py)
737
737
  }
738
738
 
739
+ /// Rebuild the ANN index from scratch using the auto-defaults for
740
+ /// the current corpus size — re-clusters centroids and retrains
741
+ /// the PQ codebook, undoing the cluster drift that accumulates as
742
+ /// memories are inserted against fixed centroids. This is the
743
+ /// command the v0.6.0 upgrade note tells users to run after
744
+ /// upgrading from v0.5.x so an index built under the old
745
+ /// `pq_subspaces=48` defaults picks up the ANN-1.1 formulas
746
+ /// (`pq_subspaces = dims/4`, size-aware `n_probe` / `n_rerank`).
747
+ ///
748
+ /// BP.1: new in v0.6.1 — before, Python had no rebuild command and
749
+ /// the CHANGELOG's `rebuild_index()` reference raised
750
+ /// `AttributeError`. Works the same way as the CLI's
751
+ /// `mnemo index <file> --rebuild`. Does not flush — call `flush()`
752
+ /// yourself to persist the new index.
753
+ ///
754
+ /// Releases the GIL during the rebuild, same as `build_index`.
755
+ fn rebuild_index(&mut self, py: Python<'_>) -> PyResult<()> {
756
+ let core = self.core_mut()?;
757
+ py.allow_threads(|| core.rebuild_index())
758
+ .map(|_| ())
759
+ .map_err(to_py)
760
+ }
761
+
739
762
  /// Drop the approximate index; recall reverts to exact scan.
740
763
  fn drop_index(&mut self) -> PyResult<()> {
741
764
  self.core_mut()?.drop_index();
@@ -763,6 +763,31 @@ def test_background_thread_makes_progress_during_long_flush():
763
763
  print(f"ok background thread ticked {during} times during blocking call")
764
764
 
765
765
 
766
+ def test_rebuild_index_reclusters_under_current_defaults():
767
+ """BP.1: `db.rebuild_index()` re-runs `build_index_with(IndexConfig::
768
+ default())`, so an index built under old defaults picks up the
769
+ current auto-formulas (ANN-1.1: `pq_subspaces = dims/4` etc).
770
+ Before BP.1 Python had no such method — the v0.6.0 CHANGELOG
771
+ promised it but called it raised `AttributeError`.
772
+ """
773
+ with tempfile.TemporaryDirectory() as d:
774
+ path = os.path.join(d, "r.mnemo")
775
+ with mnemo.open(path, "pw", dimensions=4) as db:
776
+ # Seed enough vectors to actually have an ANN index.
777
+ for i in range(40):
778
+ v = [float((i + k) % 7 + 1) for k in range(4)]
779
+ db.remember(f"m{i}", "semantic", v)
780
+ db.flush()
781
+ db.build_index()
782
+ db.flush()
783
+ # Rebuild should succeed and leave the index in place.
784
+ db.rebuild_index()
785
+ db.flush()
786
+ assert db.has_index(), "rebuild must leave an index behind"
787
+ assert len(db) == 40, "rebuild must not drop memories"
788
+ print("ok db.rebuild_index() runs + persists")
789
+
790
+
766
791
  if __name__ == "__main__":
767
792
  print(f"mnemo {mnemo.__version__}")
768
793
  test_create_remember_recall()
@@ -792,4 +817,5 @@ if __name__ == "__main__":
792
817
  test_remember_rejects_zero_vector()
793
818
  test_compact_file_module_fn()
794
819
  test_recall_accepts_n_probe_n_rerank_overrides()
820
+ test_rebuild_index_reclusters_under_current_defaults()
795
821
  print("\nall Python binding tests passed")
@@ -11,7 +11,7 @@ build-backend = "maturin"
11
11
  # Cargo.toml), so user code keeps writing `import mnemo` after
12
12
  # `pip install mnemo-engine`.
13
13
  name = "mnemo-engine"
14
- version = "0.6.0"
14
+ version = "0.6.1"
15
15
  description = "Encrypted, portable agent-memory engine — Python bindings"
16
16
  readme = "README.md"
17
17
  requires-python = ">=3.8"
File without changes