mnemo-engine 0.12.0__tar.gz → 0.12.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.
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/PKG-INFO +2 -2
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/README.md +1 -1
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/Cargo.lock +3 -3
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/Cargo.toml +1 -1
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/README.md +46 -8
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/README.md +87 -12
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/gradle.properties +1 -1
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/release-check/settings.gradle.kts +1 -1
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/scripts/central-dry-run.sh +14 -1
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/scripts/emulator-tests.sh +31 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/src/androidTest/kotlin/io/github/toarchkumar/mnemo/AndroidTests.kt +29 -1
- mnemo_engine-0.12.1/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/FlushPolicy.kt +100 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/MnemoStore.kt +208 -37
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/MnemoStoreConfiguration.kt +3 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/ProcessStopObserver.kt +15 -3
- mnemo_engine-0.12.1/mnemo/bindings/kotlin/src/test/kotlin/io/github/toarchkumar/mnemo/EmbedderLockTests.kt +112 -0
- mnemo_engine-0.12.1/mnemo/bindings/kotlin/src/test/kotlin/io/github/toarchkumar/mnemo/FlushPolicyTests.kt +185 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/src/test/kotlin/io/github/toarchkumar/mnemo/StoreTests.kt +1 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/swift/README.md +89 -8
- mnemo_engine-0.12.1/mnemo/bindings/swift/Sources/Mnemo/FlushPolicy.swift +102 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/swift/Sources/Mnemo/MnemoStore.swift +285 -56
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/swift/Sources/Mnemo/MnemoStoreError.swift +5 -2
- mnemo_engine-0.12.1/mnemo/bindings/swift/TestHost/App/MnemoTestHostApp.swift +74 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/swift/TestHost/project.yml +2 -0
- mnemo_engine-0.12.1/mnemo/bindings/swift/Tests/MnemoTests/EmbedderLockTests.swift +120 -0
- mnemo_engine-0.12.1/mnemo/bindings/swift/Tests/MnemoTests/FlushPolicyTests.swift +165 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/swift/Tests/MnemoTests/StoreTests.swift +13 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/swift/Tests/MnemoTests/iOSTests.swift +54 -0
- mnemo_engine-0.12.1/mnemo/bindings/swift/scripts/check-published-package.sh +140 -0
- mnemo_engine-0.12.1/mnemo/bindings/swift/scripts/kill-test.sh +78 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/examples/device_budget.rs +77 -2
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/bin/mnemo.rs +26 -1
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/lib.rs +4 -3
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/mcp.rs +1 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/store/flush.rs +1 -1
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/store/maintenance.rs +206 -51
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/store/mod.rs +29 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/store/records.rs +54 -2
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/wal.rs +16 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/tests/cli_smoke.rs +43 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/tests/fmt9b_column.rs +112 -1
- mnemo_engine-0.12.1/mnemo/tests/rekey_export.rs +204 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo-python/Cargo.lock +2 -2
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo-python/Cargo.toml +1 -1
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo-python/README.md +1 -1
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo-python/src/lib.rs +1 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo-python/test_mnemo.py +1 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/pyproject.toml +1 -1
- mnemo_engine-0.12.0/mnemo/bindings/swift/TestHost/App/MnemoTestHostApp.swift +0 -11
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/.gitignore +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/benches/cache.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/benches/corpus.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/benches/embed_overhead.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/benches/open.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/benches/recall.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/benches/thread.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/benches/write.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/.gitignore +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/NOTICE +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/build.gradle.kts +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/consumer-rules.pro +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/gradle/wrapper/gradle-wrapper.jar +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/gradle/wrapper/gradle-wrapper.properties +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/gradlew +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/gradlew.bat +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/release-check/build.gradle.kts +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/release-check/src/main/AndroidManifest.xml +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/release-check/src/test/kotlin/io/github/toarchkumar/mnemo/check/ConsumerTest.kt +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/scripts/build-native.sh +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/scripts/check-elf.py +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/scripts/check-package.py +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/settings.gradle.kts +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/src/androidTest/AndroidManifest.xml +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/src/androidTest/kotlin/io/github/toarchkumar/mnemo/TestActivity.kt +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/src/main/AndroidManifest.xml +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/KeyId.kt +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/MnemoKeyStorage.kt +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/MnemoKeystore.kt +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/MnemoStoreException.kt +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/src/sharedTest/kotlin/io/github/toarchkumar/mnemo/Support.kt +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/src/test/kotlin/io/github/toarchkumar/mnemo/KeystoreFileTests.kt +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/uniffi.toml +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/swift/.gitignore +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/swift/Package.swift +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/swift/Sources/Mnemo/FilePolicy.swift +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/swift/Sources/Mnemo/Lifecycle.swift +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/swift/Sources/Mnemo/MnemoKeychain.swift +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/swift/Tests/MnemoTests/Support.swift +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/swift/scripts/build-xcframework.sh +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/swift/scripts/check-release-package.sh +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/swift/scripts/make-release-package.sh +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/deny.toml +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/examples/ann_defaults_v0_6_0.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/examples/ann_diagnose.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/examples/ann_recall_grid.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/examples/ann_recall_grid_v2.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/examples/embedder_server.py +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/examples/file_size_breakdown.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/examples/fmt9_proto.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/examples/open_rss.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/examples/quickstart.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/examples/ranking_v2.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/examples/session.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/examples/thread_profile.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/cache.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/crypto.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/embed.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/embed_cmd.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/error.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/format.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/freelist.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/index.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/keyslot.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/memory.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/pager.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/result_cache.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/session.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/store/ann.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/store/cache_api.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/store/continuation.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/store/crud.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/store/essence.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/store/hooks.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/store/keyed.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/store/load.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/store/open.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/store/recall.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/store/snapshots.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/store/threads.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/text.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/transcript.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/src/veccol.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/tests/dur1_torn_header.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/tests/fix1_correctness_sweep.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/tests/fixtures/v0_10_0_memories.jsonl +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/tests/fmt9_skeleton.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/tests/fmt9c_commit.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/tests/fmt9d_bm25.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/tests/fmt9e_zstd.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/tests/integration.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/tests/proptest_store.proptest-regressions +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/tests/proptest_store.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/tests/sec1_nonce_uniqueness.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/tests/suites/dur1_torn_header.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/tests/suites/fix1_correctness_sweep.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/tests/suites/integration.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/tests/suites/sec1_nonce_uniqueness.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/tests/v0_10_fixture.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/tests/wal_recover_alloc.rs +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo-python/.gitignore +0 -0
- {mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/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.12.
|
|
3
|
+
Version: 0.12.1
|
|
4
4
|
Classifier: Programming Language :: Rust
|
|
5
5
|
Classifier: Programming Language :: Python :: 3
|
|
6
6
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
@@ -193,7 +193,7 @@ its own agent.
|
|
|
193
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
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) |
|
|
195
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 |
|
|
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) |
|
|
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) |
|
|
197
197
|
| `export_encrypted(dest)` | Copy the (already-encrypted) file elsewhere |
|
|
198
198
|
| `len(db)` | Live memory count |
|
|
199
199
|
|
|
@@ -179,7 +179,7 @@ its own agent.
|
|
|
179
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
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) |
|
|
181
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 |
|
|
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) |
|
|
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) |
|
|
183
183
|
| `export_encrypted(dest)` | Copy the (already-encrypted) file elsewhere |
|
|
184
184
|
| `len(db)` | Live memory count |
|
|
185
185
|
|
|
@@ -821,7 +821,7 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
|
|
821
821
|
|
|
822
822
|
[[package]]
|
|
823
823
|
name = "mnemo-engine"
|
|
824
|
-
version = "0.12.
|
|
824
|
+
version = "0.12.1"
|
|
825
825
|
dependencies = [
|
|
826
826
|
"aes-gcm",
|
|
827
827
|
"argon2",
|
|
@@ -849,7 +849,7 @@ dependencies = [
|
|
|
849
849
|
|
|
850
850
|
[[package]]
|
|
851
851
|
name = "mnemo-node"
|
|
852
|
-
version = "0.12.
|
|
852
|
+
version = "0.12.1"
|
|
853
853
|
dependencies = [
|
|
854
854
|
"mnemo-engine",
|
|
855
855
|
"napi",
|
|
@@ -859,7 +859,7 @@ dependencies = [
|
|
|
859
859
|
|
|
860
860
|
[[package]]
|
|
861
861
|
name = "mnemo-uniffi"
|
|
862
|
-
version = "0.12.
|
|
862
|
+
version = "0.12.1"
|
|
863
863
|
dependencies = [
|
|
864
864
|
"mnemo-engine",
|
|
865
865
|
"serde_json",
|
|
@@ -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.12.
|
|
13
|
+
version = "0.12.1"
|
|
14
14
|
edition = "2021"
|
|
15
15
|
rust-version = "1.75"
|
|
16
16
|
# `benches/corpus.rs` is a shared helper module pulled into real benches
|
|
@@ -309,6 +309,16 @@ Argon2id; the KEK wraps a random data-encryption key (DEK); the DEK encrypts
|
|
|
309
309
|
every data page with AES-256-GCM. Changing the passphrase (`rekey`) only
|
|
310
310
|
re-wraps the DEK — the bulk pages are never rewritten.
|
|
311
311
|
|
|
312
|
+
That makes `rekey` cheap, and it also means a rekey changes who can open
|
|
313
|
+
the file *from now on, provided nobody kept the old secret*: the DEK is the
|
|
314
|
+
same, so a copy of the file taken earlier still opens with the old
|
|
315
|
+
passphrase, and so does the live file's data for anyone holding that copy's
|
|
316
|
+
header. To revoke an old passphrase (after a suspected leak, say), rotate
|
|
317
|
+
the DEK too: `mnemo rekey --rotate`, or `rekey` followed by
|
|
318
|
+
`Mnemo::compact_file`, which rewrites the file under a fresh DEK.
|
|
319
|
+
`Mnemo::export_rekeyed` writes a copy under a fresh DEK and a new secret,
|
|
320
|
+
sharing no key material with the source.
|
|
321
|
+
|
|
312
322
|
The file is a sequence of fixed **8 KiB pages**:
|
|
313
323
|
|
|
314
324
|
- **Page 0** — the header (plaintext): magic, version, KDF parameters, salt,
|
|
@@ -428,10 +438,36 @@ navigable history.
|
|
|
428
438
|
|
|
429
439
|
A restore is itself an ordinary committed transaction (and a new snapshot), so
|
|
430
440
|
it is crash-safe *and* reversible — having rewound, you can roll forward again.
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
441
|
+
|
|
442
|
+
**How far back you can restore is capped.** Only retained snapshots can be
|
|
443
|
+
restored, and the cap differs by format:
|
|
444
|
+
|
|
445
|
+
| Format | Retained by default | Override |
|
|
446
|
+
|---|---|---|
|
|
447
|
+
| v9 (new files) | the newest **16** snapshots, plus any from the **last 24 hours**; retained snapshots never pin more than a quarter of the file (past that, the oldest go first, whatever their age) | `max_snapshots` / `set_max_snapshots` changes the count |
|
|
448
|
+
| v8 | the newest **256** snapshots | `max_snapshots` (`0`: no cap) |
|
|
449
|
+
|
|
450
|
+
So on a v9 file that flushes often (a phone app under the default
|
|
451
|
+
coalesced flush policy commits about once a second while it's writing),
|
|
452
|
+
"restore to an hour ago" works only within the last 24 hours, and "restore
|
|
453
|
+
to last week" doesn't work unless you raise the count. `restore_to` a
|
|
454
|
+
snapshot that's gone returns `MnemoError::NotFound`. `compact_file`
|
|
455
|
+
collapses the manifest to a single snapshot, and there's no external log
|
|
456
|
+
archiving, so nothing older than the last compaction is ever restorable.
|
|
457
|
+
`snapshots()` lists exactly what's restorable now.
|
|
458
|
+
|
|
459
|
+
### The vector column (v9)
|
|
460
|
+
|
|
461
|
+
On a v9 file, recall scans an fp16 copy of the vectors (`dims × 2 + 4`
|
|
462
|
+
bytes a fact). It stays in memory while the file's **live facts** fit
|
|
463
|
+
`set_vector_cache_budget` (96 MiB by default, 16 MiB in the mobile
|
|
464
|
+
packages). Thread turns, essence items, tombstones and superseded
|
|
465
|
+
versions don't count. Past the budget, recall reads the vectors through
|
|
466
|
+
the page cache instead: at 10,000 facts × 384 dimensions, warm recall goes
|
|
467
|
+
from about 2 ms to about 11 ms (M1 Pro). `stats().recall_mode` says which
|
|
468
|
+
path recall takes now: `ExactResident`, `ExactPaged` (over the budget, or
|
|
469
|
+
a v8 file) or `Indexed` (an IVF+PQ index, which v9 builds from 20,000
|
|
470
|
+
facts).
|
|
435
471
|
|
|
436
472
|
### Page cache
|
|
437
473
|
|
|
@@ -678,7 +714,7 @@ cargo run --bin mnemo -- <command>
|
|
|
678
714
|
| `search` | Exact nearest-neighbour search (similarity only) |
|
|
679
715
|
| `recall` | Multi-signal ranked retrieval (sim + recency + …) |
|
|
680
716
|
| `verify` | Decrypt and re-validate every live record |
|
|
681
|
-
| `rekey` | Re-encrypt the data key under a new passphrase
|
|
717
|
+
| `rekey` | Re-encrypt the data key under a new passphrase; `--rotate` also rewrites the file under a fresh data key (revokes the old passphrase) |
|
|
682
718
|
| `compact` | Rebuild the file, dropping tombstones and expired; writes v9, which upgrades a v8 file (`--format v8` keeps v8 for one release) |
|
|
683
719
|
| `snapshots` | List the restorable snapshots (one per flush) |
|
|
684
720
|
| `restore` | Roll the database back to a past snapshot |
|
|
@@ -880,9 +916,11 @@ let cfg = MnemoConfig {
|
|
|
880
916
|
**2. Cap the snapshot manifest.** Every `flush` appends one snapshot
|
|
881
917
|
entry; without a cap, long-running services accumulate them forever —
|
|
882
918
|
manifest serialize-cost and the manifest run on disk grow O(total
|
|
883
|
-
flushes). The default cap is 256 retained snapshots (the most
|
|
884
|
-
are kept; older ones are pruned at flush time, with their data
|
|
885
|
-
left on disk until the next `compact_file`).
|
|
919
|
+
flushes). The default cap on v8 is 256 retained snapshots (the most
|
|
920
|
+
recent N are kept; older ones are pruned at flush time, with their data
|
|
921
|
+
pages left on disk until the next `compact_file`). On v9 it's 16, plus
|
|
922
|
+
any from the last 24 hours (see "Snapshots & point-in-time recovery"),
|
|
923
|
+
and pruned snapshots' pages are reused. Override per-database:
|
|
886
924
|
|
|
887
925
|
```rust
|
|
888
926
|
let cfg = MnemoConfig {
|
|
@@ -19,7 +19,7 @@ From Maven Central (`mavenCentral()` in your repositories):
|
|
|
19
19
|
|
|
20
20
|
```kotlin
|
|
21
21
|
dependencies {
|
|
22
|
-
implementation("io.github.toarchkumar:mnemo-android:0.12.
|
|
22
|
+
implementation("io.github.toarchkumar:mnemo-android:0.12.1")
|
|
23
23
|
}
|
|
24
24
|
```
|
|
25
25
|
|
|
@@ -101,9 +101,72 @@ val byWord = store.recall(emptyList(), RecallOptions(keywords = "UA 931"))
|
|
|
101
101
|
- **Keyed facts:** `RememberOptions(key = ...)` writes a new version and
|
|
102
102
|
supersedes the old one. `history(key)` lists the versions, newest first.
|
|
103
103
|
- **The result cache:** `cachePut` and `cacheGet`, by exact key.
|
|
104
|
+
- **Batches:** `withSession { session -> ... }` runs many calls on one
|
|
105
|
+
open handle and commits once at the end (see Durability).
|
|
104
106
|
- **Also:** `get`, `update`, `delete`, `about`, `stats`, `count`, `flush`,
|
|
105
107
|
`close` and `compact`.
|
|
106
108
|
|
|
109
|
+
### Memory and recall speed
|
|
110
|
+
|
|
111
|
+
Recall scans an fp16 copy of the vectors (`dims × 2 + 4` bytes a fact).
|
|
112
|
+
It stays in memory while the file's **live facts** fit the configuration's
|
|
113
|
+
`vectorCacheBudgetBytes` (16 MiB by default). Thread turns, essence items and
|
|
114
|
+
superseded versions don't count. Past the budget, recall reads the vectors
|
|
115
|
+
from the file instead, which is slower, and slower still as the file grows.
|
|
116
|
+
|
|
117
|
+
| Dimensions | Facts that fit 16 MiB |
|
|
118
|
+
|---|---|
|
|
119
|
+
| 384 | 21,732 |
|
|
120
|
+
| 512 | 16,320 |
|
|
121
|
+
| 768 | 10,894 |
|
|
122
|
+
|
|
123
|
+
``store.stats()`` says which path recall takes now, in `recallMode`:
|
|
124
|
+
`RecallMode.EXACT_RESIDENT` (in memory, the fast path),
|
|
125
|
+
`RecallMode.EXACT_PAGED` (from the file) or `RecallMode.INDEXED`. Past the budget, raise `vectorCacheBudgetBytes` if the app can
|
|
126
|
+
spend the memory. Past 20,000 facts, `buildIndex()` builds the IVF+PQ
|
|
127
|
+
index instead.
|
|
128
|
+
|
|
129
|
+
### History
|
|
130
|
+
|
|
131
|
+
Every commit leaves a restorable snapshot, but only some are kept. A
|
|
132
|
+
new (v9) file keeps the newest 16 plus any from the last 24 hours, and
|
|
133
|
+
never lets them pin more than a quarter of the file. Under the default
|
|
134
|
+
flush policy a busy app commits about once a second, so the history
|
|
135
|
+
reaches back about a day, not further. A v8 file keeps the newest 256.
|
|
136
|
+
`compact()` drops all of them.
|
|
137
|
+
|
|
138
|
+
### Durability
|
|
139
|
+
|
|
140
|
+
A write is in memory until the store commits it to disk. A crash, a kill
|
|
141
|
+
(`am force-stop`, the low-memory killer, a swipe from Recents) or a power
|
|
142
|
+
loss keeps every committed write and loses the rest. When the store
|
|
143
|
+
commits is the configuration's `flushPolicy`:
|
|
144
|
+
|
|
145
|
+
| Policy | A write is durable | Use it for |
|
|
146
|
+
|---|---|---|
|
|
147
|
+
| `FlushPolicy.Coalesced(maxDelayMillis = 1000, maxWrites = 64)` (the default) | in the foreground, at most about 1 second after it returns, or at once when it's the 64th write waiting; while the app is stopped, before it returns | most apps: one commit per burst of writes |
|
|
148
|
+
| `FlushPolicy.EveryWrite` | before it returns | data the app can't lose, at the cost of a commit (a page write and a sync) per write |
|
|
149
|
+
| `FlushPolicy.Manual` | only on the events below (the behaviour before v0.12.1) | benchmarks, and apps that call `flush()` themselves |
|
|
150
|
+
|
|
151
|
+
"Stopped" is `ProcessLifecycleOwner` below `STARTED`: the app is in the
|
|
152
|
+
background, or the process started without an activity (a service, a
|
|
153
|
+
broadcast, WorkManager). A write made then commits before it returns,
|
|
154
|
+
because the process can be killed at any moment. Whatever the policy, the
|
|
155
|
+
store also commits on every `ON_STOP`, and on `flush()` and `close()`.
|
|
156
|
+
|
|
157
|
+
`withSession` batches many writes into one commit:
|
|
158
|
+
|
|
159
|
+
```kotlin
|
|
160
|
+
store.withSession { session ->
|
|
161
|
+
for ((text, vector) in notes) session.remember(text, vector)
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The calls run on one open handle with nothing else in between, and the
|
|
166
|
+
store commits once at the end (not under `Manual`). A session doesn't
|
|
167
|
+
embed, so compute the vectors first. If the block throws, the writes it
|
|
168
|
+
made stay and are committed the same way.
|
|
169
|
+
|
|
107
170
|
The names follow the Swift package where Kotlin allows. Two differ in the
|
|
108
171
|
generated layer:
|
|
109
172
|
|
|
@@ -126,8 +189,11 @@ class MyEmbedder : MnemoEmbedder {
|
|
|
126
189
|
}
|
|
127
190
|
```
|
|
128
191
|
|
|
129
|
-
- `embed`
|
|
130
|
-
on the main thread
|
|
192
|
+
- `embed` runs on the store's dispatcher before the call takes the store's
|
|
193
|
+
lock, never on the main thread. The store isn't held while it runs, so
|
|
194
|
+
other calls go ahead, and `embed` may call back into the same store.
|
|
195
|
+
(Before v0.12.1 it ran under the store's lock, so a slow model held every
|
|
196
|
+
other call.)
|
|
131
197
|
- If it throws anything, the call fails with `MnemoException.Embedder`,
|
|
132
198
|
and nothing is written. Throw `EmbedderException.Failed(reason)` to
|
|
133
199
|
choose the message.
|
|
@@ -152,11 +218,13 @@ class MyEmbedder : MnemoEmbedder {
|
|
|
152
218
|
- **Flushing.** When the app's last activity stops, `ProcessLifecycleOwner`
|
|
153
219
|
sends `ON_STOP`, about 700 ms later, and the store flushes. Every write
|
|
154
220
|
made so far is then durable, even if the process is killed in the
|
|
155
|
-
background.
|
|
221
|
+
background. From then until the next `ON_START`, each write under the
|
|
222
|
+
default policy commits before it returns (see Durability).
|
|
156
223
|
- **The file stays open.** Android doesn't kill a cached process for
|
|
157
224
|
holding a file lock, unlike iOS, so the next call needs no reopen.
|
|
158
|
-
- **Errors.** A failed background flush
|
|
159
|
-
The data written before the last
|
|
225
|
+
- **Errors.** A failed background flush, or a failed coalesced commit, is
|
|
226
|
+
kept in `lastBackgroundError`. The data written before the last
|
|
227
|
+
successful commit is safe.
|
|
160
228
|
- **Reopening.** After `close()`, or if the engine reports its handle
|
|
161
229
|
closed, the next call reopens the file transparently. No call fails with
|
|
162
230
|
`MnemoException.Closed`.
|
|
@@ -212,7 +280,7 @@ export (below), or delete the file and start over.
|
|
|
212
280
|
// On the old device: a copy that opens with the passphrase alone.
|
|
213
281
|
store.exportWithPassphrase(exportFile, passphrase)
|
|
214
282
|
|
|
215
|
-
// On the new device:
|
|
283
|
+
// On the new device: a fresh copy under a new key in this device's Keystore.
|
|
216
284
|
val store = MnemoStore.importWithPassphrase(
|
|
217
285
|
context, exportFile, passphrase,
|
|
218
286
|
MnemoStoreConfiguration(name = "assistant", dimensions = 384u),
|
|
@@ -222,7 +290,12 @@ val store = MnemoStore.importWithPassphrase(
|
|
|
222
290
|
- Both calls take a few seconds, because the passphrase goes through the
|
|
223
291
|
KDF.
|
|
224
292
|
- The destination must not exist yet, and the source is never modified.
|
|
225
|
-
-
|
|
293
|
+
- Both write a compacted copy (live data, no history) under a **fresh data
|
|
294
|
+
key**. The export shares no key material with the device's file, and the
|
|
295
|
+
imported file shares none with the export: the transfer passphrase never
|
|
296
|
+
opens the imported file, even with a leftover copy of the export.
|
|
297
|
+
- Have the user choose the passphrase. Never store it next to the export,
|
|
298
|
+
and delete the export once it's imported.
|
|
226
299
|
|
|
227
300
|
## ABIs
|
|
228
301
|
|
|
@@ -262,10 +335,12 @@ name. Nothing else is needed.
|
|
|
262
335
|
a software AES key in place of the Keystore. They need the host library
|
|
263
336
|
that `scripts/build-native.sh` puts in `generated/host/`.
|
|
264
337
|
- **Instrumented tests** (`src/androidTest`): the Android Keystore, the
|
|
265
|
-
`ON_STOP` flush through the real process lifecycle,
|
|
266
|
-
directory, and loading the native libraries on the device's
|
|
267
|
-
The `android-emulator` workflow runs them nightly and on
|
|
268
|
-
on API 35 `x86_64` images with 4 KB and 16 KB pages
|
|
338
|
+
`ON_STOP` flush and the flush policy through the real process lifecycle,
|
|
339
|
+
the default directory, and loading the native libraries on the device's
|
|
340
|
+
page size. The `android-emulator` workflow runs them nightly and on
|
|
341
|
+
release tags, on API 35 `x86_64` images with 4 KB and 16 KB pages, then
|
|
342
|
+
the sample's kill test: it writes, is force-stopped with no flush, and a
|
|
343
|
+
relaunch must find every write older than the coalescing window.
|
|
269
344
|
- **In your app's own JVM tests**, the plain JNA jar has to be on the test
|
|
270
345
|
classpath (`testImplementation("net.java.dev.jna:jna:5.19.1")`), along
|
|
271
346
|
with a host build of `libmnemo_uniffi` on `jna.library.path`.
|
{mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/release-check/settings.gradle.kts
RENAMED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// mnemo-android artifact from mavenLocal() (run the library's signed
|
|
3
3
|
// publishToMavenLocal first) and runs a JVM smoke test against it.
|
|
4
4
|
//
|
|
5
|
-
// ../gradlew -p release-check test -PmnemoVersion=0.12.
|
|
5
|
+
// ../gradlew -p release-check test -PmnemoVersion=0.12.1 \
|
|
6
6
|
// -Pjna.library.path=$PWD/generated/host
|
|
7
7
|
pluginManagement {
|
|
8
8
|
repositories {
|
{mnemo_engine-0.12.0 → mnemo_engine-0.12.1}/mnemo/bindings/kotlin/scripts/central-dry-run.sh
RENAMED
|
@@ -14,7 +14,10 @@ set -euo pipefail
|
|
|
14
14
|
|
|
15
15
|
: "${MAVEN_CENTRAL_USERNAME:?}" "${MAVEN_CENTRAL_PASSWORD:?}"
|
|
16
16
|
API=https://central.sonatype.com/api/v1/publisher
|
|
17
|
-
|
|
17
|
+
B64=$(printf '%s:%s' "$MAVEN_CENTRAL_USERNAME" "$MAVEN_CENTRAL_PASSWORD" | base64 | tr -d '\n')
|
|
18
|
+
# A derived credential GitHub's log masking doesn't know: mask it too.
|
|
19
|
+
if [ -n "${GITHUB_ACTIONS:-}" ]; then echo "::add-mask::$B64"; fi
|
|
20
|
+
AUTH="Authorization: Bearer $B64"
|
|
18
21
|
LOG="$(mktemp)"
|
|
19
22
|
trap 'rm -f "$LOG" "$LOG.body"' EXIT
|
|
20
23
|
|
|
@@ -25,6 +28,16 @@ state_of() { # deployment id -> its deploymentState (or the HTTP code)
|
|
|
25
28
|
python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["deploymentState"])' "$LOG.body"
|
|
26
29
|
}
|
|
27
30
|
|
|
31
|
+
# Central refuses a version it already has ("Component ... already
|
|
32
|
+
# exists"), so a dry run between releases (to test a workflow change, say)
|
|
33
|
+
# has nothing to validate. A release dry run runs with the next version.
|
|
34
|
+
VERSION=$(sed -n 's/^VERSION_NAME=//p' gradle.properties)
|
|
35
|
+
POM="https://repo1.maven.org/maven2/io/github/toarchkumar/mnemo-android/$VERSION/mnemo-android-$VERSION.pom"
|
|
36
|
+
if [ "$(curl -s -o /dev/null -w '%{http_code}' --max-time 30 "$POM")" = 200 ]; then
|
|
37
|
+
echo "::notice::mnemo-android $VERSION is already on Maven Central, which refuses a second upload: nothing to validate (a release dry run runs with the next version)"
|
|
38
|
+
exit 0
|
|
39
|
+
fi
|
|
40
|
+
|
|
28
41
|
echo "==> publishToMavenCentral (USER_MANAGED: upload and validate, never release)"
|
|
29
42
|
status=0
|
|
30
43
|
./gradlew --no-daemon --stacktrace publishToMavenCentral \
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
# the image should report.
|
|
9
9
|
# 2. The Android sample's R8-minified release APK: install it, launch its
|
|
10
10
|
# self-test, and check logcat for "MNEMO_SELFTEST ok" (MOBILE-1d).
|
|
11
|
+
# 3. The kill test: the same APK writes, is force-stopped with no flush,
|
|
12
|
+
# and a relaunch counts what survived (MOBILE-2b).
|
|
11
13
|
#
|
|
12
14
|
# Emulators, the 16 KB image especially, can restart the system server
|
|
13
15
|
# shortly after boot. An install then fails ("Can't find service:
|
|
@@ -79,3 +81,32 @@ for _ in $(seq 1 60); do
|
|
|
79
81
|
done
|
|
80
82
|
adb logcat -d -s MnemoSelfTest:I AndroidRuntime:E | tee selftest.log
|
|
81
83
|
grep -q "MNEMO_SELFTEST ok" selftest.log
|
|
84
|
+
|
|
85
|
+
# 3. The kill test for the default flush policy (MOBILE-2b): the sample
|
|
86
|
+
# writes, waits past the coalescing window, writes a few more, and is
|
|
87
|
+
# force-stopped with no lifecycle event. A relaunch must find every write
|
|
88
|
+
# older than the window (see DurabilityTest in the sample).
|
|
89
|
+
SETTLED=20
|
|
90
|
+
wait_for_line() { # tag, pattern, seconds
|
|
91
|
+
for _ in $(seq 1 "$3"); do
|
|
92
|
+
adb logcat -d -s "$1:I" | grep -q "$2" && return 0
|
|
93
|
+
sleep 1
|
|
94
|
+
done
|
|
95
|
+
return 1
|
|
96
|
+
}
|
|
97
|
+
# A fresh process: the self-test's activity is still on top, and an intent
|
|
98
|
+
# to it would only reach onNewIntent.
|
|
99
|
+
adb shell am force-stop io.github.toarchkumar.mnemo.sample
|
|
100
|
+
adb logcat -c
|
|
101
|
+
adb shell am start -W -n io.github.toarchkumar.mnemo.sample/.MainActivity --es durability write
|
|
102
|
+
wait_for_line MnemoDurability "MNEMO_DURABILITY \(late\|failed\)" 60 || { echo "the durability writer never finished" >&2; exit 1; }
|
|
103
|
+
adb shell am force-stop io.github.toarchkumar.mnemo.sample
|
|
104
|
+
adb logcat -d -s MnemoDurability:I | tee durability.log
|
|
105
|
+
grep -q "MNEMO_DURABILITY late" durability.log
|
|
106
|
+
adb logcat -c
|
|
107
|
+
adb shell am start -W -n io.github.toarchkumar.mnemo.sample/.MainActivity --es durability count
|
|
108
|
+
wait_for_line MnemoDurability "MNEMO_DURABILITY \(count\|failed\)" 60 || { echo "the durability reader never finished" >&2; exit 1; }
|
|
109
|
+
adb logcat -d -s MnemoDurability:I AndroidRuntime:E | tee -a durability.log
|
|
110
|
+
count=$(sed -n 's/.*MNEMO_DURABILITY count=\([0-9]*\).*/\1/p' durability.log | tail -1)
|
|
111
|
+
echo "after am force-stop: $count memories (at least $SETTLED expected)"
|
|
112
|
+
[ -n "$count" ] && [ "$count" -ge "$SETTLED" ]
|
|
@@ -109,7 +109,9 @@ class AndroidTests {
|
|
|
109
109
|
@Test fun onStopFlushesAndKeepsTheFileOpen(): Unit = runBlocking {
|
|
110
110
|
val (keystore, _) = testKeystore()
|
|
111
111
|
val dir = File(context.cacheDir, "stop-${UUID.randomUUID()}").also { cleanup += it }
|
|
112
|
-
|
|
112
|
+
// Manual, so only ON_STOP commits: the default would already have
|
|
113
|
+
// committed each write (the process is stopped: no activity yet).
|
|
114
|
+
val store = MnemoStore(context, MnemoStoreConfiguration("stop", 4u, dir, flushPolicy = FlushPolicy.Manual), keystore)
|
|
113
115
|
// The observer is added on the main thread; wait for it.
|
|
114
116
|
InstrumentationRegistry.getInstrumentation().runOnMainSync {}
|
|
115
117
|
for (i in 0 until 3) store.remember("pending $i", vec(i))
|
|
@@ -134,6 +136,32 @@ class AndroidTests {
|
|
|
134
136
|
store.close()
|
|
135
137
|
}
|
|
136
138
|
|
|
139
|
+
@Test fun theDefaultPolicyFollowsTheProcessLifecycle(): Unit = runBlocking {
|
|
140
|
+
val keys = InMemoryKeyStorage()
|
|
141
|
+
val dir = File(context.cacheDir, "policy-${UUID.randomUUID()}").also { cleanup += it }
|
|
142
|
+
val store = MnemoStore(context, MnemoStoreConfiguration("policy", 4u, dir), keys)
|
|
143
|
+
InstrumentationRegistry.getInstrumentation().runOnMainSync {}
|
|
144
|
+
// No activity: the process is stopped, and a write commits before it
|
|
145
|
+
// returns. (An earlier test's activity may still be stopping: ON_STOP
|
|
146
|
+
// comes about 700 ms after it.)
|
|
147
|
+
assertTrue(eventually(10_000) { processState() == Lifecycle.State.CREATED && store.processStopped })
|
|
148
|
+
store.remember("stopped", vec(0))
|
|
149
|
+
assertEquals(1, store.commits)
|
|
150
|
+
assertCopyHolds(store.file, keys, 1uL)
|
|
151
|
+
|
|
152
|
+
// An activity started: ON_START, and writes coalesce again.
|
|
153
|
+
val scenario = ActivityScenario.launch(TestActivity::class.java)
|
|
154
|
+
scenario.moveToState(Lifecycle.State.RESUMED)
|
|
155
|
+
assertTrue("ON_START reached the store", eventually { !store.processStopped })
|
|
156
|
+
store.remember("started", vec(1))
|
|
157
|
+
assertEquals("not committed yet", 1, store.commits)
|
|
158
|
+
assertTrue("committed within the window", eventually(5_000) { store.commits == 2 })
|
|
159
|
+
assertCopyHolds(store.file, keys, 2uL)
|
|
160
|
+
scenario.close()
|
|
161
|
+
assertTrue("ON_STOP reached the store", eventually(10_000) { store.processStopped })
|
|
162
|
+
store.close()
|
|
163
|
+
}
|
|
164
|
+
|
|
137
165
|
@Test fun theNativeLibraryLoadsOnThisPageSize(): Unit = runBlocking {
|
|
138
166
|
val pageSize = Os.sysconf(OsConstants._SC_PAGESIZE)
|
|
139
167
|
Log.i(TAG, "page size $pageSize, API ${Build.VERSION.SDK_INT}, ABIs ${Build.SUPPORTED_ABIS.joinToString()}")
|
mnemo_engine-0.12.1/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/FlushPolicy.kt
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
package io.github.toarchkumar.mnemo
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* When a [MnemoStore] commits its writes to disk on its own.
|
|
5
|
+
*
|
|
6
|
+
* A write is durable once it's committed: a crash, a kill (`am force-stop`,
|
|
7
|
+
* the low-memory killer) or a power loss after that keeps it. Before that,
|
|
8
|
+
* it's in memory only. Whatever the policy, the store also commits on every
|
|
9
|
+
* `ON_STOP`, and on [MnemoStore.flush] and [MnemoStore.close].
|
|
10
|
+
*/
|
|
11
|
+
sealed class FlushPolicy {
|
|
12
|
+
/**
|
|
13
|
+
* The default. The first write after a commit starts a timer, and the
|
|
14
|
+
* store commits once when it fires ([maxDelayMillis] later) or as soon as
|
|
15
|
+
* [maxWrites] writes are waiting, whichever comes first. A write made
|
|
16
|
+
* while the app is in the foreground is durable at most about
|
|
17
|
+
* [maxDelayMillis] after it returns. While the app is stopped (in the
|
|
18
|
+
* background, or started without an activity), each write commits
|
|
19
|
+
* before it returns.
|
|
20
|
+
*/
|
|
21
|
+
data class Coalesced(val maxDelayMillis: Long = 1_000, val maxWrites: Int = 64) : FlushPolicy()
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Every write commits before it returns. The safest, and the slowest for
|
|
25
|
+
* bursts: each commit writes and syncs pages.
|
|
26
|
+
*/
|
|
27
|
+
data object EveryWrite : FlushPolicy()
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The store commits only on the events above (the behaviour before
|
|
31
|
+
* v0.12.1). For benchmarks, and for apps that call [MnemoStore.flush]
|
|
32
|
+
* themselves.
|
|
33
|
+
*/
|
|
34
|
+
data object Manual : FlushPolicy()
|
|
35
|
+
|
|
36
|
+
companion object {
|
|
37
|
+
/** `Coalesced(maxDelayMillis = 1000, maxWrites = 64)`. */
|
|
38
|
+
@JvmField
|
|
39
|
+
val DEFAULT: FlushPolicy = Coalesced()
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A batch of calls on one open handle, from [MnemoStore.withSession].
|
|
45
|
+
*
|
|
46
|
+
* The calls run in order on the store's handle, with no other call in
|
|
47
|
+
* between, and the store commits once at the end. A session doesn't embed:
|
|
48
|
+
* pass vectors (embed first, then open the session). It's valid only inside
|
|
49
|
+
* the block it was passed to; afterwards every call throws
|
|
50
|
+
* [MnemoException.Closed].
|
|
51
|
+
*/
|
|
52
|
+
class MnemoSession internal constructor(private val db: MnemoDb) {
|
|
53
|
+
@Volatile private var ended = false
|
|
54
|
+
|
|
55
|
+
/** The writes made in this session. */
|
|
56
|
+
@Volatile internal var writes = 0
|
|
57
|
+
private set
|
|
58
|
+
|
|
59
|
+
internal fun end() {
|
|
60
|
+
ended = true
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private fun handle(write: Boolean): MnemoDb {
|
|
64
|
+
if (ended) throw MnemoException.Closed()
|
|
65
|
+
if (write) writes += 1
|
|
66
|
+
return db
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Stores a memory with its vector. */
|
|
70
|
+
fun remember(content: String, vector: List<Float>, options: RememberOptions = RememberOptions()): WriteResult =
|
|
71
|
+
handle(true).remember(content, vector, options)
|
|
72
|
+
|
|
73
|
+
/** Changes fields of a memory. A content change needs its vector in the patch: a session doesn't embed. */
|
|
74
|
+
fun update(id: String, patch: MemoryPatch): WriteOutcome {
|
|
75
|
+
if (patch.content != null && patch.vector == null) {
|
|
76
|
+
throw MnemoException.Invalid("a session doesn't embed: a content change needs its vector in the patch")
|
|
77
|
+
}
|
|
78
|
+
return handle(true).update(id, patch)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Deletes a memory. */
|
|
82
|
+
fun delete(id: String) = handle(true).delete(id)
|
|
83
|
+
|
|
84
|
+
/** One memory by id. */
|
|
85
|
+
fun get(id: String): MemoryRecord = handle(false).get(id)
|
|
86
|
+
|
|
87
|
+
/** Recall by vector. */
|
|
88
|
+
fun recall(vector: List<Float>, options: RecallOptions = RecallOptions()): RecallPage =
|
|
89
|
+
handle(false).recall(vector, options)
|
|
90
|
+
|
|
91
|
+
/** The number of live memories. */
|
|
92
|
+
fun count(): ULong = handle(false).len()
|
|
93
|
+
|
|
94
|
+
/** Stores a value in the result cache. */
|
|
95
|
+
fun cachePut(namespace: String, key: String, value: ByteArray, ttlSecs: ULong? = null) =
|
|
96
|
+
handle(true).cachePut(namespace, key, value, ttlSecs)
|
|
97
|
+
|
|
98
|
+
/** A cached value, or `null`. */
|
|
99
|
+
fun cacheGet(namespace: String, key: String): ByteArray? = handle(false).cacheGet(namespace, key)
|
|
100
|
+
}
|