memorycoreclaw 2.0.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 (31) hide show
  1. memorycoreclaw-2.0.0/LICENSE +21 -0
  2. memorycoreclaw-2.0.0/PKG-INFO +398 -0
  3. memorycoreclaw-2.0.0/README.md +359 -0
  4. memorycoreclaw-2.0.0/memorycoreclaw/__init__.py +21 -0
  5. memorycoreclaw-2.0.0/memorycoreclaw/cognitive/__init__.py +8 -0
  6. memorycoreclaw-2.0.0/memorycoreclaw/cognitive/contextual.py +100 -0
  7. memorycoreclaw-2.0.0/memorycoreclaw/cognitive/forgetting.py +162 -0
  8. memorycoreclaw-2.0.0/memorycoreclaw/cognitive/heuristic.py +217 -0
  9. memorycoreclaw-2.0.0/memorycoreclaw/cognitive/working.py +179 -0
  10. memorycoreclaw-2.0.0/memorycoreclaw/cognitive/working_memory.py +271 -0
  11. memorycoreclaw-2.0.0/memorycoreclaw/core/__init__.py +15 -0
  12. memorycoreclaw-2.0.0/memorycoreclaw/core/engine.py +944 -0
  13. memorycoreclaw-2.0.0/memorycoreclaw/core/memory.py +373 -0
  14. memorycoreclaw-2.0.0/memorycoreclaw/py.typed +2 -0
  15. memorycoreclaw-2.0.0/memorycoreclaw/retrieval/__init__.py +6 -0
  16. memorycoreclaw-2.0.0/memorycoreclaw/retrieval/ontology.py +214 -0
  17. memorycoreclaw-2.0.0/memorycoreclaw/retrieval/semantic.py +192 -0
  18. memorycoreclaw-2.0.0/memorycoreclaw/storage/__init__.py +6 -0
  19. memorycoreclaw-2.0.0/memorycoreclaw/storage/database.py +79 -0
  20. memorycoreclaw-2.0.0/memorycoreclaw/storage/multimodal.py +79 -0
  21. memorycoreclaw-2.0.0/memorycoreclaw/utils/__init__.py +6 -0
  22. memorycoreclaw-2.0.0/memorycoreclaw/utils/export.py +114 -0
  23. memorycoreclaw-2.0.0/memorycoreclaw/utils/visualization.py +1016 -0
  24. memorycoreclaw-2.0.0/memorycoreclaw.egg-info/PKG-INFO +398 -0
  25. memorycoreclaw-2.0.0/memorycoreclaw.egg-info/SOURCES.txt +29 -0
  26. memorycoreclaw-2.0.0/memorycoreclaw.egg-info/dependency_links.txt +1 -0
  27. memorycoreclaw-2.0.0/memorycoreclaw.egg-info/requires.txt +16 -0
  28. memorycoreclaw-2.0.0/memorycoreclaw.egg-info/top_level.txt +1 -0
  29. memorycoreclaw-2.0.0/pyproject.toml +87 -0
  30. memorycoreclaw-2.0.0/setup.cfg +4 -0
  31. memorycoreclaw-2.0.0/tests/test_basic.py +233 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 MemoryCoreClaw Team
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,398 @@
1
+ Metadata-Version: 2.4
2
+ Name: memorycoreclaw
3
+ Version: 2.0.0
4
+ Summary: A human-like memory engine for AI applications
5
+ Author-email: MemoryCoreClaw Team <memorycoreclaw@example.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/lcq225/MemoryCoreClaw
8
+ Project-URL: Documentation, https://github.com/lcq225/MemoryCoreClaw#readme
9
+ Project-URL: Repository, https://github.com/lcq225/MemoryCoreClaw.git
10
+ Project-URL: Issues, https://github.com/lcq225/MemoryCoreClaw/issues
11
+ Keywords: memory,ai,knowledge-graph,semantic-search,cognitive,llm
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.8
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: cryptography>=3.4
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest>=7.0; extra == "dev"
28
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
29
+ Requires-Dist: black>=23.0; extra == "dev"
30
+ Requires-Dist: isort>=5.0; extra == "dev"
31
+ Requires-Dist: mypy>=1.0; extra == "dev"
32
+ Requires-Dist: flake8>=6.0; extra == "dev"
33
+ Provides-Extra: embeddings
34
+ Requires-Dist: sentence-transformers>=2.0; extra == "embeddings"
35
+ Provides-Extra: visualization
36
+ Requires-Dist: matplotlib>=3.0; extra == "visualization"
37
+ Requires-Dist: networkx>=3.0; extra == "visualization"
38
+ Dynamic: license-file
39
+
40
+ # MemoryCoreClaw
41
+
42
+ > A human-brain-inspired long-term memory engine for AI Agents
43
+
44
+ [English](README.md) | [中文](README_zh.md)
45
+
46
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
47
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
48
+ [![GitHub release](https://img.shields.io/github/v/release/lcq225/MemoryCoreClaw.svg)](https://github.com/lcq225/MemoryCoreClaw/releases)
49
+
50
+ ---
51
+
52
+ ## Overview
53
+
54
+ MemoryCoreClaw is a long-term memory engine that simulates human brain memory mechanisms, designed specifically for AI Agents. It implements cognitive science concepts including layered memory, forgetting curve, contextual triggers, and working memory, giving AI Agents the ability to "remember".
55
+
56
+ ### Why MemoryCoreClaw?
57
+
58
+ Traditional AI Agents have limited conversation context and cannot remember user preferences or historical interactions over the long term. MemoryCoreClaw solves this problem:
59
+
60
+ | Traditional Approach | MemoryCoreClaw |
61
+ |---------------------|----------------|
62
+ | Limited context window | Permanent memory storage |
63
+ | Cannot remember user preferences | Remembers and associates user information |
64
+ | Every conversation starts from zero | Automatically recalls relevant memories |
65
+ | No knowledge accumulation | Knowledge graph continues to grow |
66
+
67
+ ---
68
+
69
+ ## Features
70
+
71
+ ### 🧠 Layered Memory
72
+ - **Core Layer** (importance ≥ 0.9): Permanent retention, injected into context
73
+ - **Important Layer** (0.7 ≤ importance < 0.9): Long-term retention
74
+ - **Normal Layer** (0.5 ≤ importance < 0.7): Periodic consolidation
75
+ - **Minor Layer** (importance < 0.5): May decay
76
+
77
+ ### 📉 Forgetting Curve
78
+ Based on the Ebbinghaus forgetting curve model:
79
+ - Memory strength decays over time
80
+ - Access strengthens memory
81
+ - Low-strength memories can be cleaned up
82
+
83
+ ### 🎯 Contextual Memory
84
+ - Bind memories by people, location, emotion, activity
85
+ - Context-triggered memory recall
86
+ - Support for "What did we discuss at the coffee shop last time?"
87
+
88
+ ### 💼 Working Memory
89
+ - Capacity limit (7±2 model)
90
+ - Priority-based eviction strategy
91
+ - TTL expiration mechanism
92
+
93
+ ### 🔗 Relation Learning
94
+ - 28 standard relation types
95
+ - Automatic relation inference
96
+ - Knowledge graph visualization
97
+
98
+ ### 📤 Export
99
+ - JSON format export
100
+ - Markdown format export
101
+ - Knowledge graph HTML visualization
102
+
103
+ ### 📊 Visualization (New in v2.0.0)
104
+
105
+ - **Knowledge Graph** - Interactive D3.js force-directed graph with drag, zoom, and click-to-view details
106
+ - **Statistics Report** - Memory count, categories, relation types visualization
107
+ - **Memory Browser** - Searchable facts/lessons/relations list
108
+
109
+ #### Screenshots
110
+
111
+ **Knowledge Graph:**
112
+
113
+ ![Knowledge Graph](docs/images/knowledge_graph.png)
114
+
115
+ **Statistics Report:**
116
+
117
+ ![Statistics Report](docs/images/stats_report.png)
118
+
119
+ **Memory Browser:**
120
+
121
+ ![Memory Browser](docs/images/memory_browser.png)
122
+
123
+ ```bash
124
+ # Generate visualizations
125
+ python -m memorycoreclaw.utils.visualization
126
+
127
+ # Or specify custom paths via environment variables
128
+ MEMORY_DB_PATH=/path/to/memory.db MEMORY_OUTPUT_DIR=./output python -m memorycoreclaw.utils.visualization
129
+ ```
130
+
131
+ ---
132
+
133
+ ## Quick Start
134
+
135
+ ### Installation
136
+
137
+ ```bash
138
+ pip install memorycoreclaw
139
+ ```
140
+
141
+ ### Basic Usage
142
+
143
+ ```python
144
+ from memorycoreclaw import Memory
145
+
146
+ # Initialize
147
+ mem = Memory()
148
+
149
+ # Remember facts
150
+ mem.remember("Alice works at TechCorp", importance=0.8)
151
+ mem.remember("Alice is skilled in Python", importance=0.7, category="technical")
152
+
153
+ # Recall memories
154
+ results = mem.recall("Alice")
155
+ for r in results:
156
+ print(f"- {r['content']} (importance: {r['importance']})")
157
+
158
+ # Learn lessons
159
+ mem.learn(
160
+ action="Deployed without testing",
161
+ context="Production release",
162
+ outcome="negative",
163
+ insight="Always test before deployment",
164
+ importance=0.9
165
+ )
166
+
167
+ # Create relations
168
+ mem.relate("Alice", "works_at", "TechCorp")
169
+ mem.relate("Alice", "knows", "Bob")
170
+
171
+ # Query relations
172
+ relations = mem.get_relations("Alice")
173
+ for rel in relations:
174
+ print(f"{rel['from_entity']} --[{rel['relation_type']}]--> {rel['to_entity']}")
175
+
176
+ # Working memory
177
+ mem.hold("current_task", "Writing documentation", priority=0.9)
178
+ task = mem.retrieve("current_task")
179
+ print(f"Current task: {task}")
180
+ ```
181
+
182
+ ---
183
+
184
+ ## Project Structure
185
+
186
+ ```
187
+ MemoryCoreClaw/
188
+ ├── memorycoreclaw/ # Core code
189
+ │ ├── core/ # Core engine
190
+ │ │ ├── engine.py # Memory engine
191
+ │ │ └── memory.py # Unified interface
192
+ │ ├── cognitive/ # Cognitive modules
193
+ │ │ ├── forgetting.py # Forgetting curve
194
+ │ │ ├── contextual.py # Contextual memory
195
+ │ │ └── working_memory.py # Working memory
196
+ │ ├── retrieval/ # Retrieval modules
197
+ │ │ ├── semantic.py # Semantic search
198
+ │ │ └── ontology.py # Ontology
199
+ │ ├── storage/ # Storage modules
200
+ │ │ ├── database.py # Database
201
+ │ │ └── multimodal.py # Multimodal
202
+ │ └── utils/ # Utility modules
203
+ │ ├── export.py # Export
204
+ │ └── visualization.py # Visualization
205
+ ├── docs/ # Documentation
206
+ │ ├── GETTING_STARTED.md # Getting started
207
+ │ ├── API.md # API reference
208
+ │ ├── ARCHITECTURE.md # Architecture
209
+ │ └── DEPLOYMENT.md # Deployment guide
210
+ ├── examples/ # Example code
211
+ ├── tests/ # Test cases
212
+ └── config/ # Configuration files
213
+ ```
214
+
215
+ ---
216
+
217
+ ## Documentation
218
+
219
+ - [Getting Started](docs/GETTING_STARTED.md) - Quick start guide
220
+ - [API Reference](docs/API.md) - Complete API documentation
221
+ - [Architecture](docs/ARCHITECTURE.md) - System architecture
222
+ - [Deployment](docs/DEPLOYMENT.md) - Installation and deployment guide
223
+
224
+ ---
225
+
226
+ ## Configuration
227
+
228
+ Default configuration file `config/default.yaml`:
229
+
230
+ ```yaml
231
+ # Database configuration
232
+ database:
233
+ path: "~/.memorycoreclaw/memory.db"
234
+ encrypt: false
235
+
236
+ # Memory layers
237
+ layers:
238
+ core:
239
+ min_importance: 0.9
240
+ retention: permanent
241
+ important:
242
+ min_importance: 0.7
243
+ retention: long_term
244
+ normal:
245
+ min_importance: 0.5
246
+ retention: standard
247
+ minor:
248
+ min_importance: 0.0
249
+ retention: may_decay
250
+
251
+ # Forgetting curve
252
+ forgetting:
253
+ enabled: true
254
+ min_strength: 0.1
255
+ access_bonus: 1.1
256
+
257
+ # Working memory
258
+ working_memory:
259
+ capacity: 9
260
+ eviction_policy: lowest_priority
261
+ ```
262
+
263
+ ---
264
+
265
+ ## Integration Examples
266
+
267
+ ### LangChain Integration
268
+
269
+ ```python
270
+ from langchain.memory import BaseMemory
271
+ from memorycoreclaw import Memory
272
+
273
+ class MemoryCoreClawMemory(BaseMemory):
274
+ """LangChain memory adapter"""
275
+
276
+ def __init__(self, db_path=None):
277
+ self.mem = Memory(db_path=db_path)
278
+
279
+ @property
280
+ def memory_variables(self):
281
+ return ["memory_context"]
282
+
283
+ def load_memory_variables(self, inputs):
284
+ query = inputs.get("input", "")
285
+ memories = self.mem.recall(query, limit=5)
286
+ context = "\n".join([m["content"] for m in memories])
287
+ return {"memory_context": context}
288
+
289
+ def save_context(self, inputs, outputs):
290
+ user_input = inputs.get("input", "")
291
+ ai_output = outputs.get("output", "")
292
+ self.mem.remember(f"User: {user_input}", importance=0.5)
293
+ self.mem.remember(f"AI: {ai_output}", importance=0.5)
294
+
295
+ def clear(self):
296
+ pass
297
+
298
+ # Usage
299
+ from langchain.chat_models import ChatOpenAI
300
+ from langchain.chains import ConversationChain
301
+
302
+ memory = MemoryCoreClawMemory()
303
+ llm = ChatOpenAI()
304
+ chain = ConversationChain(llm=llm, memory=memory)
305
+ ```
306
+
307
+ ### RAG Enhancement
308
+
309
+ ```python
310
+ from memorycoreclaw import Memory
311
+
312
+ mem = Memory()
313
+
314
+ def enhanced_rag_query(query):
315
+ # Recall relevant memories before RAG query
316
+ memories = mem.recall(query, limit=3)
317
+ context = "\n".join([m["content"] for m in memories])
318
+
319
+ # Enhanced query
320
+ enriched_query = f"""
321
+ Context memories:
322
+ {context}
323
+
324
+ User question: {query}
325
+ """
326
+ return enriched_query
327
+
328
+ # Remember new information after query
329
+ mem.remember(f"User asked about: {query}", importance=0.6)
330
+ ```
331
+
332
+ ---
333
+
334
+ ## Performance
335
+
336
+ | Metric | Value |
337
+ |--------|-------|
338
+ | Memory storage | SQLite, supports millions of records |
339
+ | Query latency | < 10ms (keyword search) |
340
+ | Memory usage | < 50MB (100k memories) |
341
+ | Concurrency | Multi-process read safe |
342
+
343
+ ---
344
+
345
+ ## Development
346
+
347
+ ### Setup Environment
348
+
349
+ ```bash
350
+ # Clone repository
351
+ git clone https://github.com/lcq225/MemoryCoreClaw.git
352
+ cd MemoryCoreClaw
353
+
354
+ # Create virtual environment
355
+ python -m venv venv
356
+ source venv/bin/activate # Linux/Mac
357
+ # or
358
+ .\venv\Scripts\activate # Windows
359
+
360
+ # Install development dependencies
361
+ pip install -e ".[dev]"
362
+
363
+ # Run tests
364
+ python tests/standalone_test.py
365
+ ```
366
+
367
+ ### Run Examples
368
+
369
+ ```bash
370
+ # Basic example
371
+ python examples/basic_usage.py
372
+
373
+ # Knowledge graph example
374
+ python examples/knowledge_graph.py
375
+ ```
376
+
377
+ ---
378
+
379
+ ## Contributing
380
+
381
+ Contributions are welcome! Please check [Contributing Guide](CONTRIBUTING.md).
382
+
383
+ ---
384
+
385
+ ## License
386
+
387
+ [MIT License](LICENSE)
388
+
389
+ ---
390
+
391
+ ## Contact
392
+
393
+ - GitHub: [https://github.com/lcq225/MemoryCoreClaw](https://github.com/lcq225/MemoryCoreClaw)
394
+ - Issues: [https://github.com/lcq225/MemoryCoreClaw/issues](https://github.com/lcq225/MemoryCoreClaw/issues)
395
+
396
+ ---
397
+
398
+ **MemoryCoreClaw** - Give AI Agents the power of memory 🧠