lorien-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.
@@ -0,0 +1,31 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.egg-info/
6
+ dist/
7
+ build/
8
+ .eggs/
9
+
10
+ # Virtual environment
11
+ .venv/
12
+ venv/
13
+ env/
14
+
15
+ # Testing
16
+ .pytest_cache/
17
+ .coverage
18
+ htmlcov/
19
+
20
+ # Kuzu DB data
21
+ *.kuzu/
22
+ .lorien/
23
+
24
+ # IDE
25
+ .vscode/
26
+ .idea/
27
+ *.swp
28
+ *.swo
29
+
30
+ # macOS
31
+ .DS_Store
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 paperbags1103-hash
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,234 @@
1
+ Metadata-Version: 2.4
2
+ Name: lorien-memory
3
+ Version: 0.2.0
4
+ Summary: Local-first personal knowledge graph for AI agents — ontology, causal chains, contradiction detection
5
+ Project-URL: Homepage, https://github.com/paperbags1103-hash/lorien
6
+ Project-URL: Repository, https://github.com/paperbags1103-hash/lorien
7
+ Project-URL: Issues, https://github.com/paperbags1103-hash/lorien/issues
8
+ Author: paperbags1103-hash
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: agents,ai,contradiction-detection,knowledge-graph,kuzu,llm,local-first,memory,ontology
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Database
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Requires-Python: >=3.12
20
+ Requires-Dist: click>=8.0
21
+ Requires-Dist: kuzu>=0.8.0
22
+ Provides-Extra: all
23
+ Requires-Dist: numpy>=1.24; extra == 'all'
24
+ Requires-Dist: openai>=1.0; extra == 'all'
25
+ Requires-Dist: sentence-transformers>=2.7.0; extra == 'all'
26
+ Provides-Extra: dev
27
+ Requires-Dist: hatchling; extra == 'dev'
28
+ Requires-Dist: pytest>=8.0; extra == 'dev'
29
+ Provides-Extra: llm
30
+ Requires-Dist: openai>=1.0; extra == 'llm'
31
+ Provides-Extra: vectors
32
+ Requires-Dist: numpy>=1.24; extra == 'vectors'
33
+ Requires-Dist: sentence-transformers>=2.7.0; extra == 'vectors'
34
+ Description-Content-Type: text/markdown
35
+
36
+ # 🌳 lorien
37
+
38
+ **Local-first personal knowledge graph for AI agents.**
39
+ What to believe, why, and what conflicts — structured memory that Mem0 can't do.
40
+
41
+ ```bash
42
+ pip install lorien-memory # core (KuzuDB + CLI)
43
+ pip install "lorien-memory[vectors]" # + semantic search
44
+ ```
45
+
46
+ ---
47
+
48
+ ## Why lorien?
49
+
50
+ | Feature | Mem0 | lorien |
51
+ |---------|------|--------|
52
+ | Conversation memory | ✅ | ✅ |
53
+ | Semantic vector search | ✅ | ✅ |
54
+ | Local (no server) | ❌ | ✅ |
55
+ | Cost | $249/mo | **$0** |
56
+ | Priority rule system | ❌ | ✅ |
57
+ | Causal reasoning (CAUSED) | ❌ | ✅ |
58
+ | **Auto contradiction detection** | ❌ | ✅ |
59
+
60
+ lorien stores *structured knowledge* — not just flat strings. Every fact has a source, every rule has a priority, and contradictions are detected automatically.
61
+
62
+ ---
63
+
64
+ ## Quickstart
65
+
66
+ ```python
67
+ from lorien import LorienMemory
68
+
69
+ mem = LorienMemory(enable_vectors=True)
70
+
71
+ # Add a conversation
72
+ mem.add([
73
+ {"role": "user", "content": "I have a severe shellfish allergy. Oysters send me to the ER."},
74
+ {"role": "assistant", "content": "Noted — I'll never recommend shellfish."},
75
+ ], user_id="alice")
76
+
77
+ # 3 months later — new conversation
78
+ mem.add([
79
+ {"role": "user", "content": "Where should I eat tonight?"},
80
+ {"role": "assistant", "content": "The new oyster bar on Main St is great!"},
81
+ ], user_id="alice")
82
+
83
+ # Semantic search — finds allergy even without exact keywords
84
+ results = mem.search("seafood restrictions", user_id="alice")
85
+ # → [{"memory": "User has severe shellfish allergy...", "score": 0.82}]
86
+
87
+ # Auto-detected contradiction
88
+ contradictions = mem.get_contradictions()
89
+ # → [{"fact_a": "shellfish allergy...", "fact_b": "oyster bar recommendation..."}]
90
+
91
+ # Hard rules with priority
92
+ rules = mem.get_entity_rules("alice")
93
+ # → [{"text": "Never recommend shellfish to alice", "priority": 100}]
94
+ ```
95
+
96
+ ---
97
+
98
+ ## Schema
99
+
100
+ lorien uses [KuzuDB](https://kuzudb.com) — an embedded graph database (like SQLite, but for graphs).
101
+
102
+ ```
103
+ Entity ─── HAS_RULE ───► Rule
104
+
105
+ ABOUT
106
+
107
+
108
+ Fact ─── CAUSED ──► Fact
109
+
110
+ CONTRADICTS
111
+
112
+
113
+ Fact
114
+ ```
115
+
116
+ **3 node types:**
117
+ - **Entity** — people, organizations, topics (`canonical_key = "type:name"`)
118
+ - **Fact** — statements about entities (subject → predicate → object)
119
+ - **Rule** — constraints with priority 0–100 (100 = absolute prohibition)
120
+
121
+ **5 edge types:** `ABOUT`, `HAS_RULE`, `RELATED_TO`, `CAUSED`, `CONTRADICTS`
122
+
123
+ ---
124
+
125
+ ## CLI
126
+
127
+ ```bash
128
+ # Initialize
129
+ lorien init
130
+
131
+ # Check status
132
+ lorien status
133
+
134
+ # Ingest a file (MEMORY.md, notes, etc.)
135
+ lorien ingest MEMORY.md
136
+ lorien ingest MEMORY.md --model haiku # LLM extraction via OpenClaw
137
+
138
+ # Query the graph
139
+ lorien query "MATCH (e:Entity) RETURN e.name LIMIT 10"
140
+
141
+ # Show entity details
142
+ lorien show "alice"
143
+
144
+ # List contradictions
145
+ lorien contradictions
146
+
147
+ # Conversation memory for a user
148
+ lorien memory alice
149
+
150
+ # Web visualization (vis.js, no extra deps)
151
+ lorien serve
152
+ ```
153
+
154
+ ---
155
+
156
+ ## Contradiction Detection
157
+
158
+ After every fact is ingested, lorien automatically checks for semantic contradictions:
159
+
160
+ 1. **Vector similarity** — find facts with similar meaning (threshold 0.55)
161
+ 2. **Heuristic check** — negation pair patterns (허용↔금지, always↔never, must↔must not, ...)
162
+ 3. **LLM confirmation** *(optional)* — yes/no question to any OpenAI-compatible model
163
+ 4. **CONTRADICTS edge** — auto-created in the graph for later querying
164
+
165
+ ```python
166
+ detector = ContradictionDetector(
167
+ store=store,
168
+ vector_index=vi,
169
+ llm_model="gpt-4o-mini",
170
+ api_key="sk-...",
171
+ similarity_threshold=0.55,
172
+ )
173
+ n = detector.check_and_record(new_fact_id, new_fact_text)
174
+ ```
175
+
176
+ ---
177
+
178
+ ## OpenClaw Integration
179
+
180
+ lorien auto-detects the [OpenClaw](https://github.com/openclaw/openclaw) gateway when available:
181
+
182
+ ```bash
183
+ lorien ingest MEMORY.md --model haiku # routes through OpenClaw → Anthropic
184
+ lorien ingest notes.md --model flash # routes through OpenClaw → Gemini
185
+ ```
186
+
187
+ No API key needed when OpenClaw gateway is running locally.
188
+
189
+ ---
190
+
191
+ ## Installation
192
+
193
+ ```bash
194
+ # Core only (graph + CLI, no LLM, no vectors)
195
+ pip install lorien-memory
196
+
197
+ # With semantic search
198
+ pip install "lorien-memory[vectors]"
199
+
200
+ # With OpenAI-compatible LLM extraction
201
+ pip install "lorien-memory[llm]"
202
+
203
+ # Everything
204
+ pip install "lorien-memory[all]"
205
+ ```
206
+
207
+ **Requirements:** Python 3.12+, no server, no Docker.
208
+ DB stored at `~/.lorien/db`. Vectors at `~/.lorien/vectors.db`.
209
+
210
+ ---
211
+
212
+ ## Roadmap
213
+
214
+ - [x] v0.1 — Core graph schema (Entity, Fact, Rule + 5 edge types)
215
+ - [x] v0.1 — LLM ingest via OpenClaw gateway
216
+ - [x] v0.1 — Mem0-compatible `LorienMemory` API
217
+ - [x] v0.2 — Vector semantic search (sentence-transformers, multilingual)
218
+ - [x] v0.2 — Automatic contradiction detection
219
+ - [ ] v0.2 — PyPI release (`pip install lorien-memory`)
220
+ - [ ] v1.0 — Web graph visualization
221
+ - [ ] v1.0 — LangChain adapter
222
+
223
+ ---
224
+
225
+ ## vs Mem0
226
+
227
+ Mem0 answers: *"What did the user say?"*
228
+ lorien answers: *"What should I believe, why, and does it contradict anything?"*
229
+
230
+ Use both. They're complementary, not competitors.
231
+
232
+ ---
233
+
234
+ MIT License · [GitHub](https://github.com/paperbags1103-hash/lorien)
@@ -0,0 +1,199 @@
1
+ # 🌳 lorien
2
+
3
+ **Local-first personal knowledge graph for AI agents.**
4
+ What to believe, why, and what conflicts — structured memory that Mem0 can't do.
5
+
6
+ ```bash
7
+ pip install lorien-memory # core (KuzuDB + CLI)
8
+ pip install "lorien-memory[vectors]" # + semantic search
9
+ ```
10
+
11
+ ---
12
+
13
+ ## Why lorien?
14
+
15
+ | Feature | Mem0 | lorien |
16
+ |---------|------|--------|
17
+ | Conversation memory | ✅ | ✅ |
18
+ | Semantic vector search | ✅ | ✅ |
19
+ | Local (no server) | ❌ | ✅ |
20
+ | Cost | $249/mo | **$0** |
21
+ | Priority rule system | ❌ | ✅ |
22
+ | Causal reasoning (CAUSED) | ❌ | ✅ |
23
+ | **Auto contradiction detection** | ❌ | ✅ |
24
+
25
+ lorien stores *structured knowledge* — not just flat strings. Every fact has a source, every rule has a priority, and contradictions are detected automatically.
26
+
27
+ ---
28
+
29
+ ## Quickstart
30
+
31
+ ```python
32
+ from lorien import LorienMemory
33
+
34
+ mem = LorienMemory(enable_vectors=True)
35
+
36
+ # Add a conversation
37
+ mem.add([
38
+ {"role": "user", "content": "I have a severe shellfish allergy. Oysters send me to the ER."},
39
+ {"role": "assistant", "content": "Noted — I'll never recommend shellfish."},
40
+ ], user_id="alice")
41
+
42
+ # 3 months later — new conversation
43
+ mem.add([
44
+ {"role": "user", "content": "Where should I eat tonight?"},
45
+ {"role": "assistant", "content": "The new oyster bar on Main St is great!"},
46
+ ], user_id="alice")
47
+
48
+ # Semantic search — finds allergy even without exact keywords
49
+ results = mem.search("seafood restrictions", user_id="alice")
50
+ # → [{"memory": "User has severe shellfish allergy...", "score": 0.82}]
51
+
52
+ # Auto-detected contradiction
53
+ contradictions = mem.get_contradictions()
54
+ # → [{"fact_a": "shellfish allergy...", "fact_b": "oyster bar recommendation..."}]
55
+
56
+ # Hard rules with priority
57
+ rules = mem.get_entity_rules("alice")
58
+ # → [{"text": "Never recommend shellfish to alice", "priority": 100}]
59
+ ```
60
+
61
+ ---
62
+
63
+ ## Schema
64
+
65
+ lorien uses [KuzuDB](https://kuzudb.com) — an embedded graph database (like SQLite, but for graphs).
66
+
67
+ ```
68
+ Entity ─── HAS_RULE ───► Rule
69
+
70
+ ABOUT
71
+
72
+
73
+ Fact ─── CAUSED ──► Fact
74
+
75
+ CONTRADICTS
76
+
77
+
78
+ Fact
79
+ ```
80
+
81
+ **3 node types:**
82
+ - **Entity** — people, organizations, topics (`canonical_key = "type:name"`)
83
+ - **Fact** — statements about entities (subject → predicate → object)
84
+ - **Rule** — constraints with priority 0–100 (100 = absolute prohibition)
85
+
86
+ **5 edge types:** `ABOUT`, `HAS_RULE`, `RELATED_TO`, `CAUSED`, `CONTRADICTS`
87
+
88
+ ---
89
+
90
+ ## CLI
91
+
92
+ ```bash
93
+ # Initialize
94
+ lorien init
95
+
96
+ # Check status
97
+ lorien status
98
+
99
+ # Ingest a file (MEMORY.md, notes, etc.)
100
+ lorien ingest MEMORY.md
101
+ lorien ingest MEMORY.md --model haiku # LLM extraction via OpenClaw
102
+
103
+ # Query the graph
104
+ lorien query "MATCH (e:Entity) RETURN e.name LIMIT 10"
105
+
106
+ # Show entity details
107
+ lorien show "alice"
108
+
109
+ # List contradictions
110
+ lorien contradictions
111
+
112
+ # Conversation memory for a user
113
+ lorien memory alice
114
+
115
+ # Web visualization (vis.js, no extra deps)
116
+ lorien serve
117
+ ```
118
+
119
+ ---
120
+
121
+ ## Contradiction Detection
122
+
123
+ After every fact is ingested, lorien automatically checks for semantic contradictions:
124
+
125
+ 1. **Vector similarity** — find facts with similar meaning (threshold 0.55)
126
+ 2. **Heuristic check** — negation pair patterns (허용↔금지, always↔never, must↔must not, ...)
127
+ 3. **LLM confirmation** *(optional)* — yes/no question to any OpenAI-compatible model
128
+ 4. **CONTRADICTS edge** — auto-created in the graph for later querying
129
+
130
+ ```python
131
+ detector = ContradictionDetector(
132
+ store=store,
133
+ vector_index=vi,
134
+ llm_model="gpt-4o-mini",
135
+ api_key="sk-...",
136
+ similarity_threshold=0.55,
137
+ )
138
+ n = detector.check_and_record(new_fact_id, new_fact_text)
139
+ ```
140
+
141
+ ---
142
+
143
+ ## OpenClaw Integration
144
+
145
+ lorien auto-detects the [OpenClaw](https://github.com/openclaw/openclaw) gateway when available:
146
+
147
+ ```bash
148
+ lorien ingest MEMORY.md --model haiku # routes through OpenClaw → Anthropic
149
+ lorien ingest notes.md --model flash # routes through OpenClaw → Gemini
150
+ ```
151
+
152
+ No API key needed when OpenClaw gateway is running locally.
153
+
154
+ ---
155
+
156
+ ## Installation
157
+
158
+ ```bash
159
+ # Core only (graph + CLI, no LLM, no vectors)
160
+ pip install lorien-memory
161
+
162
+ # With semantic search
163
+ pip install "lorien-memory[vectors]"
164
+
165
+ # With OpenAI-compatible LLM extraction
166
+ pip install "lorien-memory[llm]"
167
+
168
+ # Everything
169
+ pip install "lorien-memory[all]"
170
+ ```
171
+
172
+ **Requirements:** Python 3.12+, no server, no Docker.
173
+ DB stored at `~/.lorien/db`. Vectors at `~/.lorien/vectors.db`.
174
+
175
+ ---
176
+
177
+ ## Roadmap
178
+
179
+ - [x] v0.1 — Core graph schema (Entity, Fact, Rule + 5 edge types)
180
+ - [x] v0.1 — LLM ingest via OpenClaw gateway
181
+ - [x] v0.1 — Mem0-compatible `LorienMemory` API
182
+ - [x] v0.2 — Vector semantic search (sentence-transformers, multilingual)
183
+ - [x] v0.2 — Automatic contradiction detection
184
+ - [ ] v0.2 — PyPI release (`pip install lorien-memory`)
185
+ - [ ] v1.0 — Web graph visualization
186
+ - [ ] v1.0 — LangChain adapter
187
+
188
+ ---
189
+
190
+ ## vs Mem0
191
+
192
+ Mem0 answers: *"What did the user say?"*
193
+ lorien answers: *"What should I believe, why, and does it contradict anything?"*
194
+
195
+ Use both. They're complementary, not competitors.
196
+
197
+ ---
198
+
199
+ MIT License · [GitHub](https://github.com/paperbags1103-hash/lorien)
@@ -0,0 +1,50 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "lorien-memory"
7
+ version = "0.2.0"
8
+ description = "Local-first personal knowledge graph for AI agents — ontology, causal chains, contradiction detection"
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ requires-python = ">=3.12"
12
+ authors = [{ name = "paperbags1103-hash" }]
13
+ keywords = [
14
+ "ai", "agents", "memory", "knowledge-graph", "ontology",
15
+ "kuzu", "llm", "contradiction-detection", "local-first"
16
+ ]
17
+ classifiers = [
18
+ "Development Status :: 4 - Beta",
19
+ "Intended Audience :: Developers",
20
+ "License :: OSI Approved :: MIT License",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
24
+ "Topic :: Database",
25
+ ]
26
+
27
+ dependencies = [
28
+ "kuzu>=0.8.0",
29
+ "click>=8.0",
30
+ ]
31
+
32
+ [project.optional-dependencies]
33
+ vectors = ["sentence-transformers>=2.7.0", "numpy>=1.24"]
34
+ llm = ["openai>=1.0"]
35
+ all = ["sentence-transformers>=2.7.0", "numpy>=1.24", "openai>=1.0"]
36
+ dev = ["pytest>=8.0", "hatchling"]
37
+
38
+ [project.urls]
39
+ Homepage = "https://github.com/paperbags1103-hash/lorien"
40
+ Repository = "https://github.com/paperbags1103-hash/lorien"
41
+ Issues = "https://github.com/paperbags1103-hash/lorien/issues"
42
+
43
+ [project.scripts]
44
+ lorien = "lorien.cli:main"
45
+
46
+ [tool.hatch.build.targets.wheel]
47
+ packages = ["src/lorien"]
48
+
49
+ [tool.hatch.build.targets.sdist]
50
+ include = ["src/", "tests/", "README.md", "LICENSE"]
@@ -0,0 +1,17 @@
1
+ from .contradiction import ContradictionDetector
2
+ from .ingest import LorienIngester
3
+ from .memory import LorienMemory
4
+ from .models import Entity, Fact, Rule
5
+ from .query import KnowledgeGraph
6
+ from .schema import GraphStore
7
+
8
+ __all__ = [
9
+ "ContradictionDetector",
10
+ "Entity",
11
+ "Fact",
12
+ "Rule",
13
+ "GraphStore",
14
+ "KnowledgeGraph",
15
+ "LorienIngester",
16
+ "LorienMemory",
17
+ ]