hakua-memory 0.3.4__tar.gz → 0.3.5__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.
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/PKG-INFO +106 -40
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/README.md +105 -39
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/pyproject.toml +1 -1
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/composite.py +108 -34
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/rag/chunking.py +26 -13
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/rag/retrieval.py +4 -2
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/rag/schema.py +2 -2
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/rag/store.py +160 -45
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/semantic_graph/embedding/__init__.py +2 -0
- hakua_memory-0.3.5/src/hakua_memory/semantic_graph/embedding/gguf_local.py +125 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/semantic_graph/retrieval.py +123 -12
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/semantic_graph/store.py +119 -38
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory.egg-info/PKG-INFO +106 -40
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory.egg-info/SOURCES.txt +4 -1
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/tests/test_benchmark.py +1 -1
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/tests/test_config.py +1 -1
- hakua_memory-0.3.5/tests/test_sleep_consolidation.py +496 -0
- hakua_memory-0.3.5/tests/test_speculative_hybrid.py +131 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/LICENSE +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/setup.cfg +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/__init__.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/config.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/ebbinghaus/__init__.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/ebbinghaus/experience.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/ebbinghaus/migrations.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/ebbinghaus/models.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/ebbinghaus/policies.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/ebbinghaus/semantic_graph_bridge.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/ebbinghaus/store.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/obsidian/__init__.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/obsidian/templates.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/rag/__init__.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/rag/contradiction.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/rag/ingestion.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/rag/meeting.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/rag/models.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/semantic_graph/__init__.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/semantic_graph/cli.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/semantic_graph/cognitive.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/semantic_graph/config.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/semantic_graph/embedding/base.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/semantic_graph/embedding/fake.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/semantic_graph/embedding/llama_cpp.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/semantic_graph/embedding/serializer.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/semantic_graph/embedding/vectors.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/semantic_graph/exporter.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/semantic_graph/fusion.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/semantic_graph/graph.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/semantic_graph/inference.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/semantic_graph/models.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/semantic_graph/runtime.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/semantic_graph/sanitize.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory/semantic_graph/schemas.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory.egg-info/dependency_links.txt +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory.egg-info/requires.txt +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/src/hakua_memory.egg-info/top_level.txt +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/tests/test_acl.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/tests/test_composite.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/tests/test_ebbinghaus.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/tests/test_embedding_backend.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/tests/test_integration.py +0 -0
- {hakua_memory-0.3.4 → hakua_memory-0.3.5}/tests/test_obsidian.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hakua-memory
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.5
|
|
4
4
|
Summary: Composite memory library: Ebbinghaus + Semantic Graph + RAG + Obsidian Wiki
|
|
5
5
|
Author: Hakua
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -125,6 +125,8 @@ memory = CompositeMemory(Path("~/.hakua-memory").expanduser())
|
|
|
125
125
|
memory.remember(
|
|
126
126
|
"The user prefers concise, verifiable reports.",
|
|
127
127
|
tags=["user-preference", "communication"],
|
|
128
|
+
salience=0.9,
|
|
129
|
+
valence=0.2,
|
|
128
130
|
)
|
|
129
131
|
|
|
130
132
|
matches = memory.recall("verifiable reports")
|
|
@@ -287,68 +289,132 @@ results. Values depend on the recorded machine, dataset, seed, warmup, and repet
|
|
|
287
289
|
The optional comparison harness uses the same corpus, query set, warmup count, repetition
|
|
288
290
|
count, and randomized variant order for every paired measurement. It compares RAG
|
|
289
291
|
chunking with LangChain's `RecursiveCharacterTextSplitter` and LlamaIndex's
|
|
290
|
-
`SentenceSplitter`, and compares
|
|
291
|
-
`rank-bm25
|
|
292
|
-
|
|
292
|
+
`SentenceSplitter`, and compares CoG/retrieval peers across hakua lexical search,
|
|
293
|
+
hakua hybrid GGUF search, `rank-bm25`, LangChain BM25, LlamaIndex BM25, and
|
|
294
|
+
FAISS+same-GGUF dense retrieval. Multi-group Friedman tests and all-pairs
|
|
295
|
+
Wilcoxon/Holm corrections are recorded. This is not a claim about complete RAG quality,
|
|
296
|
+
end-to-end agent latency, memory use, or general library superiority.
|
|
293
297
|
|
|
294
298
|
Create a separate environment and run the comparison as follows:
|
|
295
299
|
|
|
296
300
|
```bash
|
|
297
301
|
python -m venv .venv-benchmark
|
|
298
302
|
# Activate .venv-benchmark for your shell, then run:
|
|
299
|
-
python -m pip install -e .
|
|
303
|
+
python -m pip install -e ".[embedding]"
|
|
300
304
|
python -m pip install -r benchmarks/requirements.txt
|
|
301
305
|
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
|
|
306
|
+
python scripts/benchmark_external_libraries.py --seed 42 --samples 40 --warmup 2 --repetitions 10 --output benchmark-results-external.json --plot benchmark-errorbars.png
|
|
307
|
+
python scripts/benchmark_speculative_hybrid.py --samples 30 --warmup 1 --repetitions 8 --output speculative-hybrid-3group.json --plot speculative-hybrid-3group.png
|
|
303
308
|
```
|
|
304
309
|
|
|
305
310
|
The comparison JSON records exact library versions, host metadata, configurations, raw
|
|
306
311
|
paired durations, mean, median, standard deviation, p50, p95, p99, and a 95% confidence
|
|
307
|
-
interval for each variant. It also records
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
The validation section separately records non-empty chunk
|
|
311
|
-
rate, so latency and retrieval-result checks are not
|
|
312
|
+
interval for each variant. It also records Friedman chi-square multi-group tests,
|
|
313
|
+
two-sided paired Wilcoxon signed-rank tests, paired t-test sensitivity, and Holm-adjusted
|
|
314
|
+
Wilcoxon p-values across all pairwise comparisons. The PNG uses mean latency with 95%
|
|
315
|
+
confidence-interval error bars. The validation section separately records non-empty chunk
|
|
316
|
+
output and expected top-k hit rate, so latency and retrieval-result checks are not
|
|
317
|
+
conflated.
|
|
312
318
|
|
|
313
319
|
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.
|
|
315
|
-
|
|
316
|
-
|
|
320
|
+
chunk-size arguments therefore do not mean equal chunk boundaries. Lexical peers compare
|
|
321
|
+
SQLite-backed graph search with in-memory BM25 indexes. Dense peers use the same local
|
|
322
|
+
GGUF embedding model (`nsfw-bge-m3-v5-q6_k`, 1024-d) via `llama-cpp-python`. These scope
|
|
323
|
+
limits are required for an honest cross-library measurement.
|
|
317
324
|
|
|
318
|
-
The following is one recorded run from commit `
|
|
319
|
-
|
|
320
|
-
`synthetic-business-v1`, seed 42, 40 samples
|
|
321
|
-
repetitions. Latencies are milliseconds
|
|
322
|
-
for the mean.
|
|
325
|
+
The following is one recorded 0.3.5 run from commit `62c8c6054bae` on Windows 11 with
|
|
326
|
+
Python 3.12.10, an AMD64 Family 23 Model 96 CPU, and CUDA via `llama-cpp` (`n_gpu_layers=-1`).
|
|
327
|
+
It used `synthetic-business-v1`, seed 42, 40 samples / 40 queries, warmup 2, and 10 paired
|
|
328
|
+
repetitions. Latencies are milliseconds; CoG rows are milliseconds per complete 40-query
|
|
329
|
+
batch. The confidence interval is the 95% CI for the mean.
|
|
323
330
|
|
|
324
331
|
| Operation | Variant | Mean | Median | Stdev | P95 | 95% CI |
|
|
325
332
|
|---|---|---:|---:|---:|---:|---:|
|
|
326
|
-
| RAG chunking | hakua-memory |
|
|
327
|
-
| RAG chunking | LangChain Text Splitters
|
|
328
|
-
| RAG chunking | LlamaIndex Core
|
|
329
|
-
|
|
|
330
|
-
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
p-values
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
333
|
+
| RAG chunking | hakua-memory | 1.0630 | 1.0358 | 0.1563 | 1.3290 | 0.9513–1.1748 |
|
|
334
|
+
| RAG chunking | LangChain Text Splitters | 0.1130 | 0.1185 | 0.0168 | 0.1329 | 0.1009–0.1250 |
|
|
335
|
+
| RAG chunking | LlamaIndex Core | 2.2198 | 2.1212 | 0.3185 | 2.6825 | 1.9919–2.4477 |
|
|
336
|
+
| CoG retrieval batch | hakua lexical | 45.5863 | 47.3555 | 7.6094 | 56.0006 | 40.1429–51.0297 |
|
|
337
|
+
| CoG retrieval batch | rank-bm25 | 4.2935 | 3.6322 | 2.2569 | 7.9821 | 2.6790–5.9080 |
|
|
338
|
+
| CoG retrieval batch | LangChain BM25 | 6.5765 | 5.6572 | 2.8180 | 11.2159 | 4.5606–8.5924 |
|
|
339
|
+
| CoG retrieval batch | LlamaIndex BM25 | 40.3695 | 39.8424 | 10.2176 | 52.1031 | 33.0602–47.6787 |
|
|
340
|
+
| CoG retrieval batch | hakua hybrid GGUF | 31519.2576 | 25784.8628 | 13763.0641 | 57242.3898 | 21673.7546–41364.7606 |
|
|
341
|
+
| CoG retrieval batch | FAISS + same GGUF | 16617.3399 | 14470.4271 | 9264.0809 | 31038.2213 | 9990.2156–23244.4642 |
|
|
342
|
+
|
|
343
|
+
#### Multi-group Friedman p-values
|
|
344
|
+
|
|
345
|
+
| Operation | Groups (n) | Friedman χ² | p-value | Reject H₀ (α=0.05) |
|
|
346
|
+
|---|---|---:|---:|---|
|
|
347
|
+
| RAG chunking | 3 | 20.0 | 4.540e-05 | yes |
|
|
348
|
+
| CoG retrieval batch | 6 | 47.6 | 4.286e-09 | yes |
|
|
349
|
+
|
|
350
|
+
#### Pairwise Wilcoxon / Holm / paired-t p-values (RAG chunking)
|
|
351
|
+
|
|
352
|
+
| Primary | Comparator | Wilcoxon p | Holm-adjusted Wilcoxon p | Paired-t p |
|
|
353
|
+
|---|---|---:|---:|---:|
|
|
354
|
+
| hakua-memory | LangChain Text Splitters | 0.001953 | 0.035156 | 1.366e-08 |
|
|
355
|
+
| hakua-memory | LlamaIndex Core | 0.001953 | 0.035156 | 3.434e-06 |
|
|
356
|
+
| LangChain Text Splitters | LlamaIndex Core | 0.001953 | 0.035156 | 7.409e-09 |
|
|
357
|
+
|
|
358
|
+
#### Pairwise Wilcoxon / Holm / paired-t p-values (CoG retrieval batch)
|
|
359
|
+
|
|
360
|
+
| Primary | Comparator | Wilcoxon p | Holm-adjusted Wilcoxon p | Paired-t p |
|
|
361
|
+
|---|---|---:|---:|---:|
|
|
362
|
+
| hakua lexical | rank-bm25 | 0.001953 | 0.035156 | 2.450e-08 |
|
|
363
|
+
| hakua lexical | LangChain BM25 | 0.001953 | 0.035156 | 4.766e-08 |
|
|
364
|
+
| hakua lexical | LlamaIndex BM25 | 0.193359 | 0.193359 | 0.137301 |
|
|
365
|
+
| hakua lexical | hakua hybrid GGUF | 0.001953 | 0.035156 | 4.913e-05 |
|
|
366
|
+
| hakua lexical | FAISS + same GGUF | 0.001953 | 0.035156 | 0.000310 |
|
|
367
|
+
| rank-bm25 | LangChain BM25 | 0.005859 | 0.035156 | 0.001648 |
|
|
368
|
+
| rank-bm25 | LlamaIndex BM25 | 0.001953 | 0.035156 | 5.045e-07 |
|
|
369
|
+
| rank-bm25 | hakua hybrid GGUF | 0.001953 | 0.035156 | 4.862e-05 |
|
|
370
|
+
| rank-bm25 | FAISS + same GGUF | 0.001953 | 0.035156 | 0.000305 |
|
|
371
|
+
| LangChain BM25 | LlamaIndex BM25 | 0.001953 | 0.035156 | 4.817e-07 |
|
|
372
|
+
| LangChain BM25 | hakua hybrid GGUF | 0.001953 | 0.035156 | 4.861e-05 |
|
|
373
|
+
| LangChain BM25 | FAISS + same GGUF | 0.001953 | 0.035156 | 0.000306 |
|
|
374
|
+
| LlamaIndex BM25 | hakua hybrid GGUF | 0.001953 | 0.035156 | 4.890e-05 |
|
|
375
|
+
| LlamaIndex BM25 | FAISS + same GGUF | 0.001953 | 0.035156 | 0.000310 |
|
|
376
|
+
| hakua hybrid GGUF | FAISS + same GGUF | 0.037109 | 0.074219 | 0.018810 |
|
|
377
|
+
|
|
378
|
+
These p-values describe this paired latency sample only; they are not accuracy claims or
|
|
379
|
+
proof of general library superiority. Holm correction is applied across all pairwise
|
|
380
|
+
Wilcoxon tests emitted by the harness for that operation family.
|
|
381
|
+
|
|
382
|
+
Dataset-specific validation found non-empty chunk output for all chunkers. Exact-record
|
|
383
|
+
hit rate at top-k=5 was 33/40 (82.5%) for hakua lexical and hakua hybrid GGUF, 38/40
|
|
384
|
+
(95.0%) for rank-bm25 and LangChain BM25, 39/40 (97.5%) for LlamaIndex BM25, and 18/40
|
|
385
|
+
(45.0%) for FAISS+GGUF on this synthetic set. This is a small query-set check, not a
|
|
386
|
+
cross-domain retrieval-quality benchmark. Generated JSON/PNG stay outside Git; rerun the
|
|
387
|
+
commands above to reproduce on another machine.
|
|
388
|
+
|
|
389
|
+
### Speculative-hybrid three-group Friedman
|
|
390
|
+
|
|
391
|
+
`scripts/benchmark_speculative_hybrid.py` compares `lexical_only`, `always_hybrid`, and
|
|
392
|
+
`speculative_hybrid` on the same corpus after sweeping `min_top_score` (primary early-accept
|
|
393
|
+
gate; absolute `final_score` margins often collapse on uniform confidence/salience data).
|
|
394
|
+
One recorded run (seed 42, 30 samples, warmup 1, 8 repetitions) chose Pareto
|
|
395
|
+
`min_top_score=0.40` (hit-rate tied with hybrid at 0.800; minimum latency). An interior
|
|
396
|
+
early-accept candidate near 50% was `min_top_score=0.55` (early-accept rate ≈ 0.367).
|
|
397
|
+
Mean latencies at the Pareto gate: lexical 56.8 ms, speculative 58.3 ms, always-hybrid
|
|
398
|
+
22800.2 ms.
|
|
399
|
+
|
|
400
|
+
| Test | Statistic | p-value | Reject H₀ (α=0.05) |
|
|
401
|
+
|---|---:|---:|---|
|
|
402
|
+
| Friedman χ² (3 groups) | 12.0 | 0.002479 | yes |
|
|
403
|
+
|
|
404
|
+
| Primary | Comparator | Wilcoxon p | Holm-adjusted Wilcoxon p | Paired-t p |
|
|
405
|
+
|---|---|---:|---:|---:|
|
|
406
|
+
| lexical_only | always_hybrid | 0.007812 | 0.023438 | 1.371e-06 |
|
|
407
|
+
| lexical_only | speculative_hybrid | 0.843750 | 0.843750 | 0.660915 |
|
|
408
|
+
| always_hybrid | speculative_hybrid | 0.007812 | 0.023438 | 1.369e-06 |
|
|
344
409
|
|
|
345
410
|
### External references
|
|
346
411
|
|
|
347
412
|
The measured comparison uses [LangChain Text Splitters](https://docs.langchain.com/oss/python/integrations/splitters/recursive_text_splitter),
|
|
348
413
|
[LlamaIndex SentenceSplitter](https://docs.llamaindex.ai/en/stable/module_guides/loading/node_parsers/modules.html),
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
414
|
+
[rank-bm25](https://pypi.org/project/rank-bm25/), LangChain/LlamaIndex BM25 retrievers,
|
|
415
|
+
and [FAISS](https://github.com/facebookresearch/faiss) with versions pinned in
|
|
416
|
+
`benchmarks/requirements.txt`. NetworkX and PyTorch Geometric remain external references
|
|
417
|
+
only; this repository does not publish direct measurements for them.
|
|
352
418
|
|
|
353
419
|
## Reproducible synthetic data
|
|
354
420
|
|
|
@@ -96,6 +96,8 @@ memory = CompositeMemory(Path("~/.hakua-memory").expanduser())
|
|
|
96
96
|
memory.remember(
|
|
97
97
|
"The user prefers concise, verifiable reports.",
|
|
98
98
|
tags=["user-preference", "communication"],
|
|
99
|
+
salience=0.9,
|
|
100
|
+
valence=0.2,
|
|
99
101
|
)
|
|
100
102
|
|
|
101
103
|
matches = memory.recall("verifiable reports")
|
|
@@ -258,68 +260,132 @@ results. Values depend on the recorded machine, dataset, seed, warmup, and repet
|
|
|
258
260
|
The optional comparison harness uses the same corpus, query set, warmup count, repetition
|
|
259
261
|
count, and randomized variant order for every paired measurement. It compares RAG
|
|
260
262
|
chunking with LangChain's `RecursiveCharacterTextSplitter` and LlamaIndex's
|
|
261
|
-
`SentenceSplitter`, and compares
|
|
262
|
-
`rank-bm25
|
|
263
|
-
|
|
263
|
+
`SentenceSplitter`, and compares CoG/retrieval peers across hakua lexical search,
|
|
264
|
+
hakua hybrid GGUF search, `rank-bm25`, LangChain BM25, LlamaIndex BM25, and
|
|
265
|
+
FAISS+same-GGUF dense retrieval. Multi-group Friedman tests and all-pairs
|
|
266
|
+
Wilcoxon/Holm corrections are recorded. This is not a claim about complete RAG quality,
|
|
267
|
+
end-to-end agent latency, memory use, or general library superiority.
|
|
264
268
|
|
|
265
269
|
Create a separate environment and run the comparison as follows:
|
|
266
270
|
|
|
267
271
|
```bash
|
|
268
272
|
python -m venv .venv-benchmark
|
|
269
273
|
# Activate .venv-benchmark for your shell, then run:
|
|
270
|
-
python -m pip install -e .
|
|
274
|
+
python -m pip install -e ".[embedding]"
|
|
271
275
|
python -m pip install -r benchmarks/requirements.txt
|
|
272
276
|
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
|
|
277
|
+
python scripts/benchmark_external_libraries.py --seed 42 --samples 40 --warmup 2 --repetitions 10 --output benchmark-results-external.json --plot benchmark-errorbars.png
|
|
278
|
+
python scripts/benchmark_speculative_hybrid.py --samples 30 --warmup 1 --repetitions 8 --output speculative-hybrid-3group.json --plot speculative-hybrid-3group.png
|
|
274
279
|
```
|
|
275
280
|
|
|
276
281
|
The comparison JSON records exact library versions, host metadata, configurations, raw
|
|
277
282
|
paired durations, mean, median, standard deviation, p50, p95, p99, and a 95% confidence
|
|
278
|
-
interval for each variant. It also records
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
The validation section separately records non-empty chunk
|
|
282
|
-
rate, so latency and retrieval-result checks are not
|
|
283
|
+
interval for each variant. It also records Friedman chi-square multi-group tests,
|
|
284
|
+
two-sided paired Wilcoxon signed-rank tests, paired t-test sensitivity, and Holm-adjusted
|
|
285
|
+
Wilcoxon p-values across all pairwise comparisons. The PNG uses mean latency with 95%
|
|
286
|
+
confidence-interval error bars. The validation section separately records non-empty chunk
|
|
287
|
+
output and expected top-k hit rate, so latency and retrieval-result checks are not
|
|
288
|
+
conflated.
|
|
283
289
|
|
|
284
290
|
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.
|
|
286
|
-
|
|
287
|
-
|
|
291
|
+
chunk-size arguments therefore do not mean equal chunk boundaries. Lexical peers compare
|
|
292
|
+
SQLite-backed graph search with in-memory BM25 indexes. Dense peers use the same local
|
|
293
|
+
GGUF embedding model (`nsfw-bge-m3-v5-q6_k`, 1024-d) via `llama-cpp-python`. These scope
|
|
294
|
+
limits are required for an honest cross-library measurement.
|
|
288
295
|
|
|
289
|
-
The following is one recorded run from commit `
|
|
290
|
-
|
|
291
|
-
`synthetic-business-v1`, seed 42, 40 samples
|
|
292
|
-
repetitions. Latencies are milliseconds
|
|
293
|
-
for the mean.
|
|
296
|
+
The following is one recorded 0.3.5 run from commit `62c8c6054bae` on Windows 11 with
|
|
297
|
+
Python 3.12.10, an AMD64 Family 23 Model 96 CPU, and CUDA via `llama-cpp` (`n_gpu_layers=-1`).
|
|
298
|
+
It used `synthetic-business-v1`, seed 42, 40 samples / 40 queries, warmup 2, and 10 paired
|
|
299
|
+
repetitions. Latencies are milliseconds; CoG rows are milliseconds per complete 40-query
|
|
300
|
+
batch. The confidence interval is the 95% CI for the mean.
|
|
294
301
|
|
|
295
302
|
| Operation | Variant | Mean | Median | Stdev | P95 | 95% CI |
|
|
296
303
|
|---|---|---:|---:|---:|---:|---:|
|
|
297
|
-
| RAG chunking | hakua-memory |
|
|
298
|
-
| RAG chunking | LangChain Text Splitters
|
|
299
|
-
| RAG chunking | LlamaIndex Core
|
|
300
|
-
|
|
|
301
|
-
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
p-values
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
304
|
+
| RAG chunking | hakua-memory | 1.0630 | 1.0358 | 0.1563 | 1.3290 | 0.9513–1.1748 |
|
|
305
|
+
| RAG chunking | LangChain Text Splitters | 0.1130 | 0.1185 | 0.0168 | 0.1329 | 0.1009–0.1250 |
|
|
306
|
+
| RAG chunking | LlamaIndex Core | 2.2198 | 2.1212 | 0.3185 | 2.6825 | 1.9919–2.4477 |
|
|
307
|
+
| CoG retrieval batch | hakua lexical | 45.5863 | 47.3555 | 7.6094 | 56.0006 | 40.1429–51.0297 |
|
|
308
|
+
| CoG retrieval batch | rank-bm25 | 4.2935 | 3.6322 | 2.2569 | 7.9821 | 2.6790–5.9080 |
|
|
309
|
+
| CoG retrieval batch | LangChain BM25 | 6.5765 | 5.6572 | 2.8180 | 11.2159 | 4.5606–8.5924 |
|
|
310
|
+
| CoG retrieval batch | LlamaIndex BM25 | 40.3695 | 39.8424 | 10.2176 | 52.1031 | 33.0602–47.6787 |
|
|
311
|
+
| CoG retrieval batch | hakua hybrid GGUF | 31519.2576 | 25784.8628 | 13763.0641 | 57242.3898 | 21673.7546–41364.7606 |
|
|
312
|
+
| CoG retrieval batch | FAISS + same GGUF | 16617.3399 | 14470.4271 | 9264.0809 | 31038.2213 | 9990.2156–23244.4642 |
|
|
313
|
+
|
|
314
|
+
#### Multi-group Friedman p-values
|
|
315
|
+
|
|
316
|
+
| Operation | Groups (n) | Friedman χ² | p-value | Reject H₀ (α=0.05) |
|
|
317
|
+
|---|---|---:|---:|---|
|
|
318
|
+
| RAG chunking | 3 | 20.0 | 4.540e-05 | yes |
|
|
319
|
+
| CoG retrieval batch | 6 | 47.6 | 4.286e-09 | yes |
|
|
320
|
+
|
|
321
|
+
#### Pairwise Wilcoxon / Holm / paired-t p-values (RAG chunking)
|
|
322
|
+
|
|
323
|
+
| Primary | Comparator | Wilcoxon p | Holm-adjusted Wilcoxon p | Paired-t p |
|
|
324
|
+
|---|---|---:|---:|---:|
|
|
325
|
+
| hakua-memory | LangChain Text Splitters | 0.001953 | 0.035156 | 1.366e-08 |
|
|
326
|
+
| hakua-memory | LlamaIndex Core | 0.001953 | 0.035156 | 3.434e-06 |
|
|
327
|
+
| LangChain Text Splitters | LlamaIndex Core | 0.001953 | 0.035156 | 7.409e-09 |
|
|
328
|
+
|
|
329
|
+
#### Pairwise Wilcoxon / Holm / paired-t p-values (CoG retrieval batch)
|
|
330
|
+
|
|
331
|
+
| Primary | Comparator | Wilcoxon p | Holm-adjusted Wilcoxon p | Paired-t p |
|
|
332
|
+
|---|---|---:|---:|---:|
|
|
333
|
+
| hakua lexical | rank-bm25 | 0.001953 | 0.035156 | 2.450e-08 |
|
|
334
|
+
| hakua lexical | LangChain BM25 | 0.001953 | 0.035156 | 4.766e-08 |
|
|
335
|
+
| hakua lexical | LlamaIndex BM25 | 0.193359 | 0.193359 | 0.137301 |
|
|
336
|
+
| hakua lexical | hakua hybrid GGUF | 0.001953 | 0.035156 | 4.913e-05 |
|
|
337
|
+
| hakua lexical | FAISS + same GGUF | 0.001953 | 0.035156 | 0.000310 |
|
|
338
|
+
| rank-bm25 | LangChain BM25 | 0.005859 | 0.035156 | 0.001648 |
|
|
339
|
+
| rank-bm25 | LlamaIndex BM25 | 0.001953 | 0.035156 | 5.045e-07 |
|
|
340
|
+
| rank-bm25 | hakua hybrid GGUF | 0.001953 | 0.035156 | 4.862e-05 |
|
|
341
|
+
| rank-bm25 | FAISS + same GGUF | 0.001953 | 0.035156 | 0.000305 |
|
|
342
|
+
| LangChain BM25 | LlamaIndex BM25 | 0.001953 | 0.035156 | 4.817e-07 |
|
|
343
|
+
| LangChain BM25 | hakua hybrid GGUF | 0.001953 | 0.035156 | 4.861e-05 |
|
|
344
|
+
| LangChain BM25 | FAISS + same GGUF | 0.001953 | 0.035156 | 0.000306 |
|
|
345
|
+
| LlamaIndex BM25 | hakua hybrid GGUF | 0.001953 | 0.035156 | 4.890e-05 |
|
|
346
|
+
| LlamaIndex BM25 | FAISS + same GGUF | 0.001953 | 0.035156 | 0.000310 |
|
|
347
|
+
| hakua hybrid GGUF | FAISS + same GGUF | 0.037109 | 0.074219 | 0.018810 |
|
|
348
|
+
|
|
349
|
+
These p-values describe this paired latency sample only; they are not accuracy claims or
|
|
350
|
+
proof of general library superiority. Holm correction is applied across all pairwise
|
|
351
|
+
Wilcoxon tests emitted by the harness for that operation family.
|
|
352
|
+
|
|
353
|
+
Dataset-specific validation found non-empty chunk output for all chunkers. Exact-record
|
|
354
|
+
hit rate at top-k=5 was 33/40 (82.5%) for hakua lexical and hakua hybrid GGUF, 38/40
|
|
355
|
+
(95.0%) for rank-bm25 and LangChain BM25, 39/40 (97.5%) for LlamaIndex BM25, and 18/40
|
|
356
|
+
(45.0%) for FAISS+GGUF on this synthetic set. This is a small query-set check, not a
|
|
357
|
+
cross-domain retrieval-quality benchmark. Generated JSON/PNG stay outside Git; rerun the
|
|
358
|
+
commands above to reproduce on another machine.
|
|
359
|
+
|
|
360
|
+
### Speculative-hybrid three-group Friedman
|
|
361
|
+
|
|
362
|
+
`scripts/benchmark_speculative_hybrid.py` compares `lexical_only`, `always_hybrid`, and
|
|
363
|
+
`speculative_hybrid` on the same corpus after sweeping `min_top_score` (primary early-accept
|
|
364
|
+
gate; absolute `final_score` margins often collapse on uniform confidence/salience data).
|
|
365
|
+
One recorded run (seed 42, 30 samples, warmup 1, 8 repetitions) chose Pareto
|
|
366
|
+
`min_top_score=0.40` (hit-rate tied with hybrid at 0.800; minimum latency). An interior
|
|
367
|
+
early-accept candidate near 50% was `min_top_score=0.55` (early-accept rate ≈ 0.367).
|
|
368
|
+
Mean latencies at the Pareto gate: lexical 56.8 ms, speculative 58.3 ms, always-hybrid
|
|
369
|
+
22800.2 ms.
|
|
370
|
+
|
|
371
|
+
| Test | Statistic | p-value | Reject H₀ (α=0.05) |
|
|
372
|
+
|---|---:|---:|---|
|
|
373
|
+
| Friedman χ² (3 groups) | 12.0 | 0.002479 | yes |
|
|
374
|
+
|
|
375
|
+
| Primary | Comparator | Wilcoxon p | Holm-adjusted Wilcoxon p | Paired-t p |
|
|
376
|
+
|---|---|---:|---:|---:|
|
|
377
|
+
| lexical_only | always_hybrid | 0.007812 | 0.023438 | 1.371e-06 |
|
|
378
|
+
| lexical_only | speculative_hybrid | 0.843750 | 0.843750 | 0.660915 |
|
|
379
|
+
| always_hybrid | speculative_hybrid | 0.007812 | 0.023438 | 1.369e-06 |
|
|
315
380
|
|
|
316
381
|
### External references
|
|
317
382
|
|
|
318
383
|
The measured comparison uses [LangChain Text Splitters](https://docs.langchain.com/oss/python/integrations/splitters/recursive_text_splitter),
|
|
319
384
|
[LlamaIndex SentenceSplitter](https://docs.llamaindex.ai/en/stable/module_guides/loading/node_parsers/modules.html),
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
385
|
+
[rank-bm25](https://pypi.org/project/rank-bm25/), LangChain/LlamaIndex BM25 retrievers,
|
|
386
|
+
and [FAISS](https://github.com/facebookresearch/faiss) with versions pinned in
|
|
387
|
+
`benchmarks/requirements.txt`. NetworkX and PyTorch Geometric remain external references
|
|
388
|
+
only; this repository does not publish direct measurements for them.
|
|
323
389
|
|
|
324
390
|
## Reproducible synthetic data
|
|
325
391
|
|
|
@@ -2,47 +2,87 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
import sqlite3
|
|
6
5
|
from pathlib import Path
|
|
7
|
-
from typing import Any, Optional
|
|
6
|
+
from typing import TYPE_CHECKING, Any, Optional
|
|
8
7
|
|
|
9
8
|
from hakua_memory.ebbinghaus.store import EbbinghausMemoryStore
|
|
10
9
|
from hakua_memory.obsidian import write_diary
|
|
11
|
-
from hakua_memory.rag import (
|
|
12
|
-
AclEntry,
|
|
13
|
-
DocumentStore,
|
|
14
|
-
RagResult,
|
|
15
|
-
detect_contradictions,
|
|
16
|
-
extract_meeting_items,
|
|
17
|
-
ingest_document,
|
|
18
|
-
ingest_markdown_string,
|
|
19
|
-
ingest_text_string,
|
|
20
|
-
render_citation_context,
|
|
21
|
-
search_chunks,
|
|
22
|
-
)
|
|
23
10
|
from hakua_memory.semantic_graph.embedding.base import EmbeddingBackend
|
|
24
|
-
from hakua_memory.semantic_graph.retrieval import
|
|
11
|
+
from hakua_memory.semantic_graph.retrieval import (
|
|
12
|
+
hybrid_search_and_rank,
|
|
13
|
+
speculative_hybrid_search_and_rank,
|
|
14
|
+
)
|
|
25
15
|
from hakua_memory.semantic_graph.store import SemanticGraphStore
|
|
26
16
|
|
|
17
|
+
if TYPE_CHECKING:
|
|
18
|
+
from hakua_memory.rag.retrieval import RagResult
|
|
19
|
+
from hakua_memory.rag.store import DocumentStore
|
|
20
|
+
|
|
27
21
|
|
|
28
22
|
class CompositeMemory:
|
|
29
|
-
"""Single entrypoint for local composite memory.
|
|
23
|
+
"""Single entrypoint for local composite memory.
|
|
24
|
+
|
|
25
|
+
Embedding backends remain first-class for hybrid search quality. Pass an
|
|
26
|
+
``EmbeddingBackend`` to :meth:`search` (llama.cpp HTTP or in-process via
|
|
27
|
+
the ``[embedding]`` extra). RAG modules load lazily so remember/recall-only
|
|
28
|
+
paths stay light.
|
|
29
|
+
"""
|
|
30
30
|
|
|
31
|
-
def __init__(self, root: Path) -> None:
|
|
31
|
+
def __init__(self, root: Path, *, enable_rag: bool = True) -> None:
|
|
32
32
|
self.root = Path(root)
|
|
33
33
|
self.root.mkdir(parents=True, exist_ok=True)
|
|
34
34
|
self.ebbinghaus = EbbinghausMemoryStore(self.root / "ebbinghaus.db")
|
|
35
35
|
self.semantic = SemanticGraphStore(self.root / "semantic.db")
|
|
36
|
-
self.
|
|
36
|
+
self._enable_rag = enable_rag
|
|
37
|
+
self._documents: DocumentStore | None = None
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
@property
|
|
40
|
+
def documents(self) -> DocumentStore:
|
|
41
|
+
"""Lazy DocumentStore so import/RSS stay light until RAG is used."""
|
|
42
|
+
if self._documents is None:
|
|
43
|
+
if not self._enable_rag:
|
|
44
|
+
raise RuntimeError("RAG store is disabled for this CompositeMemory")
|
|
45
|
+
from hakua_memory.rag.store import DocumentStore
|
|
46
|
+
|
|
47
|
+
self._documents = DocumentStore(self.root / "rag.db")
|
|
48
|
+
return self._documents
|
|
49
|
+
|
|
50
|
+
def remember(
|
|
51
|
+
self,
|
|
52
|
+
content: str,
|
|
53
|
+
tags: Optional[list[str]] = None,
|
|
54
|
+
*,
|
|
55
|
+
salience: float = 0.65,
|
|
56
|
+
valence: float = 0.0,
|
|
57
|
+
source: str = "",
|
|
58
|
+
session_id: str = "",
|
|
59
|
+
memory_type: str = "episodic",
|
|
60
|
+
) -> dict[str, Any]:
|
|
61
|
+
"""Store an episodic/semantic cue with optional salience and valence.
|
|
62
|
+
|
|
63
|
+
``salience`` and ``valence`` are passed through to
|
|
64
|
+
:meth:`EbbinghausMemoryStore.remember` so sleep/dream consolidation can
|
|
65
|
+
keep high-value traces without dropping to the store API.
|
|
66
|
+
"""
|
|
67
|
+
return self.ebbinghaus.remember(
|
|
68
|
+
content=content,
|
|
69
|
+
tags=tags or [],
|
|
70
|
+
salience=salience,
|
|
71
|
+
valence=valence,
|
|
72
|
+
source=source,
|
|
73
|
+
session_id=session_id,
|
|
74
|
+
memory_type=memory_type,
|
|
75
|
+
)
|
|
40
76
|
|
|
41
77
|
def recall(self, query: str, top_k: int = 5) -> list[dict[str, Any]]:
|
|
42
78
|
return self.ebbinghaus.recall(query, limit=top_k)
|
|
43
79
|
|
|
44
|
-
def sleep(
|
|
45
|
-
|
|
80
|
+
def sleep(
|
|
81
|
+
self,
|
|
82
|
+
**sleep_kwargs: Any,
|
|
83
|
+
) -> dict[str, Any]:
|
|
84
|
+
"""Run one sleep-cycle consolidation pass (optional kwargs forwarded)."""
|
|
85
|
+
return self.ebbinghaus.sleep_cycle(**sleep_kwargs)
|
|
46
86
|
|
|
47
87
|
def add_node(self, node: dict[str, Any]) -> dict[str, Any]:
|
|
48
88
|
self.semantic.ensure_ready()
|
|
@@ -54,7 +94,24 @@ class CompositeMemory:
|
|
|
54
94
|
*,
|
|
55
95
|
top_k: int = 8,
|
|
56
96
|
backend: Optional[EmbeddingBackend] = None,
|
|
97
|
+
speculative: bool = False,
|
|
98
|
+
margin_threshold: float = 0.0,
|
|
99
|
+
min_top_score: float = 0.55,
|
|
57
100
|
) -> list[dict[str, Any]]:
|
|
101
|
+
"""Hybrid lexical + dense search. Pass ``backend`` for embedding quality.
|
|
102
|
+
|
|
103
|
+
When ``speculative=True`` and ``backend`` is set, lexical drafts early-accept
|
|
104
|
+
on high margin; otherwise dense hybrid verifies (speculative-hybrid path).
|
|
105
|
+
"""
|
|
106
|
+
if speculative and backend is not None:
|
|
107
|
+
return speculative_hybrid_search_and_rank(
|
|
108
|
+
self.semantic,
|
|
109
|
+
query,
|
|
110
|
+
backend=backend,
|
|
111
|
+
top_k=top_k,
|
|
112
|
+
margin_threshold=margin_threshold,
|
|
113
|
+
min_top_score=min_top_score,
|
|
114
|
+
)
|
|
58
115
|
return hybrid_search_and_rank(
|
|
59
116
|
self.semantic,
|
|
60
117
|
query,
|
|
@@ -66,6 +123,8 @@ class CompositeMemory:
|
|
|
66
123
|
|
|
67
124
|
def ingest_document(self, path: Path, **kwargs: Any) -> dict[str, Any]:
|
|
68
125
|
"""Ingest a document file and store it with chunks."""
|
|
126
|
+
from hakua_memory.rag.ingestion import ingest_document
|
|
127
|
+
|
|
69
128
|
doc, chunks = ingest_document(path, **kwargs)
|
|
70
129
|
self.documents.insert_document(doc)
|
|
71
130
|
chunk_ids = self.documents.insert_chunks(chunks)
|
|
@@ -78,6 +137,8 @@ class CompositeMemory:
|
|
|
78
137
|
|
|
79
138
|
def ingest_markdown(self, text: str, **kwargs: Any) -> dict[str, Any]:
|
|
80
139
|
"""Ingest a markdown string."""
|
|
140
|
+
from hakua_memory.rag.ingestion import ingest_markdown_string
|
|
141
|
+
|
|
81
142
|
doc, chunks = ingest_markdown_string(text, **kwargs)
|
|
82
143
|
self.documents.insert_document(doc)
|
|
83
144
|
chunk_ids = self.documents.insert_chunks(chunks)
|
|
@@ -89,6 +150,8 @@ class CompositeMemory:
|
|
|
89
150
|
|
|
90
151
|
def ingest_text(self, text: str, **kwargs: Any) -> dict[str, Any]:
|
|
91
152
|
"""Ingest a plain text string."""
|
|
153
|
+
from hakua_memory.rag.ingestion import ingest_text_string
|
|
154
|
+
|
|
92
155
|
doc, chunks = ingest_text_string(text, **kwargs)
|
|
93
156
|
self.documents.insert_document(doc)
|
|
94
157
|
chunk_ids = self.documents.insert_chunks(chunks)
|
|
@@ -108,6 +171,8 @@ class CompositeMemory:
|
|
|
108
171
|
department: str = "",
|
|
109
172
|
) -> list[dict[str, Any]]:
|
|
110
173
|
"""Search ingested documents with full-text search."""
|
|
174
|
+
from hakua_memory.rag.retrieval import search_chunks
|
|
175
|
+
|
|
111
176
|
results = search_chunks(
|
|
112
177
|
self.documents,
|
|
113
178
|
query,
|
|
@@ -126,8 +191,9 @@ class CompositeMemory:
|
|
|
126
191
|
format: str = "markdown",
|
|
127
192
|
) -> str:
|
|
128
193
|
"""Render citation context from search results."""
|
|
129
|
-
|
|
130
|
-
|
|
194
|
+
from hakua_memory.rag.retrieval import RagResult, render_citation_context
|
|
195
|
+
|
|
196
|
+
rag_results: list[RagResult] = []
|
|
131
197
|
for r in results:
|
|
132
198
|
chunk = self.documents.get_chunk(r["chunk_id"])
|
|
133
199
|
doc = self.documents.get_document(r["document_id"])
|
|
@@ -146,6 +212,8 @@ class CompositeMemory:
|
|
|
146
212
|
self, document_id: str, *, auto_store: bool = True
|
|
147
213
|
) -> list[dict[str, Any]]:
|
|
148
214
|
"""Extract meeting items (decisions, tasks, action items) from a document."""
|
|
215
|
+
from hakua_memory.rag.meeting import extract_meeting_items
|
|
216
|
+
|
|
149
217
|
chunks = self._get_chunks(document_id)
|
|
150
218
|
items = extract_meeting_items(
|
|
151
219
|
document_id, chunks, store=self.documents, auto_store=auto_store
|
|
@@ -169,6 +237,8 @@ class CompositeMemory:
|
|
|
169
237
|
min_confidence: float = 0.6,
|
|
170
238
|
) -> list[dict[str, Any]]:
|
|
171
239
|
"""Detect contradictions between documents."""
|
|
240
|
+
from hakua_memory.rag.contradiction import detect_contradictions
|
|
241
|
+
|
|
172
242
|
contradictions = detect_contradictions(
|
|
173
243
|
self.documents,
|
|
174
244
|
document_ids=document_ids,
|
|
@@ -198,6 +268,8 @@ class CompositeMemory:
|
|
|
198
268
|
permission: "read", "write", or "delete".
|
|
199
269
|
department: Optional department scope.
|
|
200
270
|
"""
|
|
271
|
+
from hakua_memory.rag.models import AclEntry
|
|
272
|
+
|
|
201
273
|
entry = AclEntry(
|
|
202
274
|
document_id=document_id,
|
|
203
275
|
principal=principal,
|
|
@@ -232,26 +304,28 @@ class CompositeMemory:
|
|
|
232
304
|
|
|
233
305
|
def _get_chunks(self, document_id: str) -> list:
|
|
234
306
|
"""Get all chunks for a document."""
|
|
235
|
-
|
|
236
|
-
conn.row_factory = sqlite3.Row
|
|
237
|
-
rows = conn.execute(
|
|
238
|
-
"SELECT * FROM chunks WHERE document_id = ? ORDER BY chunk_index",
|
|
239
|
-
(document_id,),
|
|
240
|
-
).fetchall()
|
|
241
|
-
from hakua_memory.rag.store import _row_to_chunk
|
|
242
|
-
return [_row_to_chunk(row) for row in rows]
|
|
307
|
+
return self.documents.list_chunks_for_document(document_id)
|
|
243
308
|
|
|
244
309
|
def close(self) -> None:
|
|
245
310
|
"""Close all underlying stores."""
|
|
246
311
|
self.ebbinghaus.close()
|
|
312
|
+
self.semantic.close()
|
|
313
|
+
if self._documents is not None:
|
|
314
|
+
self._documents.close()
|
|
315
|
+
self._documents = None
|
|
247
316
|
|
|
248
317
|
def export_wiki(self, wiki_root: Path) -> dict[str, Any]:
|
|
249
318
|
path = write_diary(wiki_root, "composite-export", "# CompositeMemory export\n")
|
|
250
319
|
return {"diary": str(path)}
|
|
251
320
|
|
|
252
321
|
def stats(self) -> dict[str, Any]:
|
|
253
|
-
|
|
322
|
+
result: dict[str, Any] = {
|
|
254
323
|
"ebbinghaus": self.ebbinghaus.stats(),
|
|
255
324
|
"semantic_graph": self.semantic.get_status_counts(),
|
|
256
|
-
"rag": self.documents.stats(),
|
|
257
325
|
}
|
|
326
|
+
if self._documents is not None:
|
|
327
|
+
result["rag"] = self._documents.stats()
|
|
328
|
+
elif self._enable_rag:
|
|
329
|
+
# Keep API shape without forcing RAG open on remember-only paths.
|
|
330
|
+
result["rag"] = {"initialized": False}
|
|
331
|
+
return result
|