hakua-memory 0.2.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 (51) hide show
  1. hakua_memory-0.2.0/LICENSE +201 -0
  2. hakua_memory-0.2.0/PKG-INFO +238 -0
  3. hakua_memory-0.2.0/README.md +213 -0
  4. hakua_memory-0.2.0/pyproject.toml +40 -0
  5. hakua_memory-0.2.0/setup.cfg +4 -0
  6. hakua_memory-0.2.0/src/hakua_memory/__init__.py +21 -0
  7. hakua_memory-0.2.0/src/hakua_memory/composite.py +257 -0
  8. hakua_memory-0.2.0/src/hakua_memory/config.py +168 -0
  9. hakua_memory-0.2.0/src/hakua_memory/ebbinghaus/__init__.py +862 -0
  10. hakua_memory-0.2.0/src/hakua_memory/ebbinghaus/experience.py +1488 -0
  11. hakua_memory-0.2.0/src/hakua_memory/ebbinghaus/migrations.py +362 -0
  12. hakua_memory-0.2.0/src/hakua_memory/ebbinghaus/models.py +85 -0
  13. hakua_memory-0.2.0/src/hakua_memory/ebbinghaus/policies.py +529 -0
  14. hakua_memory-0.2.0/src/hakua_memory/ebbinghaus/semantic_graph_bridge.py +764 -0
  15. hakua_memory-0.2.0/src/hakua_memory/ebbinghaus/store.py +2736 -0
  16. hakua_memory-0.2.0/src/hakua_memory/obsidian/__init__.py +32 -0
  17. hakua_memory-0.2.0/src/hakua_memory/obsidian/templates.py +212 -0
  18. hakua_memory-0.2.0/src/hakua_memory/rag/__init__.py +36 -0
  19. hakua_memory-0.2.0/src/hakua_memory/rag/chunking.py +150 -0
  20. hakua_memory-0.2.0/src/hakua_memory/rag/contradiction.py +228 -0
  21. hakua_memory-0.2.0/src/hakua_memory/rag/ingestion.py +260 -0
  22. hakua_memory-0.2.0/src/hakua_memory/rag/meeting.py +150 -0
  23. hakua_memory-0.2.0/src/hakua_memory/rag/models.py +156 -0
  24. hakua_memory-0.2.0/src/hakua_memory/rag/retrieval.py +235 -0
  25. hakua_memory-0.2.0/src/hakua_memory/rag/schema.py +159 -0
  26. hakua_memory-0.2.0/src/hakua_memory/rag/store.py +539 -0
  27. hakua_memory-0.2.0/src/hakua_memory/semantic_graph/__init__.py +23 -0
  28. hakua_memory-0.2.0/src/hakua_memory/semantic_graph/cli.py +161 -0
  29. hakua_memory-0.2.0/src/hakua_memory/semantic_graph/cognitive.py +174 -0
  30. hakua_memory-0.2.0/src/hakua_memory/semantic_graph/config.py +273 -0
  31. hakua_memory-0.2.0/src/hakua_memory/semantic_graph/embedding/__init__.py +45 -0
  32. hakua_memory-0.2.0/src/hakua_memory/semantic_graph/embedding/base.py +57 -0
  33. hakua_memory-0.2.0/src/hakua_memory/semantic_graph/embedding/fake.py +78 -0
  34. hakua_memory-0.2.0/src/hakua_memory/semantic_graph/embedding/llama_cpp.py +221 -0
  35. hakua_memory-0.2.0/src/hakua_memory/semantic_graph/embedding/serializer.py +65 -0
  36. hakua_memory-0.2.0/src/hakua_memory/semantic_graph/embedding/vectors.py +144 -0
  37. hakua_memory-0.2.0/src/hakua_memory/semantic_graph/exporter.py +132 -0
  38. hakua_memory-0.2.0/src/hakua_memory/semantic_graph/fusion.py +85 -0
  39. hakua_memory-0.2.0/src/hakua_memory/semantic_graph/graph.py +480 -0
  40. hakua_memory-0.2.0/src/hakua_memory/semantic_graph/inference.py +103 -0
  41. hakua_memory-0.2.0/src/hakua_memory/semantic_graph/models.py +156 -0
  42. hakua_memory-0.2.0/src/hakua_memory/semantic_graph/retrieval.py +235 -0
  43. hakua_memory-0.2.0/src/hakua_memory/semantic_graph/runtime.py +1185 -0
  44. hakua_memory-0.2.0/src/hakua_memory/semantic_graph/sanitize.py +164 -0
  45. hakua_memory-0.2.0/src/hakua_memory/semantic_graph/schemas.py +462 -0
  46. hakua_memory-0.2.0/src/hakua_memory/semantic_graph/store.py +1533 -0
  47. hakua_memory-0.2.0/src/hakua_memory.egg-info/PKG-INFO +238 -0
  48. hakua_memory-0.2.0/src/hakua_memory.egg-info/SOURCES.txt +49 -0
  49. hakua_memory-0.2.0/src/hakua_memory.egg-info/dependency_links.txt +1 -0
  50. hakua_memory-0.2.0/src/hakua_memory.egg-info/requires.txt +19 -0
  51. hakua_memory-0.2.0/src/hakua_memory.egg-info/top_level.txt +1 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorised by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorised to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative Works
95
+ a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Hakua
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,238 @@
1
+ Metadata-Version: 2.4
2
+ Name: hakua-memory
3
+ Version: 0.2.0
4
+ Summary: Composite memory library: Ebbinghaus + Semantic Graph + RAG + Obsidian Wiki
5
+ Author: Hakua
6
+ License: 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: pyyaml>=6; extra == "all"
24
+ Dynamic: license-file
25
+
26
+ # hakua-memory
27
+
28
+ > **TL;DR:** `hakua-memory` is a self-contained Python memory library for autonomous agents. It combines SQLite-backed Ebbinghaus memory, a structured semantic graph, optional embedding-based retrieval, RAG (Retrieval-Augmented Generation) with citation tracking and ACL filtering, sleep-cycle consolidation, and Obsidian-compatible diary and dream exports behind a small, composable API.
29
+
30
+ ## Overview
31
+
32
+ Long-running agents need more than a vector index. They need memories that can decay, be reinforced, be inspected as structured claims, and be exported into a human-readable knowledge base.
33
+
34
+ `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.
35
+
36
+ ## Features
37
+
38
+ - **Ebbinghaus memory store**
39
+ - SQLite persistence
40
+ - Retention and forgetting-curve calculations
41
+ - Recall scoring and reinforcement
42
+ - Salience, valence, tags, and memory-state handling
43
+ - Sleep-cycle rehearsal, archival, pruning, and dream candidates
44
+ - **Semantic Graph**
45
+ - SQLite graph storage
46
+ - Typed nodes, edges, evidence, fragments, and evaluations
47
+ - Full-text search where available
48
+ - Sanitisation and deterministic data handling
49
+ - **Embedding retrieval**
50
+ - Pluggable embedding backend contract
51
+ - Deterministic fake backend for tests and demonstrations
52
+ - Optional `llama-cpp-python` backend
53
+ - Versioned embedding namespaces and dimension validation
54
+ - Hybrid lexical/dense retrieval with deterministic reciprocal-rank fusion
55
+ - **RAG (Retrieval-Augmented Generation)**
56
+ - Document ingestion (PDF, DOCX, PPTX, Markdown, plain text)
57
+ - Page/slide/section-aware chunking with provenance
58
+ - Document version management
59
+ - ACL (Access Control List) filtering per document
60
+ - Citation context rendering (Markdown + XML)
61
+ - Meeting item extraction (decisions, tasks, action items, unresolved items)
62
+ - Contradiction detection between documents
63
+ - CJK-aware search with FTS + LIKE fallback
64
+ - **Obsidian export**
65
+ - Diary and dream markdown exports
66
+ - Human-readable files suitable for an Obsidian vault
67
+ - **Single composite API**
68
+ - One entry point for remembering, recalling, graph updates, RAG operations, retrieval, sleep, export, and status reporting
69
+
70
+ ## Installation
71
+
72
+ Python 3.11, 3.12, and 3.13 are supported.
73
+
74
+ ```bash
75
+ python -m pip install hakua-memory
76
+ ```
77
+
78
+ For local development:
79
+
80
+ ```bash
81
+ python -m pip install -e ".[dev]"
82
+ ```
83
+
84
+ Optional extras:
85
+
86
+ ```bash
87
+ # Obsidian/Git integration helpers
88
+ python -m pip install "hakua-memory[obsidian]"
89
+
90
+ # llama.cpp embedding support
91
+ python -m pip install "hakua-memory[embedding]"
92
+
93
+ # RAG document ingestion (PDF/DOCX/PPTX)
94
+ python -m pip install "hakua-memory[rag]"
95
+ ```
96
+
97
+ ## Quick start
98
+
99
+ ```python
100
+ from pathlib import Path
101
+
102
+ from hakua_memory import CompositeMemory
103
+
104
+ memory = CompositeMemory(Path(".memory"))
105
+
106
+ memory.remember(
107
+ "The user prefers concise, verifiable reports.",
108
+ tags=["user-preference", "communication"],
109
+ )
110
+
111
+ matches = memory.recall("verifiable reports")
112
+ print(matches)
113
+
114
+ memory.add_node(
115
+ {
116
+ "node_id": "claim-1",
117
+ "node_type": "Claim",
118
+ "label": "Verifiable reporting",
119
+ "summary": "Reports should distinguish observed results from assumptions.",
120
+ "status": "asserted",
121
+ "authority": "user",
122
+ "confidence": 0.95,
123
+ "salience": 0.8,
124
+ "evidence": [],
125
+ }
126
+ )
127
+
128
+ print(memory.stats())
129
+ memory.sleep()
130
+ memory.export_wiki(Path("knowledge-base"))
131
+ ```
132
+
133
+ ## RAG Quick start
134
+
135
+ ```python
136
+ from pathlib import Path
137
+ from hakua_memory import CompositeMemory
138
+
139
+ memory = CompositeMemory(Path(".memory"))
140
+
141
+ # Ingest a PDF document
142
+ result = memory.ingest_document(
143
+ Path("meeting_notes.pdf"),
144
+ title="Q3 Planning Meeting",
145
+ author="Alice",
146
+ department="Product",
147
+ )
148
+ print(result) # {'document_id': '...', 'title': '...', 'chunks': 12, ...}
149
+
150
+ # Search with citation tracking
151
+ results = memory.search_documents("release schedule", top_k=5)
152
+ for r in results:
153
+ print(f"[{r['rank']}] {r['document_title']} (p.{r.get('page_number')})")
154
+ print(f" {r['content'][:100]}...")
155
+
156
+ # Render citation context for RAG answers
157
+ context = memory.render_citations(results, format="markdown")
158
+ print(context)
159
+
160
+ # Extract meeting items (decisions, tasks, action items)
161
+ items = memory.extract_meeting_items(results[0]["document_id"])
162
+ for item in items:
163
+ print(f"[{item['item_type']}] {item['content']}")
164
+
165
+ # Grant ACL access and search with filtering
166
+ memory.grant_access(results[0]["document_id"], "alice", "read")
167
+ alice_results = memory.search_documents("schedule", principal="alice")
168
+
169
+ # Detect contradictions between documents
170
+ contradictions = memory.detect_contradictions(min_confidence=0.6)
171
+ for c in contradictions:
172
+ print(f"[{c['type']}] {c['description']}")
173
+ ```
174
+
175
+ ## Embedding retrieval
176
+
177
+ Embedding support is backend-agnostic. The package includes a deterministic fake backend for tests and a contract for production backends.
178
+
179
+ ```python
180
+ from hakua_memory.semantic_graph.embedding.base import EmbeddingModelIdentity
181
+ from hakua_memory.semantic_graph.embedding.fake import DeterministicFakeEmbeddingBackend
182
+
183
+ backend = DeterministicFakeEmbeddingBackend(
184
+ identity=EmbeddingModelIdentity(
185
+ provider="demo",
186
+ model="deterministic",
187
+ revision="1",
188
+ dimensions=8,
189
+ serializer_version=1,
190
+ ),
191
+ vectors={"Verifiable reporting": [1, 2, 3, 4, 5, 6, 7, 8]},
192
+ )
193
+
194
+ results = memory.search("Verifiable reporting", backend=backend)
195
+ ```
196
+
197
+ The retrieval layer validates vector dimensions, records the embedding namespace, and combines lexical and dense rankings without silently mixing incompatible representations.
198
+
199
+ ## Architecture
200
+
201
+ ```text
202
+ CompositeMemory
203
+ ├── EbbinghausMemoryStore ── SQLite memory database
204
+ ├── SemanticGraphStore ──── SQLite graph database
205
+ ├── Hybrid retrieval ────── lexical + optional embedding backend
206
+ └── Obsidian export ──────── diary and dream Markdown files
207
+ ```
208
+
209
+ The package is intentionally independent from Hermes Agent. It can be embedded into another agent runtime, used as a local library, or extended through its backend interfaces.
210
+
211
+ ## Development
212
+
213
+ Run the package checks from the repository root:
214
+
215
+ ```bash
216
+ python -m compileall -q src
217
+ python -m build
218
+ ```
219
+
220
+ The integration path can be exercised with a temporary directory and the deterministic embedding backend, covering:
221
+
222
+ 1. memory insertion and recall;
223
+ 2. semantic-node insertion;
224
+ 3. hybrid search;
225
+ 4. sleep-cycle processing; and
226
+ 5. Obsidian diary export.
227
+
228
+ ## Design notes
229
+
230
+ - SQLite is the persistence boundary; generated databases should normally remain outside the repository.
231
+ - Embedding backends are optional and replaceable.
232
+ - Lexical retrieval remains available when no embedding backend is configured.
233
+ - Numerical verification and formal proof are deliberately separate concerns.
234
+ - Exported Markdown is intended to be inspectable and version-controllable by the user.
235
+
236
+ ## License
237
+
238
+ Apache License 2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,213 @@
1
+ # hakua-memory
2
+
3
+ > **TL;DR:** `hakua-memory` is a self-contained Python memory library for autonomous agents. It combines SQLite-backed Ebbinghaus memory, a structured semantic graph, optional embedding-based retrieval, RAG (Retrieval-Augmented Generation) with citation tracking and ACL filtering, sleep-cycle consolidation, and Obsidian-compatible diary and dream exports behind a small, composable API.
4
+
5
+ ## Overview
6
+
7
+ Long-running agents need more than a vector index. They need memories that can decay, be reinforced, be inspected as structured claims, and be exported into a human-readable knowledge base.
8
+
9
+ `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.
10
+
11
+ ## Features
12
+
13
+ - **Ebbinghaus memory store**
14
+ - SQLite persistence
15
+ - Retention and forgetting-curve calculations
16
+ - Recall scoring and reinforcement
17
+ - Salience, valence, tags, and memory-state handling
18
+ - Sleep-cycle rehearsal, archival, pruning, and dream candidates
19
+ - **Semantic Graph**
20
+ - SQLite graph storage
21
+ - Typed nodes, edges, evidence, fragments, and evaluations
22
+ - Full-text search where available
23
+ - Sanitisation and deterministic data handling
24
+ - **Embedding retrieval**
25
+ - Pluggable embedding backend contract
26
+ - Deterministic fake backend for tests and demonstrations
27
+ - Optional `llama-cpp-python` backend
28
+ - Versioned embedding namespaces and dimension validation
29
+ - Hybrid lexical/dense retrieval with deterministic reciprocal-rank fusion
30
+ - **RAG (Retrieval-Augmented Generation)**
31
+ - Document ingestion (PDF, DOCX, PPTX, Markdown, plain text)
32
+ - Page/slide/section-aware chunking with provenance
33
+ - Document version management
34
+ - ACL (Access Control List) filtering per document
35
+ - Citation context rendering (Markdown + XML)
36
+ - Meeting item extraction (decisions, tasks, action items, unresolved items)
37
+ - Contradiction detection between documents
38
+ - CJK-aware search with FTS + LIKE fallback
39
+ - **Obsidian export**
40
+ - Diary and dream markdown exports
41
+ - Human-readable files suitable for an Obsidian vault
42
+ - **Single composite API**
43
+ - One entry point for remembering, recalling, graph updates, RAG operations, retrieval, sleep, export, and status reporting
44
+
45
+ ## Installation
46
+
47
+ Python 3.11, 3.12, and 3.13 are supported.
48
+
49
+ ```bash
50
+ python -m pip install hakua-memory
51
+ ```
52
+
53
+ For local development:
54
+
55
+ ```bash
56
+ python -m pip install -e ".[dev]"
57
+ ```
58
+
59
+ Optional extras:
60
+
61
+ ```bash
62
+ # Obsidian/Git integration helpers
63
+ python -m pip install "hakua-memory[obsidian]"
64
+
65
+ # llama.cpp embedding support
66
+ python -m pip install "hakua-memory[embedding]"
67
+
68
+ # RAG document ingestion (PDF/DOCX/PPTX)
69
+ python -m pip install "hakua-memory[rag]"
70
+ ```
71
+
72
+ ## Quick start
73
+
74
+ ```python
75
+ from pathlib import Path
76
+
77
+ from hakua_memory import CompositeMemory
78
+
79
+ memory = CompositeMemory(Path(".memory"))
80
+
81
+ memory.remember(
82
+ "The user prefers concise, verifiable reports.",
83
+ tags=["user-preference", "communication"],
84
+ )
85
+
86
+ matches = memory.recall("verifiable reports")
87
+ print(matches)
88
+
89
+ memory.add_node(
90
+ {
91
+ "node_id": "claim-1",
92
+ "node_type": "Claim",
93
+ "label": "Verifiable reporting",
94
+ "summary": "Reports should distinguish observed results from assumptions.",
95
+ "status": "asserted",
96
+ "authority": "user",
97
+ "confidence": 0.95,
98
+ "salience": 0.8,
99
+ "evidence": [],
100
+ }
101
+ )
102
+
103
+ print(memory.stats())
104
+ memory.sleep()
105
+ memory.export_wiki(Path("knowledge-base"))
106
+ ```
107
+
108
+ ## RAG Quick start
109
+
110
+ ```python
111
+ from pathlib import Path
112
+ from hakua_memory import CompositeMemory
113
+
114
+ memory = CompositeMemory(Path(".memory"))
115
+
116
+ # Ingest a PDF document
117
+ result = memory.ingest_document(
118
+ Path("meeting_notes.pdf"),
119
+ title="Q3 Planning Meeting",
120
+ author="Alice",
121
+ department="Product",
122
+ )
123
+ print(result) # {'document_id': '...', 'title': '...', 'chunks': 12, ...}
124
+
125
+ # Search with citation tracking
126
+ results = memory.search_documents("release schedule", top_k=5)
127
+ for r in results:
128
+ print(f"[{r['rank']}] {r['document_title']} (p.{r.get('page_number')})")
129
+ print(f" {r['content'][:100]}...")
130
+
131
+ # Render citation context for RAG answers
132
+ context = memory.render_citations(results, format="markdown")
133
+ print(context)
134
+
135
+ # Extract meeting items (decisions, tasks, action items)
136
+ items = memory.extract_meeting_items(results[0]["document_id"])
137
+ for item in items:
138
+ print(f"[{item['item_type']}] {item['content']}")
139
+
140
+ # Grant ACL access and search with filtering
141
+ memory.grant_access(results[0]["document_id"], "alice", "read")
142
+ alice_results = memory.search_documents("schedule", principal="alice")
143
+
144
+ # Detect contradictions between documents
145
+ contradictions = memory.detect_contradictions(min_confidence=0.6)
146
+ for c in contradictions:
147
+ print(f"[{c['type']}] {c['description']}")
148
+ ```
149
+
150
+ ## Embedding retrieval
151
+
152
+ Embedding support is backend-agnostic. The package includes a deterministic fake backend for tests and a contract for production backends.
153
+
154
+ ```python
155
+ from hakua_memory.semantic_graph.embedding.base import EmbeddingModelIdentity
156
+ from hakua_memory.semantic_graph.embedding.fake import DeterministicFakeEmbeddingBackend
157
+
158
+ backend = DeterministicFakeEmbeddingBackend(
159
+ identity=EmbeddingModelIdentity(
160
+ provider="demo",
161
+ model="deterministic",
162
+ revision="1",
163
+ dimensions=8,
164
+ serializer_version=1,
165
+ ),
166
+ vectors={"Verifiable reporting": [1, 2, 3, 4, 5, 6, 7, 8]},
167
+ )
168
+
169
+ results = memory.search("Verifiable reporting", backend=backend)
170
+ ```
171
+
172
+ The retrieval layer validates vector dimensions, records the embedding namespace, and combines lexical and dense rankings without silently mixing incompatible representations.
173
+
174
+ ## Architecture
175
+
176
+ ```text
177
+ CompositeMemory
178
+ ├── EbbinghausMemoryStore ── SQLite memory database
179
+ ├── SemanticGraphStore ──── SQLite graph database
180
+ ├── Hybrid retrieval ────── lexical + optional embedding backend
181
+ └── Obsidian export ──────── diary and dream Markdown files
182
+ ```
183
+
184
+ The package is intentionally independent from Hermes Agent. It can be embedded into another agent runtime, used as a local library, or extended through its backend interfaces.
185
+
186
+ ## Development
187
+
188
+ Run the package checks from the repository root:
189
+
190
+ ```bash
191
+ python -m compileall -q src
192
+ python -m build
193
+ ```
194
+
195
+ The integration path can be exercised with a temporary directory and the deterministic embedding backend, covering:
196
+
197
+ 1. memory insertion and recall;
198
+ 2. semantic-node insertion;
199
+ 3. hybrid search;
200
+ 4. sleep-cycle processing; and
201
+ 5. Obsidian diary export.
202
+
203
+ ## Design notes
204
+
205
+ - SQLite is the persistence boundary; generated databases should normally remain outside the repository.
206
+ - Embedding backends are optional and replaceable.
207
+ - Lexical retrieval remains available when no embedding backend is configured.
208
+ - Numerical verification and formal proof are deliberately separate concerns.
209
+ - Exported Markdown is intended to be inspectable and version-controllable by the user.
210
+
211
+ ## License
212
+
213
+ Apache License 2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,40 @@
1
+ [build-system]
2
+ requires = ["setuptools>=75", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "hakua-memory"
7
+ version = "0.2.0"
8
+ description = "Composite memory library: Ebbinghaus + Semantic Graph + RAG + Obsidian Wiki"
9
+ readme = "README.md"
10
+ license = {text = "Apache-2.0"}
11
+ requires-python = ">=3.11,<3.14"
12
+ authors = [{name = "Hakua"}]
13
+ dependencies = ["pyyaml>=6"]
14
+
15
+ [project.optional-dependencies]
16
+ obsidian = ["gitpython>=3,<4"]
17
+ embedding = ["llama-cpp-python>=0.3,<1"]
18
+ rag = [
19
+ "pypdf>=4,<5",
20
+ "python-docx>=1,<2",
21
+ "python-pptx>=1,<2",
22
+ ]
23
+ dev = ["pytest>=8", "ruff"]
24
+ all = ["pyyaml>=6"]
25
+
26
+ [tool.setuptools.packages.find]
27
+ where = ["src"]
28
+
29
+ [tool.ruff]
30
+ line-length = 100
31
+ target-version = "py311"
32
+
33
+ [tool.ruff.lint]
34
+ select = ["E", "F", "W", "I"]
35
+ ignore = ["E501"]
36
+
37
+ [tool.ruff.lint.per-file-ignores]
38
+ "scripts/*.py" = ["E402"]
39
+ "src/hakua_memory/semantic_graph/**/*.py" = ["F821", "F841", "F401", "E402"]
40
+ "src/hakua_memory/ebbinghaus/**/*.py" = ["F821", "F841", "F401", "E402"]