hakua-memory 0.3.4__tar.gz → 0.4.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 (78) hide show
  1. hakua_memory-0.4.0/MANIFEST.in +3 -0
  2. {hakua_memory-0.3.4/src/hakua_memory.egg-info → hakua_memory-0.4.0}/PKG-INFO +175 -40
  3. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/README.md +172 -39
  4. hakua_memory-0.4.0/docs/memory45-pair.md +55 -0
  5. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/pyproject.toml +9 -2
  6. hakua_memory-0.4.0/scripts/benchmark_cross_validation.py +194 -0
  7. hakua_memory-0.4.0/scripts/synthetic_dataset.py +42 -0
  8. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/composite.py +190 -34
  9. hakua_memory-0.4.0/src/hakua_memory/data/memory45_scopes.json +144 -0
  10. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/ebbinghaus/experience.py +3 -1
  11. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/ebbinghaus/store.py +99 -3
  12. hakua_memory-0.4.0/src/hakua_memory/handoff.py +44 -0
  13. hakua_memory-0.4.0/src/hakua_memory/memory45.py +124 -0
  14. hakua_memory-0.4.0/src/hakua_memory/memory45_pair.py +97 -0
  15. hakua_memory-0.4.0/src/hakua_memory/memory45_recall.py +81 -0
  16. hakua_memory-0.4.0/src/hakua_memory/memory45_refit.py +84 -0
  17. hakua_memory-0.4.0/src/hakua_memory/memory45_scope.py +110 -0
  18. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/rag/chunking.py +26 -13
  19. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/rag/retrieval.py +4 -2
  20. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/rag/schema.py +2 -2
  21. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/rag/store.py +160 -45
  22. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/semantic_graph/embedding/__init__.py +2 -0
  23. hakua_memory-0.4.0/src/hakua_memory/semantic_graph/embedding/gguf_local.py +125 -0
  24. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/semantic_graph/retrieval.py +123 -12
  25. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/semantic_graph/store.py +119 -38
  26. {hakua_memory-0.3.4 → hakua_memory-0.4.0/src/hakua_memory.egg-info}/PKG-INFO +175 -40
  27. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory.egg-info/SOURCES.txt +20 -1
  28. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/tests/test_benchmark.py +6 -2
  29. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/tests/test_config.py +2 -1
  30. hakua_memory-0.4.0/tests/test_handoff_cli.py +35 -0
  31. hakua_memory-0.4.0/tests/test_identity_continuity.py +68 -0
  32. hakua_memory-0.4.0/tests/test_memory45_pair.py +105 -0
  33. hakua_memory-0.4.0/tests/test_memory45_scope.py +73 -0
  34. hakua_memory-0.4.0/tests/test_portable_sleep.py +109 -0
  35. hakua_memory-0.4.0/tests/test_sleep_consolidation.py +496 -0
  36. hakua_memory-0.4.0/tests/test_speculative_hybrid.py +131 -0
  37. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/LICENSE +0 -0
  38. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/setup.cfg +0 -0
  39. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/__init__.py +0 -0
  40. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/config.py +0 -0
  41. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/ebbinghaus/__init__.py +0 -0
  42. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/ebbinghaus/migrations.py +0 -0
  43. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/ebbinghaus/models.py +0 -0
  44. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/ebbinghaus/policies.py +0 -0
  45. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/ebbinghaus/semantic_graph_bridge.py +0 -0
  46. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/obsidian/__init__.py +0 -0
  47. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/obsidian/templates.py +0 -0
  48. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/rag/__init__.py +0 -0
  49. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/rag/contradiction.py +0 -0
  50. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/rag/ingestion.py +0 -0
  51. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/rag/meeting.py +0 -0
  52. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/rag/models.py +0 -0
  53. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/semantic_graph/__init__.py +0 -0
  54. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/semantic_graph/cli.py +0 -0
  55. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/semantic_graph/cognitive.py +0 -0
  56. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/semantic_graph/config.py +0 -0
  57. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/semantic_graph/embedding/base.py +0 -0
  58. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/semantic_graph/embedding/fake.py +0 -0
  59. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/semantic_graph/embedding/llama_cpp.py +0 -0
  60. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/semantic_graph/embedding/serializer.py +0 -0
  61. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/semantic_graph/embedding/vectors.py +0 -0
  62. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/semantic_graph/exporter.py +0 -0
  63. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/semantic_graph/fusion.py +0 -0
  64. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/semantic_graph/graph.py +0 -0
  65. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/semantic_graph/inference.py +0 -0
  66. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/semantic_graph/models.py +0 -0
  67. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/semantic_graph/runtime.py +0 -0
  68. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/semantic_graph/sanitize.py +0 -0
  69. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory/semantic_graph/schemas.py +0 -0
  70. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory.egg-info/dependency_links.txt +0 -0
  71. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory.egg-info/requires.txt +0 -0
  72. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/src/hakua_memory.egg-info/top_level.txt +0 -0
  73. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/tests/test_acl.py +0 -0
  74. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/tests/test_composite.py +0 -0
  75. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/tests/test_ebbinghaus.py +0 -0
  76. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/tests/test_embedding_backend.py +0 -0
  77. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/tests/test_integration.py +0 -0
  78. {hakua_memory-0.3.4 → hakua_memory-0.4.0}/tests/test_obsidian.py +0 -0
@@ -0,0 +1,3 @@
1
+ include docs/memory45-pair.md
2
+ include scripts/benchmark_cross_validation.py
3
+ include scripts/synthetic_dataset.py
@@ -1,9 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hakua-memory
3
- Version: 0.3.4
3
+ Version: 0.4.0
4
4
  Summary: Composite memory library: Ebbinghaus + Semantic Graph + RAG + Obsidian Wiki
5
5
  Author: Hakua
6
6
  License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/zapabob/hakua-memory
8
+ Project-URL: Documentation, https://zapabob.github.io/hakua-memory/
7
9
  Requires-Python: <3.14,>=3.11
8
10
  Description-Content-Type: text/markdown
9
11
  License-File: LICENSE
@@ -33,6 +35,8 @@ Dynamic: license-file
33
35
 
34
36
  ## Install
35
37
 
38
+ Version 0.4.0 adds model-independent identity handoff and bilingual Memory45 recall. With compatible external models and writers, both the compact Mini VLT and Qwen3.5-2B can load the same approved revision through model-specific stock LoRA adapters. See [the Memory45 guide](https://github.com/zapabob/hakua-memory/blob/main/docs/memory45-pair.md).
39
+
36
40
  ```bash
37
41
  pip install hakua-memory
38
42
  ```
@@ -125,6 +129,8 @@ memory = CompositeMemory(Path("~/.hakua-memory").expanduser())
125
129
  memory.remember(
126
130
  "The user prefers concise, verifiable reports.",
127
131
  tags=["user-preference", "communication"],
132
+ salience=0.9,
133
+ valence=0.2,
128
134
  )
129
135
 
130
136
  matches = memory.recall("verifiable reports")
@@ -287,68 +293,132 @@ results. Values depend on the recorded machine, dataset, seed, warmup, and repet
287
293
  The optional comparison harness uses the same corpus, query set, warmup count, repetition
288
294
  count, and randomized variant order for every paired measurement. It compares RAG
289
295
  chunking with LangChain's `RecursiveCharacterTextSplitter` and LlamaIndex's
290
- `SentenceSplitter`, and compares the Semantic Graph lexical query path with
291
- `rank-bm25`'s `BM25Okapi`. The comparison is limited to those operations; it is not a
292
- claim about complete RAG quality, end-to-end agent latency, memory use, or GPU speed.
296
+ `SentenceSplitter`, and compares CoG/retrieval peers across hakua lexical search,
297
+ hakua hybrid GGUF search, `rank-bm25`, LangChain BM25, LlamaIndex BM25, and
298
+ FAISS+same-GGUF dense retrieval. Multi-group Friedman tests and all-pairs
299
+ Wilcoxon/Holm corrections are recorded. This is not a claim about complete RAG quality,
300
+ end-to-end agent latency, memory use, or general library superiority.
293
301
 
294
302
  Create a separate environment and run the comparison as follows:
295
303
 
296
304
  ```bash
297
305
  python -m venv .venv-benchmark
298
306
  # Activate .venv-benchmark for your shell, then run:
299
- python -m pip install -e .
307
+ python -m pip install -e ".[embedding]"
300
308
  python -m pip install -r benchmarks/requirements.txt
301
309
  python scripts/generate_synthetic_data.py --seed 42 --samples 40 --output synthetic_business_dataset.json
302
- python scripts/benchmark_external_libraries.py --seed 42 --samples 40 --warmup 5 --repetitions 30 --output benchmark-results-external.json --plot benchmark-errorbars.png
310
+ python scripts/benchmark_external_libraries.py --seed 42 --samples 40 --warmup 2 --repetitions 10 --output benchmark-results-external.json --plot benchmark-errorbars.png
311
+ python scripts/benchmark_speculative_hybrid.py --samples 30 --warmup 1 --repetitions 8 --output speculative-hybrid-3group.json --plot speculative-hybrid-3group.png
303
312
  ```
304
313
 
305
314
  The comparison JSON records exact library versions, host metadata, configurations, raw
306
315
  paired durations, mean, median, standard deviation, p50, p95, p99, and a 95% confidence
307
- interval for each variant. It also records the two-sided paired Wilcoxon signed-rank
308
- test, paired t-test sensitivity result, and Holm-adjusted Wilcoxon p-value across the
309
- three comparisons. The PNG uses mean latency with 95% confidence-interval error bars.
310
- The validation section separately records non-empty chunk output and expected top-k hit
311
- rate, so latency and retrieval-result checks are not conflated.
316
+ interval for each variant. It also records Friedman chi-square multi-group tests,
317
+ two-sided paired Wilcoxon signed-rank tests, paired t-test sensitivity, and Holm-adjusted
318
+ Wilcoxon p-values across all pairwise comparisons. The PNG uses mean latency with 95%
319
+ confidence-interval error bars. The validation section separately records non-empty chunk
320
+ output and expected top-k hit rate, so latency and retrieval-result checks are not
321
+ conflated.
312
322
 
313
323
  The chunkers use their native length units, which are recorded in the JSON; equal numeric
314
- chunk-size arguments therefore do not mean equal chunk boundaries. The lexical comparison
315
- also compares SQLite-backed graph search with an in-memory BM25 index. These scope limits
316
- are required for an honest cross-library measurement.
324
+ chunk-size arguments therefore do not mean equal chunk boundaries. Lexical peers compare
325
+ SQLite-backed graph search with in-memory BM25 indexes. Dense peers use the same local
326
+ GGUF embedding model (`nsfw-bge-m3-v5-q6_k`, 1024-d) via `llama-cpp-python`. These scope
327
+ limits are required for an honest cross-library measurement.
317
328
 
318
- The following is one recorded run from commit `e2bbb3c8bfd3bbfcd7a5e508a757917919dd5e89`
319
- on Windows 11 with Python 3.12.13 and an AMD64 Family 23 Model 96 CPU. It used
320
- `synthetic-business-v1`, seed 42, 40 samples, 40 queries, warmup 5, and 30 paired
321
- repetitions. Latencies are milliseconds per operation; the confidence interval is 95% CI
322
- for the mean.
329
+ The following is one recorded 0.3.5 run from commit `62c8c6054bae` on Windows 11 with
330
+ Python 3.12.10, an AMD64 Family 23 Model 96 CPU, and CUDA via `llama-cpp` (`n_gpu_layers=-1`).
331
+ It used `synthetic-business-v1`, seed 42, 40 samples / 40 queries, warmup 2, and 10 paired
332
+ repetitions. Latencies are milliseconds; CoG rows are milliseconds per complete 40-query
333
+ batch. The confidence interval is the 95% CI for the mean.
323
334
 
324
335
  | Operation | Variant | Mean | Median | Stdev | P95 | 95% CI |
325
336
  |---|---|---:|---:|---:|---:|---:|
326
- | RAG chunking | hakua-memory | 0.6312 | 0.5901 | 0.1184 | 0.8746 | 0.5870–0.6754 |
327
- | RAG chunking | LangChain Text Splitters 1.1.2 | 0.0694 | 0.0681 | 0.0144 | 0.0854 | 0.0640–0.0747 |
328
- | RAG chunking | LlamaIndex Core 0.14.24 | 1.8174 | 1.6806 | 0.3354 | 2.4531 | 1.6921–1.9426 |
329
- | Lexical retrieval, 40-query batch | hakua-memory | 264.2875 | 155.3723 | 487.9654 | 397.6564 | 82.0782–446.4968 |
330
- | Lexical retrieval, 40-query batch | rank-bm25 0.2.2 | 2.5974 | 2.4707 | 0.3772 | 3.0580 | 2.4566–2.7382 |
331
-
332
- The paired two-sided Wilcoxon signed-rank p-values were `1.862645149e-09` for each
333
- comparison. Holm-adjusted values across the three comparisons were `5.587935448e-09`
334
- for each comparison. Paired t-test sensitivity p-values were `1.387202830e-21` for
335
- LangChain, `4.399465113e-19` for LlamaIndex, and `0.006427546` for rank-bm25. These
336
- p-values describe this paired latency sample only; they are not accuracy claims or proof
337
- of general library superiority.
338
-
339
- The dataset-specific validation found non-empty chunk output for all variants. The
340
- expected exact-record hit rate at top-k=5 was 33/40 (82.5%) for hakua-memory and 38/40
341
- (95.0%) for rank-bm25. This is a small synthetic query-set check, not a benchmark of
342
- retrieval quality across domains. The generated JSON and error-bar PNG are intentionally
343
- kept outside Git; rerun the command above to reproduce them on another machine.
337
+ | RAG chunking | hakua-memory | 1.0630 | 1.0358 | 0.1563 | 1.3290 | 0.9513–1.1748 |
338
+ | RAG chunking | LangChain Text Splitters | 0.1130 | 0.1185 | 0.0168 | 0.1329 | 0.1009–0.1250 |
339
+ | RAG chunking | LlamaIndex Core | 2.2198 | 2.1212 | 0.3185 | 2.6825 | 1.9919–2.4477 |
340
+ | CoG retrieval batch | hakua lexical | 45.5863 | 47.3555 | 7.6094 | 56.0006 | 40.1429–51.0297 |
341
+ | CoG retrieval batch | rank-bm25 | 4.2935 | 3.6322 | 2.2569 | 7.9821 | 2.6790–5.9080 |
342
+ | CoG retrieval batch | LangChain BM25 | 6.5765 | 5.6572 | 2.8180 | 11.2159 | 4.5606–8.5924 |
343
+ | CoG retrieval batch | LlamaIndex BM25 | 40.3695 | 39.8424 | 10.2176 | 52.1031 | 33.0602–47.6787 |
344
+ | CoG retrieval batch | hakua hybrid GGUF | 31519.2576 | 25784.8628 | 13763.0641 | 57242.3898 | 21673.7546–41364.7606 |
345
+ | CoG retrieval batch | FAISS + same GGUF | 16617.3399 | 14470.4271 | 9264.0809 | 31038.2213 | 9990.2156–23244.4642 |
346
+
347
+ #### Multi-group Friedman p-values
348
+
349
+ | Operation | Groups (n) | Friedman χ² | p-value | Reject H₀ (α=0.05) |
350
+ |---|---|---:|---:|---|
351
+ | RAG chunking | 3 | 20.0 | 4.540e-05 | yes |
352
+ | CoG retrieval batch | 6 | 47.6 | 4.286e-09 | yes |
353
+
354
+ #### Pairwise Wilcoxon / Holm / paired-t p-values (RAG chunking)
355
+
356
+ | Primary | Comparator | Wilcoxon p | Holm-adjusted Wilcoxon p | Paired-t p |
357
+ |---|---|---:|---:|---:|
358
+ | hakua-memory | LangChain Text Splitters | 0.001953 | 0.035156 | 1.366e-08 |
359
+ | hakua-memory | LlamaIndex Core | 0.001953 | 0.035156 | 3.434e-06 |
360
+ | LangChain Text Splitters | LlamaIndex Core | 0.001953 | 0.035156 | 7.409e-09 |
361
+
362
+ #### Pairwise Wilcoxon / Holm / paired-t p-values (CoG retrieval batch)
363
+
364
+ | Primary | Comparator | Wilcoxon p | Holm-adjusted Wilcoxon p | Paired-t p |
365
+ |---|---|---:|---:|---:|
366
+ | hakua lexical | rank-bm25 | 0.001953 | 0.035156 | 2.450e-08 |
367
+ | hakua lexical | LangChain BM25 | 0.001953 | 0.035156 | 4.766e-08 |
368
+ | hakua lexical | LlamaIndex BM25 | 0.193359 | 0.193359 | 0.137301 |
369
+ | hakua lexical | hakua hybrid GGUF | 0.001953 | 0.035156 | 4.913e-05 |
370
+ | hakua lexical | FAISS + same GGUF | 0.001953 | 0.035156 | 0.000310 |
371
+ | rank-bm25 | LangChain BM25 | 0.005859 | 0.035156 | 0.001648 |
372
+ | rank-bm25 | LlamaIndex BM25 | 0.001953 | 0.035156 | 5.045e-07 |
373
+ | rank-bm25 | hakua hybrid GGUF | 0.001953 | 0.035156 | 4.862e-05 |
374
+ | rank-bm25 | FAISS + same GGUF | 0.001953 | 0.035156 | 0.000305 |
375
+ | LangChain BM25 | LlamaIndex BM25 | 0.001953 | 0.035156 | 4.817e-07 |
376
+ | LangChain BM25 | hakua hybrid GGUF | 0.001953 | 0.035156 | 4.861e-05 |
377
+ | LangChain BM25 | FAISS + same GGUF | 0.001953 | 0.035156 | 0.000306 |
378
+ | LlamaIndex BM25 | hakua hybrid GGUF | 0.001953 | 0.035156 | 4.890e-05 |
379
+ | LlamaIndex BM25 | FAISS + same GGUF | 0.001953 | 0.035156 | 0.000310 |
380
+ | hakua hybrid GGUF | FAISS + same GGUF | 0.037109 | 0.074219 | 0.018810 |
381
+
382
+ These p-values describe this paired latency sample only; they are not accuracy claims or
383
+ proof of general library superiority. Holm correction is applied across all pairwise
384
+ Wilcoxon tests emitted by the harness for that operation family.
385
+
386
+ Dataset-specific validation found non-empty chunk output for all chunkers. Exact-record
387
+ hit rate at top-k=5 was 33/40 (82.5%) for hakua lexical and hakua hybrid GGUF, 38/40
388
+ (95.0%) for rank-bm25 and LangChain BM25, 39/40 (97.5%) for LlamaIndex BM25, and 18/40
389
+ (45.0%) for FAISS+GGUF on this synthetic set. This is a small query-set check, not a
390
+ cross-domain retrieval-quality benchmark. Generated JSON/PNG stay outside Git; rerun the
391
+ commands above to reproduce on another machine.
392
+
393
+ ### Speculative-hybrid three-group Friedman
394
+
395
+ `scripts/benchmark_speculative_hybrid.py` compares `lexical_only`, `always_hybrid`, and
396
+ `speculative_hybrid` on the same corpus after sweeping `min_top_score` (primary early-accept
397
+ gate; absolute `final_score` margins often collapse on uniform confidence/salience data).
398
+ One recorded run (seed 42, 30 samples, warmup 1, 8 repetitions) chose Pareto
399
+ `min_top_score=0.40` (hit-rate tied with hybrid at 0.800; minimum latency). An interior
400
+ early-accept candidate near 50% was `min_top_score=0.55` (early-accept rate ≈ 0.367).
401
+ Mean latencies at the Pareto gate: lexical 56.8 ms, speculative 58.3 ms, always-hybrid
402
+ 22800.2 ms.
403
+
404
+ | Test | Statistic | p-value | Reject H₀ (α=0.05) |
405
+ |---|---:|---:|---|
406
+ | Friedman χ² (3 groups) | 12.0 | 0.002479 | yes |
407
+
408
+ | Primary | Comparator | Wilcoxon p | Holm-adjusted Wilcoxon p | Paired-t p |
409
+ |---|---|---:|---:|---:|
410
+ | lexical_only | always_hybrid | 0.007812 | 0.023438 | 1.371e-06 |
411
+ | lexical_only | speculative_hybrid | 0.843750 | 0.843750 | 0.660915 |
412
+ | always_hybrid | speculative_hybrid | 0.007812 | 0.023438 | 1.369e-06 |
344
413
 
345
414
  ### External references
346
415
 
347
416
  The measured comparison uses [LangChain Text Splitters](https://docs.langchain.com/oss/python/integrations/splitters/recursive_text_splitter),
348
417
  [LlamaIndex SentenceSplitter](https://docs.llamaindex.ai/en/stable/module_guides/loading/node_parsers/modules.html),
349
- and [rank-bm25](https://pypi.org/project/rank-bm25/), with versions pinned in
350
- `benchmarks/requirements.txt`. NetworkX, PyTorch Geometric, and FAISS remain external
351
- references only; this repository does not publish direct measurements for them.
418
+ [rank-bm25](https://pypi.org/project/rank-bm25/), LangChain/LlamaIndex BM25 retrievers,
419
+ and [FAISS](https://github.com/facebookresearch/faiss) with versions pinned in
420
+ `benchmarks/requirements.txt`. NetworkX and PyTorch Geometric remain external references
421
+ only; this repository does not publish direct measurements for them.
352
422
 
353
423
  ## Reproducible synthetic data
354
424
 
@@ -413,3 +483,68 @@ The integration path can be exercised with a temporary directory and the determi
413
483
  ## License
414
484
 
415
485
  Apache License 2.0. See [LICENSE](LICENSE).
486
+ # Model-independent continuity
487
+
488
+ Keep a host-authorized identity UUID across model switches. Open the same local root
489
+ and UUID for both models, save confirmed persona preferences as `portable_persona`
490
+ and transferable episodes as `portable_episode`. Each new generation can request a
491
+ fresh snapshot. The snapshot contains the current text, stable belief ID, version
492
+ and source. Pass it only to a model authorized to receive that identity's records.
493
+
494
+ ```python
495
+ from hakua_memory.composite import CompositeMemory
496
+
497
+ memory = CompositeMemory.for_identity(root, identity_uuid)
498
+ try:
499
+ entry = memory.remember("I prefer short replies.", memory_type="portable_persona",
500
+ source="user")
501
+ snapshot = memory.continuity()
502
+ finally:
503
+ memory.close()
504
+ ```
505
+
506
+ Use the existing `revise_memory` and `retract_memory` on the scoped Ebbinghaus
507
+ store for corrections and deletions. Regenerate the snapshot and discard earlier
508
+ message context when switching revisions. Retraction excludes the entry from
509
+ future snapshots. The local revision history and copies already given to a model
510
+ have separate lifetimes. UUIDs select a namespace, and the host controls access.
511
+ Each model can use its own tokenizer and weights. By default the snapshot contains
512
+ only persona entries. To hand over an episode, pass its stable belief ID in
513
+ `continuity(episode_beliefs=(entry["belief_id"],))` after authorizing the request.
514
+ Persona entries appear first within the requested limit,
515
+ and `truncated` reports whether more eligible entries exist.
516
+ For a chat integration, use `memory.continuity_message(episode_beliefs=approved_ids)`
517
+ to render the same selection into one system message. It separates persona preferences
518
+ from current episodes and omits database IDs. Only trust user-authorized persona entries
519
+ with this role. Use a fresh message when reopening or revising a conversation.
520
+ Pass `include_provenance=True` to include the scoped identity, belief IDs, versions
521
+ and sources. This emits the original record representation for models qualified with it.
522
+
523
+ In a synthetic local CPU trial, Inkling‑2‑Mini v3.1 IQ3_S retained the requested
524
+ punctuation after a deletion with the full record view. Its compact view reached
525
+ the generation limit on one of two punctuation checks. Qwen3.5-2B Q8_0 omitted
526
+ a saved exclamation mark once with the full view and passed both compact-view
527
+ checks. Test the representation on the specific model that will receive it.
528
+
529
+ To switch GGUFs, keep the same store root, identity UUID and approved belief IDs.
530
+ Generate a fresh request body for the new server's model alias on each turn:
531
+
532
+ ```powershell
533
+ python -m hakua_memory.handoff --root $root --identity $identity --model $modelAlias --episode $beliefId --question '前回決めた名前は?'
534
+ ```
535
+
536
+ The command prints JSON for a chat-completions client. It opens an existing identity
537
+ and includes only current authorized records and the new question. Omit `--episode`
538
+ to carry persona alone. Use `--with-provenance` for a recipient that needs the full
539
+ record representation. The target server applies its own tokenizer and chat template
540
+ and must accept system and user messages. Discard old chat history on a handoff.
541
+
542
+ At the end of a session, call `memory.ebbinghaus.sleep_portable_episodes(limit=256)`
543
+ on the scoped identity. This reviews the least recently examined current episodes first.
544
+ It uses the existing exponential retention curve and configurable sleep thresholds.
545
+ By default, a protected or high-salience episode (at least 0.80) is rehearsed when
546
+ retention falls to 0.35. An unprotected lower-salience episode becomes latent at 0.10.
547
+ Latent episodes disappear from subsequent continuity requests. Persona records,
548
+ retracted beliefs and superseded revisions are outside this pass. The returned IDs
549
+ identify rehearsed and newly latent episodes. Source history remains available for
550
+ audit. Weight-based readers must rebuild and reload their snapshot to see a change.
@@ -4,6 +4,8 @@
4
4
 
5
5
  ## Install
6
6
 
7
+ Version 0.4.0 adds model-independent identity handoff and bilingual Memory45 recall. With compatible external models and writers, both the compact Mini VLT and Qwen3.5-2B can load the same approved revision through model-specific stock LoRA adapters. See [the Memory45 guide](https://github.com/zapabob/hakua-memory/blob/main/docs/memory45-pair.md).
8
+
7
9
  ```bash
8
10
  pip install hakua-memory
9
11
  ```
@@ -96,6 +98,8 @@ memory = CompositeMemory(Path("~/.hakua-memory").expanduser())
96
98
  memory.remember(
97
99
  "The user prefers concise, verifiable reports.",
98
100
  tags=["user-preference", "communication"],
101
+ salience=0.9,
102
+ valence=0.2,
99
103
  )
100
104
 
101
105
  matches = memory.recall("verifiable reports")
@@ -258,68 +262,132 @@ results. Values depend on the recorded machine, dataset, seed, warmup, and repet
258
262
  The optional comparison harness uses the same corpus, query set, warmup count, repetition
259
263
  count, and randomized variant order for every paired measurement. It compares RAG
260
264
  chunking with LangChain's `RecursiveCharacterTextSplitter` and LlamaIndex's
261
- `SentenceSplitter`, and compares the Semantic Graph lexical query path with
262
- `rank-bm25`'s `BM25Okapi`. The comparison is limited to those operations; it is not a
263
- claim about complete RAG quality, end-to-end agent latency, memory use, or GPU speed.
265
+ `SentenceSplitter`, and compares CoG/retrieval peers across hakua lexical search,
266
+ hakua hybrid GGUF search, `rank-bm25`, LangChain BM25, LlamaIndex BM25, and
267
+ FAISS+same-GGUF dense retrieval. Multi-group Friedman tests and all-pairs
268
+ Wilcoxon/Holm corrections are recorded. This is not a claim about complete RAG quality,
269
+ end-to-end agent latency, memory use, or general library superiority.
264
270
 
265
271
  Create a separate environment and run the comparison as follows:
266
272
 
267
273
  ```bash
268
274
  python -m venv .venv-benchmark
269
275
  # Activate .venv-benchmark for your shell, then run:
270
- python -m pip install -e .
276
+ python -m pip install -e ".[embedding]"
271
277
  python -m pip install -r benchmarks/requirements.txt
272
278
  python scripts/generate_synthetic_data.py --seed 42 --samples 40 --output synthetic_business_dataset.json
273
- python scripts/benchmark_external_libraries.py --seed 42 --samples 40 --warmup 5 --repetitions 30 --output benchmark-results-external.json --plot benchmark-errorbars.png
279
+ python scripts/benchmark_external_libraries.py --seed 42 --samples 40 --warmup 2 --repetitions 10 --output benchmark-results-external.json --plot benchmark-errorbars.png
280
+ python scripts/benchmark_speculative_hybrid.py --samples 30 --warmup 1 --repetitions 8 --output speculative-hybrid-3group.json --plot speculative-hybrid-3group.png
274
281
  ```
275
282
 
276
283
  The comparison JSON records exact library versions, host metadata, configurations, raw
277
284
  paired durations, mean, median, standard deviation, p50, p95, p99, and a 95% confidence
278
- interval for each variant. It also records the two-sided paired Wilcoxon signed-rank
279
- test, paired t-test sensitivity result, and Holm-adjusted Wilcoxon p-value across the
280
- three comparisons. The PNG uses mean latency with 95% confidence-interval error bars.
281
- The validation section separately records non-empty chunk output and expected top-k hit
282
- rate, so latency and retrieval-result checks are not conflated.
285
+ interval for each variant. It also records Friedman chi-square multi-group tests,
286
+ two-sided paired Wilcoxon signed-rank tests, paired t-test sensitivity, and Holm-adjusted
287
+ Wilcoxon p-values across all pairwise comparisons. The PNG uses mean latency with 95%
288
+ confidence-interval error bars. The validation section separately records non-empty chunk
289
+ output and expected top-k hit rate, so latency and retrieval-result checks are not
290
+ conflated.
283
291
 
284
292
  The chunkers use their native length units, which are recorded in the JSON; equal numeric
285
- chunk-size arguments therefore do not mean equal chunk boundaries. The lexical comparison
286
- also compares SQLite-backed graph search with an in-memory BM25 index. These scope limits
287
- are required for an honest cross-library measurement.
293
+ chunk-size arguments therefore do not mean equal chunk boundaries. Lexical peers compare
294
+ SQLite-backed graph search with in-memory BM25 indexes. Dense peers use the same local
295
+ GGUF embedding model (`nsfw-bge-m3-v5-q6_k`, 1024-d) via `llama-cpp-python`. These scope
296
+ limits are required for an honest cross-library measurement.
288
297
 
289
- The following is one recorded run from commit `e2bbb3c8bfd3bbfcd7a5e508a757917919dd5e89`
290
- on Windows 11 with Python 3.12.13 and an AMD64 Family 23 Model 96 CPU. It used
291
- `synthetic-business-v1`, seed 42, 40 samples, 40 queries, warmup 5, and 30 paired
292
- repetitions. Latencies are milliseconds per operation; the confidence interval is 95% CI
293
- for the mean.
298
+ The following is one recorded 0.3.5 run from commit `62c8c6054bae` on Windows 11 with
299
+ Python 3.12.10, an AMD64 Family 23 Model 96 CPU, and CUDA via `llama-cpp` (`n_gpu_layers=-1`).
300
+ It used `synthetic-business-v1`, seed 42, 40 samples / 40 queries, warmup 2, and 10 paired
301
+ repetitions. Latencies are milliseconds; CoG rows are milliseconds per complete 40-query
302
+ batch. The confidence interval is the 95% CI for the mean.
294
303
 
295
304
  | Operation | Variant | Mean | Median | Stdev | P95 | 95% CI |
296
305
  |---|---|---:|---:|---:|---:|---:|
297
- | RAG chunking | hakua-memory | 0.6312 | 0.5901 | 0.1184 | 0.8746 | 0.5870–0.6754 |
298
- | RAG chunking | LangChain Text Splitters 1.1.2 | 0.0694 | 0.0681 | 0.0144 | 0.0854 | 0.0640–0.0747 |
299
- | RAG chunking | LlamaIndex Core 0.14.24 | 1.8174 | 1.6806 | 0.3354 | 2.4531 | 1.6921–1.9426 |
300
- | Lexical retrieval, 40-query batch | hakua-memory | 264.2875 | 155.3723 | 487.9654 | 397.6564 | 82.0782–446.4968 |
301
- | Lexical retrieval, 40-query batch | rank-bm25 0.2.2 | 2.5974 | 2.4707 | 0.3772 | 3.0580 | 2.4566–2.7382 |
302
-
303
- The paired two-sided Wilcoxon signed-rank p-values were `1.862645149e-09` for each
304
- comparison. Holm-adjusted values across the three comparisons were `5.587935448e-09`
305
- for each comparison. Paired t-test sensitivity p-values were `1.387202830e-21` for
306
- LangChain, `4.399465113e-19` for LlamaIndex, and `0.006427546` for rank-bm25. These
307
- p-values describe this paired latency sample only; they are not accuracy claims or proof
308
- of general library superiority.
309
-
310
- The dataset-specific validation found non-empty chunk output for all variants. The
311
- expected exact-record hit rate at top-k=5 was 33/40 (82.5%) for hakua-memory and 38/40
312
- (95.0%) for rank-bm25. This is a small synthetic query-set check, not a benchmark of
313
- retrieval quality across domains. The generated JSON and error-bar PNG are intentionally
314
- kept outside Git; rerun the command above to reproduce them on another machine.
306
+ | RAG chunking | hakua-memory | 1.0630 | 1.0358 | 0.1563 | 1.3290 | 0.9513–1.1748 |
307
+ | RAG chunking | LangChain Text Splitters | 0.1130 | 0.1185 | 0.0168 | 0.1329 | 0.1009–0.1250 |
308
+ | RAG chunking | LlamaIndex Core | 2.2198 | 2.1212 | 0.3185 | 2.6825 | 1.9919–2.4477 |
309
+ | CoG retrieval batch | hakua lexical | 45.5863 | 47.3555 | 7.6094 | 56.0006 | 40.1429–51.0297 |
310
+ | CoG retrieval batch | rank-bm25 | 4.2935 | 3.6322 | 2.2569 | 7.9821 | 2.6790–5.9080 |
311
+ | CoG retrieval batch | LangChain BM25 | 6.5765 | 5.6572 | 2.8180 | 11.2159 | 4.5606–8.5924 |
312
+ | CoG retrieval batch | LlamaIndex BM25 | 40.3695 | 39.8424 | 10.2176 | 52.1031 | 33.0602–47.6787 |
313
+ | CoG retrieval batch | hakua hybrid GGUF | 31519.2576 | 25784.8628 | 13763.0641 | 57242.3898 | 21673.7546–41364.7606 |
314
+ | CoG retrieval batch | FAISS + same GGUF | 16617.3399 | 14470.4271 | 9264.0809 | 31038.2213 | 9990.2156–23244.4642 |
315
+
316
+ #### Multi-group Friedman p-values
317
+
318
+ | Operation | Groups (n) | Friedman χ² | p-value | Reject H₀ (α=0.05) |
319
+ |---|---|---:|---:|---|
320
+ | RAG chunking | 3 | 20.0 | 4.540e-05 | yes |
321
+ | CoG retrieval batch | 6 | 47.6 | 4.286e-09 | yes |
322
+
323
+ #### Pairwise Wilcoxon / Holm / paired-t p-values (RAG chunking)
324
+
325
+ | Primary | Comparator | Wilcoxon p | Holm-adjusted Wilcoxon p | Paired-t p |
326
+ |---|---|---:|---:|---:|
327
+ | hakua-memory | LangChain Text Splitters | 0.001953 | 0.035156 | 1.366e-08 |
328
+ | hakua-memory | LlamaIndex Core | 0.001953 | 0.035156 | 3.434e-06 |
329
+ | LangChain Text Splitters | LlamaIndex Core | 0.001953 | 0.035156 | 7.409e-09 |
330
+
331
+ #### Pairwise Wilcoxon / Holm / paired-t p-values (CoG retrieval batch)
332
+
333
+ | Primary | Comparator | Wilcoxon p | Holm-adjusted Wilcoxon p | Paired-t p |
334
+ |---|---|---:|---:|---:|
335
+ | hakua lexical | rank-bm25 | 0.001953 | 0.035156 | 2.450e-08 |
336
+ | hakua lexical | LangChain BM25 | 0.001953 | 0.035156 | 4.766e-08 |
337
+ | hakua lexical | LlamaIndex BM25 | 0.193359 | 0.193359 | 0.137301 |
338
+ | hakua lexical | hakua hybrid GGUF | 0.001953 | 0.035156 | 4.913e-05 |
339
+ | hakua lexical | FAISS + same GGUF | 0.001953 | 0.035156 | 0.000310 |
340
+ | rank-bm25 | LangChain BM25 | 0.005859 | 0.035156 | 0.001648 |
341
+ | rank-bm25 | LlamaIndex BM25 | 0.001953 | 0.035156 | 5.045e-07 |
342
+ | rank-bm25 | hakua hybrid GGUF | 0.001953 | 0.035156 | 4.862e-05 |
343
+ | rank-bm25 | FAISS + same GGUF | 0.001953 | 0.035156 | 0.000305 |
344
+ | LangChain BM25 | LlamaIndex BM25 | 0.001953 | 0.035156 | 4.817e-07 |
345
+ | LangChain BM25 | hakua hybrid GGUF | 0.001953 | 0.035156 | 4.861e-05 |
346
+ | LangChain BM25 | FAISS + same GGUF | 0.001953 | 0.035156 | 0.000306 |
347
+ | LlamaIndex BM25 | hakua hybrid GGUF | 0.001953 | 0.035156 | 4.890e-05 |
348
+ | LlamaIndex BM25 | FAISS + same GGUF | 0.001953 | 0.035156 | 0.000310 |
349
+ | hakua hybrid GGUF | FAISS + same GGUF | 0.037109 | 0.074219 | 0.018810 |
350
+
351
+ These p-values describe this paired latency sample only; they are not accuracy claims or
352
+ proof of general library superiority. Holm correction is applied across all pairwise
353
+ Wilcoxon tests emitted by the harness for that operation family.
354
+
355
+ Dataset-specific validation found non-empty chunk output for all chunkers. Exact-record
356
+ hit rate at top-k=5 was 33/40 (82.5%) for hakua lexical and hakua hybrid GGUF, 38/40
357
+ (95.0%) for rank-bm25 and LangChain BM25, 39/40 (97.5%) for LlamaIndex BM25, and 18/40
358
+ (45.0%) for FAISS+GGUF on this synthetic set. This is a small query-set check, not a
359
+ cross-domain retrieval-quality benchmark. Generated JSON/PNG stay outside Git; rerun the
360
+ commands above to reproduce on another machine.
361
+
362
+ ### Speculative-hybrid three-group Friedman
363
+
364
+ `scripts/benchmark_speculative_hybrid.py` compares `lexical_only`, `always_hybrid`, and
365
+ `speculative_hybrid` on the same corpus after sweeping `min_top_score` (primary early-accept
366
+ gate; absolute `final_score` margins often collapse on uniform confidence/salience data).
367
+ One recorded run (seed 42, 30 samples, warmup 1, 8 repetitions) chose Pareto
368
+ `min_top_score=0.40` (hit-rate tied with hybrid at 0.800; minimum latency). An interior
369
+ early-accept candidate near 50% was `min_top_score=0.55` (early-accept rate ≈ 0.367).
370
+ Mean latencies at the Pareto gate: lexical 56.8 ms, speculative 58.3 ms, always-hybrid
371
+ 22800.2 ms.
372
+
373
+ | Test | Statistic | p-value | Reject H₀ (α=0.05) |
374
+ |---|---:|---:|---|
375
+ | Friedman χ² (3 groups) | 12.0 | 0.002479 | yes |
376
+
377
+ | Primary | Comparator | Wilcoxon p | Holm-adjusted Wilcoxon p | Paired-t p |
378
+ |---|---|---:|---:|---:|
379
+ | lexical_only | always_hybrid | 0.007812 | 0.023438 | 1.371e-06 |
380
+ | lexical_only | speculative_hybrid | 0.843750 | 0.843750 | 0.660915 |
381
+ | always_hybrid | speculative_hybrid | 0.007812 | 0.023438 | 1.369e-06 |
315
382
 
316
383
  ### External references
317
384
 
318
385
  The measured comparison uses [LangChain Text Splitters](https://docs.langchain.com/oss/python/integrations/splitters/recursive_text_splitter),
319
386
  [LlamaIndex SentenceSplitter](https://docs.llamaindex.ai/en/stable/module_guides/loading/node_parsers/modules.html),
320
- and [rank-bm25](https://pypi.org/project/rank-bm25/), with versions pinned in
321
- `benchmarks/requirements.txt`. NetworkX, PyTorch Geometric, and FAISS remain external
322
- references only; this repository does not publish direct measurements for them.
387
+ [rank-bm25](https://pypi.org/project/rank-bm25/), LangChain/LlamaIndex BM25 retrievers,
388
+ and [FAISS](https://github.com/facebookresearch/faiss) with versions pinned in
389
+ `benchmarks/requirements.txt`. NetworkX and PyTorch Geometric remain external references
390
+ only; this repository does not publish direct measurements for them.
323
391
 
324
392
  ## Reproducible synthetic data
325
393
 
@@ -384,3 +452,68 @@ The integration path can be exercised with a temporary directory and the determi
384
452
  ## License
385
453
 
386
454
  Apache License 2.0. See [LICENSE](LICENSE).
455
+ # Model-independent continuity
456
+
457
+ Keep a host-authorized identity UUID across model switches. Open the same local root
458
+ and UUID for both models, save confirmed persona preferences as `portable_persona`
459
+ and transferable episodes as `portable_episode`. Each new generation can request a
460
+ fresh snapshot. The snapshot contains the current text, stable belief ID, version
461
+ and source. Pass it only to a model authorized to receive that identity's records.
462
+
463
+ ```python
464
+ from hakua_memory.composite import CompositeMemory
465
+
466
+ memory = CompositeMemory.for_identity(root, identity_uuid)
467
+ try:
468
+ entry = memory.remember("I prefer short replies.", memory_type="portable_persona",
469
+ source="user")
470
+ snapshot = memory.continuity()
471
+ finally:
472
+ memory.close()
473
+ ```
474
+
475
+ Use the existing `revise_memory` and `retract_memory` on the scoped Ebbinghaus
476
+ store for corrections and deletions. Regenerate the snapshot and discard earlier
477
+ message context when switching revisions. Retraction excludes the entry from
478
+ future snapshots. The local revision history and copies already given to a model
479
+ have separate lifetimes. UUIDs select a namespace, and the host controls access.
480
+ Each model can use its own tokenizer and weights. By default the snapshot contains
481
+ only persona entries. To hand over an episode, pass its stable belief ID in
482
+ `continuity(episode_beliefs=(entry["belief_id"],))` after authorizing the request.
483
+ Persona entries appear first within the requested limit,
484
+ and `truncated` reports whether more eligible entries exist.
485
+ For a chat integration, use `memory.continuity_message(episode_beliefs=approved_ids)`
486
+ to render the same selection into one system message. It separates persona preferences
487
+ from current episodes and omits database IDs. Only trust user-authorized persona entries
488
+ with this role. Use a fresh message when reopening or revising a conversation.
489
+ Pass `include_provenance=True` to include the scoped identity, belief IDs, versions
490
+ and sources. This emits the original record representation for models qualified with it.
491
+
492
+ In a synthetic local CPU trial, Inkling‑2‑Mini v3.1 IQ3_S retained the requested
493
+ punctuation after a deletion with the full record view. Its compact view reached
494
+ the generation limit on one of two punctuation checks. Qwen3.5-2B Q8_0 omitted
495
+ a saved exclamation mark once with the full view and passed both compact-view
496
+ checks. Test the representation on the specific model that will receive it.
497
+
498
+ To switch GGUFs, keep the same store root, identity UUID and approved belief IDs.
499
+ Generate a fresh request body for the new server's model alias on each turn:
500
+
501
+ ```powershell
502
+ python -m hakua_memory.handoff --root $root --identity $identity --model $modelAlias --episode $beliefId --question '前回決めた名前は?'
503
+ ```
504
+
505
+ The command prints JSON for a chat-completions client. It opens an existing identity
506
+ and includes only current authorized records and the new question. Omit `--episode`
507
+ to carry persona alone. Use `--with-provenance` for a recipient that needs the full
508
+ record representation. The target server applies its own tokenizer and chat template
509
+ and must accept system and user messages. Discard old chat history on a handoff.
510
+
511
+ At the end of a session, call `memory.ebbinghaus.sleep_portable_episodes(limit=256)`
512
+ on the scoped identity. This reviews the least recently examined current episodes first.
513
+ It uses the existing exponential retention curve and configurable sleep thresholds.
514
+ By default, a protected or high-salience episode (at least 0.80) is rehearsed when
515
+ retention falls to 0.35. An unprotected lower-salience episode becomes latent at 0.10.
516
+ Latent episodes disappear from subsequent continuity requests. Persona records,
517
+ retracted beliefs and superseded revisions are outside this pass. The returned IDs
518
+ identify rehearsed and newly latent episodes. Source history remains available for
519
+ audit. Weight-based readers must rebuild and reload their snapshot to see a change.
@@ -0,0 +1,55 @@
1
+ # Share approved memories between the compact Mini VLT and Qwen3.5-2B
2
+
3
+ Open the same authorised Hakua identity from either application. Each model needs an adapter fitted to its own GGUF. The compact Mini VLT and both stock adapters can share the 45,000,000-byte deployment allowance; the external 2B base, llama-server, training tools, ledger and retained historical copies need separate storage.
4
+
5
+ Use `CompositeMemory.for_identity(root, uuid)` to open the store. Save a `portable_persona` or `portable_episode` with `remember`. Keep the returned belief ID. Plain content supplies the same literal value in either language. To supply translated values, store JSON with schema `memory45.dialogue.v1` and an `answers` mapping from `en` and `ja` to the approved answers. Populate a trusted binding specification with the actual identity UUID and belief IDs:
6
+
7
+ ```json
8
+ {
9
+ "identity": "008058e4-9d0e-440d-bc06-9344a8c836be",
10
+ "bindings": [{
11
+ "belief_id": "memory-1",
12
+ "kind": "portable_episode",
13
+ "questions": [
14
+ {"language": "en", "question": "What is my archive code?"},
15
+ {"language": "ja", "question": "私の資料室の符号は?"}
16
+ ]
17
+ }],
18
+ "unknown": [
19
+ {"language": "en", "question": "What is the pier number?"},
20
+ {"language": "ja", "question": "桟橋の番号は?"}
21
+ ],
22
+ "neutral": [{"language": "en", "question": "Name a colour."}]
23
+ }
24
+ ```
25
+
26
+ `unknown` supplies negative memory requests with explicit abstention targets. `neutral` supplies ordinary examples for which the writer preserves the base response. Approved questions, current ledger answers, identity and version numbers determine one revision. After a correction (`memory.ebbinghaus.revise_memory`) or withdrawal (`retract_memory`), a fresh snapshot resolves the new answers and both adapters must be regenerated. Existing scoped callers without this feature continue using the original APIs.
27
+
28
+ Use Python with the compact writer's dependencies and the matching local Qwen capture executable. Set `QWEN_CAPTURE` to that executable and `LLAMA_BIN` to the matching llama.cpp library directory. From the Hakua environment:
29
+
30
+ ```text
31
+ python -m hakua_memory.memory45_refit --root LEDGER_ROOT --spec approved.json --mini-kit V4_KIT --qwen-base QWEN_2B.gguf --tied-writer QWEN_WRITER/writer.py --server /path/to/llama-server
32
+ ```
33
+
34
+ The command returns both adapter paths. Use `--lookup-only` to require already built current adapters. A failed second fit publishes neither model. The host authorises the identity, checks the current pair before each admission, and starts or reloads each standard llama-server with the matching `--lora FILE`. The compact model also needs its supplied `--mmproj`. Bindings and answers are used during fitting. The chat request to the model contains only the question. Retained older files, previously loaded processes, and saved chat transcripts have independent lifetimes.
35
+
36
+ For an explicit recall request, send `/recall ` followed by the original question to either model. For a host-assisted lookup, use `memory.memory45_recall(spec, question, language, expected_revision=revision)` with the revision from the loaded pair's `manifest.json`. If the result has a question, send it verbatim to the selected model. Otherwise return its abstention. The optional matcher uses lexical similarity between approved cues; it can miss synonyms or confuse similar entities. A local abstention must be recorded separately from model-generated text in evaluations. Ordinary chat can continue to send its original message.
37
+
38
+ ### Distinguish the owner’s observatory from an observatory in another town
39
+
40
+ Adjacent alternatives such as `not local but one town over` and `隣町ではなく地元` select the second approved location. Negation involving an unknown name or a separate clause gives a local abstention.
41
+
42
+ For records with similar names, add a `scope` to every binding in the trusted specification. The installed package includes an English and Japanese example. Use the vocabulary appropriate to each binding:
43
+
44
+ ```python
45
+ import json
46
+ from importlib.resources import files
47
+
48
+ vocabulary = files("hakua_memory").joinpath("data", "memory45_scopes.json")
49
+ scopes = json.loads(vocabulary.read_text(encoding="utf8"))
50
+ observatory_binding["scope"] = scopes["observatory"]
51
+ ```
52
+
53
+ Each language entry lists approved entity names, the requested attribute and expressions for the same or a different location. The writers read answers from the current ledger. Hosts can update the routing vocabulary without rebuilding the weights. Install the model GGUFs, llama-server and fitting tools separately when using the two-model workflow.
54
+
55
+ Hakua accepts a single recognised entity and attribute when it can account for the whole request in the selected language. It forwards the approved question to the current adapter. A recognised other location returns `間違えちゃった` or `I got that wrong.` locally. The location vocabulary remains available after a value is withdrawn. Unknown names, unrecognised attributes, ambiguous bindings and withdrawn home values return `記録がない` or `No record.` locally. Further names and expressions require explicit aliases. The matcher does not resolve arbitrary grammar, negation or geographical facts.
@@ -1,10 +1,10 @@
1
1
  [build-system]
2
- requires = ["setuptools>=75", "wheel"]
2
+ requires = ["setuptools>=77.0.3", "wheel"]
3
3
  build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "hakua-memory"
7
- version = "0.3.4"
7
+ version = "0.4.0"
8
8
  description = "Composite memory library: Ebbinghaus + Semantic Graph + RAG + Obsidian Wiki"
9
9
  readme = "README.md"
10
10
  license = "Apache-2.0"
@@ -12,6 +12,10 @@ requires-python = ">=3.11,<3.14"
12
12
  authors = [{name = "Hakua"}]
13
13
  dependencies = ["pyyaml>=6"]
14
14
 
15
+ [project.urls]
16
+ Repository = "https://github.com/zapabob/hakua-memory"
17
+ Documentation = "https://zapabob.github.io/hakua-memory/"
18
+
15
19
  [project.optional-dependencies]
16
20
  obsidian = ["gitpython>=3,<4"]
17
21
  embedding = ["llama-cpp-python>=0.3,<1"]
@@ -32,6 +36,9 @@ all = [
32
36
  [tool.setuptools.packages.find]
33
37
  where = ["src"]
34
38
 
39
+ [tool.setuptools.package-data]
40
+ hakua_memory = ["data/memory45_scopes.json"]
41
+
35
42
  [tool.ruff]
36
43
  line-length = 100
37
44
  target-version = "py311"