A human-like memory engine for AI applications with safety enhancements
Project description
MemoryCoreClaw
A human-brain-inspired long-term memory engine for AI Agents
Overview
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".
Why MemoryCoreClaw?
Traditional AI Agents have limited conversation context and cannot remember user preferences or historical interactions over the long term. MemoryCoreClaw solves this problem:
| Traditional Approach | MemoryCoreClaw |
|---|---|
| Limited context window | Permanent memory storage |
| Cannot remember user preferences | Remembers and associates user information |
| Every conversation starts from zero | Automatically recalls relevant memories |
| No knowledge accumulation | Knowledge graph continues to grow |
Features
๐ง Layered Memory
- Core Layer (importance โฅ 0.9): Permanent retention, injected into context
- Important Layer (0.7 โค importance < 0.9): Long-term retention
- Normal Layer (0.5 โค importance < 0.7): Periodic consolidation
- Minor Layer (importance < 0.5): May decay
๐ Forgetting Curve
Based on the Ebbinghaus forgetting curve model:
- Memory strength decays over time
- Access strengthens memory
- Low-strength memories can be cleaned up
๐ฏ Contextual Memory
- Bind memories by people, location, emotion, activity
- Context-triggered memory recall
- Support for "What did we discuss at the coffee shop last time?"
๐ผ Working Memory
- Capacity limit (7ยฑ2 model)
- Priority-based eviction strategy
- TTL expiration mechanism
๐ Relation Learning
- 28 standard relation types
- Automatic relation inference
- Knowledge graph visualization
๐ค Export
- JSON format export
- Markdown format export
- Knowledge graph HTML visualization
๐ Visualization (New in v2.0.0)
- Knowledge Graph - Interactive D3.js force-directed graph with drag, zoom, and click-to-view details
- Statistics Report - Memory count, categories, relation types visualization
- Memory Browser - Searchable facts/lessons/relations list
๐ Plugin System (New in v2.4.0)
- StoragePlugin - Custom storage backends (e.g., PostgreSQL, MongoDB)
- RetrievalPlugin - Custom retrieval strategies (e.g., BM25, Hybrid)
- CognitivePlugin - Custom cognitive models (e.g., emotion analysis)
- CompressionPlugin - Custom memory compression algorithms
๐ฏ Reranker Service (New in v2.4.0)
- Semantic Reranking - Re-rank search results for better relevance
- Multi-provider Support - GiteeAI Qwen3-Reranker, custom models
- Easy Integration -
search_with_rerank()method
๐ก๏ธ Safe Operations (New in v2.4.0)
- SafeMemory - Safe wrapper with operation validation
- SafeDatabaseManager - SQL injection prevention
- MemoryHealthChecker - Database health monitoring
Screenshots
Knowledge Graph:
Statistics Report:
Memory Browser:
# Generate visualizations
python -m memorycoreclaw.utils.visualization
# Or specify custom paths via environment variables
MEMORY_DB_PATH=/path/to/memory.db MEMORY_OUTPUT_DIR=./output python -m memorycoreclaw.utils.visualization
Quick Start
Installation
pip install memorycoreclaw
Basic Usage
from memorycoreclaw import Memory
# Initialize
mem = Memory()
# Remember facts
mem.remember("Alice works at TechCorp", importance=0.8)
mem.remember("Alice is skilled in Python", importance=0.7, category="technical")
# Recall memories
results = mem.recall("Alice")
for r in results:
print(f"- {r['content']} (importance: {r['importance']})")
# Learn lessons
mem.learn(
action="Deployed without testing",
context="Production release",
outcome="negative",
insight="Always test before deployment",
importance=0.9
)
# Create relations
mem.relate("Alice", "works_at", "TechCorp")
mem.relate("Alice", "knows", "Bob")
# Query relations
relations = mem.get_relations("Alice")
for rel in relations:
print(f"{rel['from_entity']} --[{rel['relation_type']}]--> {rel['to_entity']}")
# Working memory
mem.hold("current_task", "Writing documentation", priority=0.9)
task = mem.retrieve("current_task")
print(f"Current task: {task}")
Project Structure
MemoryCoreClaw/
โโโ memorycoreclaw/ # Core code
โ โโโ core/ # Core engine
โ โ โโโ engine.py # Memory engine
โ โ โโโ memory.py # Unified interface
โ โโโ cognitive/ # Cognitive modules
โ โ โโโ forgetting.py # Forgetting curve
โ โ โโโ contextual.py # Contextual memory
โ โ โโโ working_memory.py # Working memory
โ โโโ retrieval/ # Retrieval modules
โ โ โโโ semantic.py # Semantic search
โ โ โโโ ontology.py # Ontology
โ โโโ storage/ # Storage modules
โ โ โโโ database.py # Database
โ โ โโโ multimodal.py # Multimodal
โ โโโ utils/ # Utility modules
โ โโโ export.py # Export
โ โโโ visualization.py # Visualization
โโโ docs/ # Documentation
โ โโโ GETTING_STARTED.md # Getting started
โ โโโ API.md # API reference
โ โโโ ARCHITECTURE.md # Architecture
โ โโโ DEPLOYMENT.md # Deployment guide
โโโ examples/ # Example code
โโโ tests/ # Test cases
โโโ config/ # Configuration files
Documentation
- Getting Started - Quick start guide
- API Reference - Complete API documentation
- Architecture - System architecture
- Deployment - Installation and deployment guide
Configuration
Default configuration file config/default.yaml:
# Database configuration
database:
path: "~/.memorycoreclaw/memory.db"
encrypt: false
# Memory layers
layers:
core:
min_importance: 0.9
retention: permanent
important:
min_importance: 0.7
retention: long_term
normal:
min_importance: 0.5
retention: standard
minor:
min_importance: 0.0
retention: may_decay
# Forgetting curve
forgetting:
enabled: true
min_strength: 0.1
access_bonus: 1.1
# Working memory
working_memory:
capacity: 9
eviction_policy: lowest_priority
Integration Examples
LangChain Integration
from langchain.memory import BaseMemory
from memorycoreclaw import Memory
class MemoryCoreClawMemory(BaseMemory):
"""LangChain memory adapter"""
def __init__(self, db_path=None):
self.mem = Memory(db_path=db_path)
@property
def memory_variables(self):
return ["memory_context"]
def load_memory_variables(self, inputs):
query = inputs.get("input", "")
memories = self.mem.recall(query, limit=5)
context = "\n".join([m["content"] for m in memories])
return {"memory_context": context}
def save_context(self, inputs, outputs):
user_input = inputs.get("input", "")
ai_output = outputs.get("output", "")
self.mem.remember(f"User: {user_input}", importance=0.5)
self.mem.remember(f"AI: {ai_output}", importance=0.5)
def clear(self):
pass
# Usage
from langchain.chat_models import ChatOpenAI
from langchain.chains import ConversationChain
memory = MemoryCoreClawMemory()
llm = ChatOpenAI()
chain = ConversationChain(llm=llm, memory=memory)
RAG Enhancement
from memorycoreclaw import Memory
mem = Memory()
def enhanced_rag_query(query):
# Recall relevant memories before RAG query
memories = mem.recall(query, limit=3)
context = "\n".join([m["content"] for m in memories])
# Enhanced query
enriched_query = f"""
Context memories:
{context}
User question: {query}
"""
return enriched_query
# Remember new information after query
mem.remember(f"User asked about: {query}", importance=0.6)
Performance
| Metric | Value |
|---|---|
| Memory storage | SQLite, supports millions of records |
| Query latency | < 10ms (keyword search) |
| Memory usage | < 50MB (100k memories) |
| Concurrency | Multi-process read safe |
Development
Setup Environment
# Clone repository
git clone https://github.com/lcq225/MemoryCoreClaw.git
cd MemoryCoreClaw
# Create virtual environment
python -m venv venv
source venv/bin/activate # Linux/Mac
# or
.\venv\Scripts\activate # Windows
# Install development dependencies
pip install -e ".[dev]"
# Run tests
python tests/standalone_test.py
Run Examples
# Basic example
python examples/basic_usage.py
# Knowledge graph example
python examples/knowledge_graph.py
Contributing
Contributions are welcome! Please check Contributing Guide.
License
Contact
- GitHub: https://github.com/lcq225/MemoryCoreClaw
- Issues: https://github.com/lcq225/MemoryCoreClaw/issues
MemoryCoreClaw - Give AI Agents the power of memory ๐ง
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file memorycoreclaw-2.5.0.tar.gz.
File metadata
- Download URL: memorycoreclaw-2.5.0.tar.gz
- Upload date:
- Size: 100.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e12189a11ac44e1b600cc3030045e2e36ee64a81139dd64e0b14e50813895cb
|
|
| MD5 |
34c07db6793ac46ac56966b27000a73f
|
|
| BLAKE2b-256 |
4a5f76574ab1ecf1107e05eb9aa9f2fac01d38e4ad06cace3d096f87979ed696
|
File details
Details for the file memorycoreclaw-2.5.0-py3-none-any.whl.
File metadata
- Download URL: memorycoreclaw-2.5.0-py3-none-any.whl
- Upload date:
- Size: 116.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
054a8178feb1c3fcd00225ff93f29a47b4cd8361b31ac2712566646cf98f4b03
|
|
| MD5 |
1b9483644f5bbf5702e7e7c4776bc478
|
|
| BLAKE2b-256 |
b6d084422f195a713a18623d991f87152ee14d95ecee485dd98bdfdc0ecbeb1b
|