hakua-memory 0.2.0__tar.gz → 0.3.4__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/PKG-INFO +415 -0
- hakua_memory-0.3.4/README.md +386 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/pyproject.toml +9 -8
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/ebbinghaus/__init__.py +4 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/ebbinghaus/models.py +17 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/ebbinghaus/store.py +1 -2
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/obsidian/templates.py +4 -1
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/semantic_graph/graph.py +5 -2
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/semantic_graph/retrieval.py +1 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/semantic_graph/store.py +8 -0
- hakua_memory-0.3.4/src/hakua_memory.egg-info/PKG-INFO +415 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory.egg-info/SOURCES.txt +9 -1
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory.egg-info/requires.txt +5 -1
- hakua_memory-0.3.4/tests/test_acl.py +135 -0
- hakua_memory-0.3.4/tests/test_benchmark.py +43 -0
- hakua_memory-0.3.4/tests/test_composite.py +171 -0
- hakua_memory-0.3.4/tests/test_config.py +112 -0
- hakua_memory-0.3.4/tests/test_ebbinghaus.py +28 -0
- hakua_memory-0.3.4/tests/test_embedding_backend.py +98 -0
- hakua_memory-0.3.4/tests/test_integration.py +120 -0
- hakua_memory-0.3.4/tests/test_obsidian.py +90 -0
- hakua_memory-0.2.0/PKG-INFO +0 -238
- hakua_memory-0.2.0/README.md +0 -213
- hakua_memory-0.2.0/src/hakua_memory.egg-info/PKG-INFO +0 -238
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/LICENSE +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/setup.cfg +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/__init__.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/composite.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/config.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/ebbinghaus/experience.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/ebbinghaus/migrations.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/ebbinghaus/policies.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/ebbinghaus/semantic_graph_bridge.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/obsidian/__init__.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/rag/__init__.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/rag/chunking.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/rag/contradiction.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/rag/ingestion.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/rag/meeting.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/rag/models.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/rag/retrieval.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/rag/schema.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/rag/store.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/semantic_graph/__init__.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/semantic_graph/cli.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/semantic_graph/cognitive.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/semantic_graph/config.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/semantic_graph/embedding/__init__.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/semantic_graph/embedding/base.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/semantic_graph/embedding/fake.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/semantic_graph/embedding/llama_cpp.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/semantic_graph/embedding/serializer.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/semantic_graph/embedding/vectors.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/semantic_graph/exporter.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/semantic_graph/fusion.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/semantic_graph/inference.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/semantic_graph/models.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/semantic_graph/runtime.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/semantic_graph/sanitize.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory/semantic_graph/schemas.py +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory.egg-info/dependency_links.txt +0 -0
- {hakua_memory-0.2.0 → hakua_memory-0.3.4}/src/hakua_memory.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hakua-memory
|
|
3
|
+
Version: 0.3.4
|
|
4
|
+
Summary: Composite memory library: Ebbinghaus + Semantic Graph + RAG + Obsidian Wiki
|
|
5
|
+
Author: Hakua
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Requires-Python: <3.14,>=3.11
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: pyyaml>=6
|
|
11
|
+
Provides-Extra: obsidian
|
|
12
|
+
Requires-Dist: gitpython<4,>=3; extra == "obsidian"
|
|
13
|
+
Provides-Extra: embedding
|
|
14
|
+
Requires-Dist: llama-cpp-python<1,>=0.3; extra == "embedding"
|
|
15
|
+
Provides-Extra: rag
|
|
16
|
+
Requires-Dist: pypdf<5,>=4; extra == "rag"
|
|
17
|
+
Requires-Dist: python-docx<2,>=1; extra == "rag"
|
|
18
|
+
Requires-Dist: python-pptx<2,>=1; extra == "rag"
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
21
|
+
Requires-Dist: ruff; extra == "dev"
|
|
22
|
+
Provides-Extra: all
|
|
23
|
+
Requires-Dist: gitpython<4,>=3; extra == "all"
|
|
24
|
+
Requires-Dist: llama-cpp-python<1,>=0.3; extra == "all"
|
|
25
|
+
Requires-Dist: pypdf<5,>=4; extra == "all"
|
|
26
|
+
Requires-Dist: python-docx<2,>=1; extra == "all"
|
|
27
|
+
Requires-Dist: python-pptx<2,>=1; extra == "all"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# hakua-memory
|
|
31
|
+
|
|
32
|
+
> **TL;DR:** `hakua-memory` is a self-contained Python memory library for autonomous agents. It combines SQLite-backed Ebbinghaus memory, a structured semantic graph (CoG), optional embedding-based retrieval, RAG (Retrieval-Augmented Generation) with citation tracking and ACL filtering, sleep-cycle consolidation, cross-source contradiction detection via LLM-as-Judge, and Obsidian-compatible diary and dream exports behind a small, composable API.
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install hakua-memory
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Python 3.11–3.13 are supported. Optional integrations are listed in the
|
|
41
|
+
Installation section below.
|
|
42
|
+
|
|
43
|
+
## Overview
|
|
44
|
+
|
|
45
|
+
Long-running agents need more than a vector index. They need memories that can decay, be reinforced, be inspected as structured claims, be cross-validated across multiple memory systems, and be exported into a human-readable knowledge base.
|
|
46
|
+
|
|
47
|
+
`hakua-memory` provides those building blocks without requiring the Hermes Agent codebase. The package uses a `src/` layout and keeps the main integrations optional where practical.
|
|
48
|
+
|
|
49
|
+
## Features
|
|
50
|
+
|
|
51
|
+
- **Ebbinghaus memory store**
|
|
52
|
+
- SQLite persistence
|
|
53
|
+
- Retention and forgetting-curve calculations
|
|
54
|
+
- Recall scoring and reinforcement
|
|
55
|
+
- Salience, valence, tags, and memory-state handling
|
|
56
|
+
- Sleep-cycle rehearsal, archival, pruning, and dream candidates
|
|
57
|
+
- Japanese vocabulary support for identity-critical concepts
|
|
58
|
+
- **Semantic Graph (Cognitive Graph / CoG)**
|
|
59
|
+
- SQLite graph storage
|
|
60
|
+
- Typed nodes, edges (10+ relation types: causes, contradicts, supports, requires, enables, prevents, relates_to, part_of, precedes, follows), evidence, fragments, and evaluations
|
|
61
|
+
- Full-text search where available
|
|
62
|
+
- Sanitisation and deterministic data handling
|
|
63
|
+
- Cross-domain relationship modeling
|
|
64
|
+
- **Embedding retrieval**
|
|
65
|
+
- Pluggable embedding backend contract
|
|
66
|
+
- Deterministic fake backend for tests and demonstrations
|
|
67
|
+
- Optional `llama-cpp-python` backend
|
|
68
|
+
- Versioned embedding namespaces and dimension validation
|
|
69
|
+
- Hybrid lexical/dense retrieval with deterministic reciprocal-rank fusion
|
|
70
|
+
- **RAG (Retrieval-Augmented Generation)**
|
|
71
|
+
- Document ingestion (PDF, DOCX, PPTX, Markdown, plain text)
|
|
72
|
+
- Page/slide/section-aware chunking with provenance
|
|
73
|
+
- Document version management
|
|
74
|
+
- ACL (Access Control List) filtering per document
|
|
75
|
+
- Citation context rendering (Markdown + XML)
|
|
76
|
+
- Meeting item extraction (decisions, tasks, action items, unresolved items)
|
|
77
|
+
- Contradiction detection between documents
|
|
78
|
+
- CJK-aware search with FTS + LIKE fallback
|
|
79
|
+
- **Cross-source Contradiction Detection (LLM-as-Judge)**
|
|
80
|
+
- Triangulation across Ebbinghaus, RAG, and Semantic Graph
|
|
81
|
+
- Structured prompts for LLM-based judgment
|
|
82
|
+
- 5 contradiction types: factual, numerical, causal, temporal, confidence
|
|
83
|
+
- Hermes Agent LLM integration (gpt-5.6-luna, openai-codex, etc.)
|
|
84
|
+
- JSON-structured output for automated processing
|
|
85
|
+
- **Obsidian export**
|
|
86
|
+
- Diary and dream markdown exports
|
|
87
|
+
- Human-readable files suitable for an Obsidian vault
|
|
88
|
+
- **Single composite API**
|
|
89
|
+
- One entry point for remembering, recalling, graph updates, RAG operations, retrieval, sleep, export, and status reporting
|
|
90
|
+
|
|
91
|
+
## Installation
|
|
92
|
+
|
|
93
|
+
Python 3.11, 3.12, and 3.13 are supported.
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pip install hakua-memory
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
For local development:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
pip install -e ".[dev]"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Optional extras:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
pip install "hakua-memory[rag]" # PDF/DOCX/PPTX ingestion
|
|
109
|
+
pip install "hakua-memory[embedding]" # llama.cpp embeddings
|
|
110
|
+
pip install "hakua-memory[obsidian]" # Obsidian helpers
|
|
111
|
+
pip install "hakua-memory[all]" # all optional integrations
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The `all` extra is the union of the `obsidian`, `embedding`, and `rag` integration
|
|
115
|
+
dependencies. `pyyaml` is installed by the base package.
|
|
116
|
+
|
|
117
|
+
## Quick start
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from pathlib import Path
|
|
121
|
+
from hakua_memory import CompositeMemory
|
|
122
|
+
|
|
123
|
+
memory = CompositeMemory(Path("~/.hakua-memory").expanduser())
|
|
124
|
+
|
|
125
|
+
memory.remember(
|
|
126
|
+
"The user prefers concise, verifiable reports.",
|
|
127
|
+
tags=["user-preference", "communication"],
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
matches = memory.recall("verifiable reports")
|
|
131
|
+
print(matches)
|
|
132
|
+
|
|
133
|
+
memory.add_node(
|
|
134
|
+
{
|
|
135
|
+
"node_id": "claim-1",
|
|
136
|
+
"node_type": "Claim",
|
|
137
|
+
"label": "Verifiable reporting",
|
|
138
|
+
"summary": "Reports should distinguish observed results from assumptions.",
|
|
139
|
+
"status": "asserted",
|
|
140
|
+
"authority": "user",
|
|
141
|
+
"confidence": 0.95,
|
|
142
|
+
"salience": 0.8,
|
|
143
|
+
"evidence": [],
|
|
144
|
+
}
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
results = memory.search("Verifiable reporting")
|
|
148
|
+
print(results)
|
|
149
|
+
|
|
150
|
+
print(memory.stats())
|
|
151
|
+
memory.sleep()
|
|
152
|
+
memory.export_wiki(Path("~/.hakua-memory/wiki").expanduser())
|
|
153
|
+
memory.close()
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## RAG Quick start
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
from pathlib import Path
|
|
160
|
+
from hakua_memory import CompositeMemory
|
|
161
|
+
|
|
162
|
+
memory = CompositeMemory(Path("~/.hakua-memory").expanduser())
|
|
163
|
+
result = memory.ingest_text(
|
|
164
|
+
"Decision: the release schedule is Friday. Task: Alice will confirm the schedule.",
|
|
165
|
+
title="Q3 Planning Meeting",
|
|
166
|
+
author="Alice",
|
|
167
|
+
department="Product",
|
|
168
|
+
)
|
|
169
|
+
print(result)
|
|
170
|
+
|
|
171
|
+
results = memory.search_documents("release schedule", top_k=5)
|
|
172
|
+
context = memory.render_citations(results, format="markdown")
|
|
173
|
+
print(context)
|
|
174
|
+
|
|
175
|
+
items = memory.extract_meeting_items(result["document_id"])
|
|
176
|
+
for item in items:
|
|
177
|
+
print(f"[{item['item_type']}] {item['content']}")
|
|
178
|
+
|
|
179
|
+
memory.grant_access(result["document_id"], "alice", "read")
|
|
180
|
+
alice_results = memory.search_documents("schedule", principal="alice")
|
|
181
|
+
print(alice_results)
|
|
182
|
+
print(memory.detect_contradictions(min_confidence=0.6))
|
|
183
|
+
memory.close()
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Cross-source Contradiction Detection (LLM-as-Judge)
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
from pathlib import Path
|
|
190
|
+
from hakua_memory import CompositeMemory
|
|
191
|
+
from scripts.contradiction_detector import ContradictionDetector
|
|
192
|
+
|
|
193
|
+
memory = CompositeMemory(Path("~/.hakua-memory").expanduser())
|
|
194
|
+
detector = ContradictionDetector(memory)
|
|
195
|
+
|
|
196
|
+
# Detect contradictions across all three memory systems
|
|
197
|
+
queries = [
|
|
198
|
+
"キャッシュフロー分析",
|
|
199
|
+
"マイクロサービスアーキテクチャ",
|
|
200
|
+
"医療DX推進",
|
|
201
|
+
]
|
|
202
|
+
|
|
203
|
+
for query in queries:
|
|
204
|
+
# Get the judge prompt for LLM evaluation
|
|
205
|
+
prompt = detector.get_judge_prompt(query)
|
|
206
|
+
|
|
207
|
+
# Send to Hermes Agent / LLM for judgment
|
|
208
|
+
# llm_response = hermes_agent.chat(prompt)
|
|
209
|
+
# result = json.loads(llm_response)
|
|
210
|
+
|
|
211
|
+
print(f"Query: {query}")
|
|
212
|
+
print(f"Prompt ready for LLM evaluation")
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
**Detected Contradictions (v0.3.0):**
|
|
216
|
+
|
|
217
|
+
| Query | Contradiction | Type | Confidence | Sources |
|
|
218
|
+
|-------|--------------|------|------------|---------|
|
|
219
|
+
| キャッシュフロー分析 | ✅ True | factual | 0.85 | Ebbinghaus vs RAG vs CoG |
|
|
220
|
+
| マイクロサービスアーキテクチャ | ✅ True | factual | 0.90 | Ebbinghaus/CoG vs RAG |
|
|
221
|
+
| 医療DX推進 | False | none | 0.80 | - |
|
|
222
|
+
|
|
223
|
+
**Contradiction Types:**
|
|
224
|
+
- `factual` - 事実の矛盾 (同じ事象について異なる事実)
|
|
225
|
+
- `numerical` - 数値の矛盾 (同じ指標について異なる数値)
|
|
226
|
+
- `causal` - 因果関係の矛盾 (異なる原因・結果)
|
|
227
|
+
- `temporal` - 時系列の矛盾 (異なる時期・順序)
|
|
228
|
+
- `confidence` - 確信度の乖離 (高確信度同士で内容が食い違う)
|
|
229
|
+
|
|
230
|
+
## Embedding retrieval
|
|
231
|
+
|
|
232
|
+
Embedding support is backend-agnostic. The package includes a deterministic fake backend for tests and a contract for production backends.
|
|
233
|
+
|
|
234
|
+
```python
|
|
235
|
+
from hakua_memory.semantic_graph.embedding.base import EmbeddingModelIdentity
|
|
236
|
+
from hakua_memory.semantic_graph.embedding.fake import DeterministicFakeEmbeddingBackend
|
|
237
|
+
|
|
238
|
+
backend = DeterministicFakeEmbeddingBackend(
|
|
239
|
+
identity=EmbeddingModelIdentity(
|
|
240
|
+
provider="demo",
|
|
241
|
+
model="deterministic",
|
|
242
|
+
revision="1",
|
|
243
|
+
dimensions=8,
|
|
244
|
+
serializer_version=1,
|
|
245
|
+
),
|
|
246
|
+
vectors={"Verifiable reporting": [1, 2, 3, 4, 5, 6, 7, 8]},
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
results = memory.search("Verifiable reporting", backend=backend)
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
The retrieval layer validates vector dimensions, records the embedding namespace, and combines lexical and dense rankings without silently mixing incompatible representations.
|
|
253
|
+
|
|
254
|
+
## Performance comparison
|
|
255
|
+
|
|
256
|
+
### Internal reproducible measurements
|
|
257
|
+
|
|
258
|
+
Run the RAG chunking, semantic-graph lexical retrieval, and Ebbinghaus recall
|
|
259
|
+
operations with one deterministic dataset and query configuration:
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
python scripts/generate_synthetic_data.py \
|
|
263
|
+
--seed 42 \
|
|
264
|
+
--samples 40 \
|
|
265
|
+
--output synthetic_business_dataset.json
|
|
266
|
+
python scripts/benchmark_cross_validation.py \
|
|
267
|
+
--seed 42 \
|
|
268
|
+
--samples 40 \
|
|
269
|
+
--warmup 5 \
|
|
270
|
+
--repetitions 30 \
|
|
271
|
+
--output benchmark-results.json
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
The benchmark output is machine-readable JSON containing package version, commit SHA,
|
|
275
|
+
timestamp, operating system, Python version, CPU, dataset id, seed, sample count, warmup
|
|
276
|
+
count, repetition count, and mean, median, standard deviation, p50, p95, and p99 latency
|
|
277
|
+
for every measured operation. No GPU is used by this harness. Generated JSON, SQLite
|
|
278
|
+
state, and temporary benchmark databases are not version-controlled;
|
|
279
|
+
`benchmarks/synthetic_dataset_config.json` records the dataset recipe and expected
|
|
280
|
+
summary.
|
|
281
|
+
|
|
282
|
+
Only measurements produced by this repository's harness should be described as internal
|
|
283
|
+
results. Values depend on the recorded machine, dataset, seed, warmup, and repetitions.
|
|
284
|
+
|
|
285
|
+
### Cross-library validation on the same hardware
|
|
286
|
+
|
|
287
|
+
The optional comparison harness uses the same corpus, query set, warmup count, repetition
|
|
288
|
+
count, and randomized variant order for every paired measurement. It compares RAG
|
|
289
|
+
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.
|
|
293
|
+
|
|
294
|
+
Create a separate environment and run the comparison as follows:
|
|
295
|
+
|
|
296
|
+
```bash
|
|
297
|
+
python -m venv .venv-benchmark
|
|
298
|
+
# Activate .venv-benchmark for your shell, then run:
|
|
299
|
+
python -m pip install -e .
|
|
300
|
+
python -m pip install -r benchmarks/requirements.txt
|
|
301
|
+
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
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
The comparison JSON records exact library versions, host metadata, configurations, raw
|
|
306
|
+
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.
|
|
312
|
+
|
|
313
|
+
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.
|
|
317
|
+
|
|
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.
|
|
323
|
+
|
|
324
|
+
| Operation | Variant | Mean | Median | Stdev | P95 | 95% CI |
|
|
325
|
+
|---|---|---:|---:|---:|---:|---:|
|
|
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.
|
|
344
|
+
|
|
345
|
+
### External references
|
|
346
|
+
|
|
347
|
+
The measured comparison uses [LangChain Text Splitters](https://docs.langchain.com/oss/python/integrations/splitters/recursive_text_splitter),
|
|
348
|
+
[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.
|
|
352
|
+
|
|
353
|
+
## Reproducible synthetic data
|
|
354
|
+
|
|
355
|
+
The generator is deterministic for a given seed and sample count. Its schema version,
|
|
356
|
+
generator version, defaults, and expected summary are recorded in
|
|
357
|
+
`benchmarks/synthetic_dataset_config.json`. Use a different output path when retaining
|
|
358
|
+
multiple datasets; generated files remain ignored by Git.
|
|
359
|
+
|
|
360
|
+
## Architecture
|
|
361
|
+
|
|
362
|
+
```text
|
|
363
|
+
CompositeMemory
|
|
364
|
+
├── EbbinghausMemoryStore ── SQLite memory database (forgetting curves, salience)
|
|
365
|
+
├── SemanticGraphStore ──── SQLite graph database (nodes, 10 edge types, evidence)
|
|
366
|
+
├── Hybrid retrieval ────── lexical + optional embedding backend
|
|
367
|
+
├── Contradiction Detector ─ LLM-as-Judge across 3 memory systems
|
|
368
|
+
└── Obsidian export ──────── diary and dream Markdown files
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
### Semantic Graph Edge Types
|
|
372
|
+
|
|
373
|
+
| Type | Japanese | Description |
|
|
374
|
+
|------|----------|-------------|
|
|
375
|
+
| `causes` | 原因 | A causes B |
|
|
376
|
+
| `contradicts` | 矛盾 | A contradicts B |
|
|
377
|
+
| `supports` | 支持 | A supports B |
|
|
378
|
+
| `requires` | 必要 | A requires B |
|
|
379
|
+
| `enables` | 可能にする | A enables B |
|
|
380
|
+
| `prevents` | 防止 | A prevents B |
|
|
381
|
+
| `relates_to` | 関連 | A relates to B |
|
|
382
|
+
| `part_of` | 一部 | A is part of B |
|
|
383
|
+
| `precedes` | 先行 | A precedes B |
|
|
384
|
+
| `follows` | 後続 | A follows B |
|
|
385
|
+
|
|
386
|
+
## Development
|
|
387
|
+
|
|
388
|
+
Run the package checks from the repository root:
|
|
389
|
+
|
|
390
|
+
```bash
|
|
391
|
+
python -m compileall -q src
|
|
392
|
+
python -m build
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
The integration path can be exercised with a temporary directory and the deterministic embedding backend, covering:
|
|
396
|
+
|
|
397
|
+
1. memory insertion and recall;
|
|
398
|
+
2. semantic-node insertion;
|
|
399
|
+
3. hybrid search;
|
|
400
|
+
4. sleep-cycle processing; and
|
|
401
|
+
5. Obsidian diary export.
|
|
402
|
+
|
|
403
|
+
## Design notes
|
|
404
|
+
|
|
405
|
+
- SQLite is the persistence boundary; generated databases should normally remain outside the repository.
|
|
406
|
+
- Embedding backends are optional and replaceable.
|
|
407
|
+
- Lexical retrieval remains available when no embedding backend is configured.
|
|
408
|
+
- Numerical verification and formal proof are deliberately separate concerns.
|
|
409
|
+
- Exported Markdown is intended to be inspectable and version-controllable by the user.
|
|
410
|
+
- Japanese vocabulary is used for identity-critical concepts (Hermes Agent = はくあ, etc.)
|
|
411
|
+
- Cross-source contradiction detection requires LLM Judge (Hermes Agent integration provided)
|
|
412
|
+
|
|
413
|
+
## License
|
|
414
|
+
|
|
415
|
+
Apache License 2.0. See [LICENSE](LICENSE).
|