Skip to main content

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

English | ไธญๆ–‡

Python 3.9+ PyPI version License: MIT GitHub release


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

Screenshots

Knowledge Graph:

Knowledge Graph

Statistics Report:

Statistics Report

Memory Browser:

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


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

MIT License


Contact


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

memorycoreclaw-2.2.0.tar.gz (55.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

memorycoreclaw-2.2.0-py3-none-any.whl (60.1 kB view details)

Uploaded Python 3

File details

Details for the file memorycoreclaw-2.2.0.tar.gz.

File metadata

  • Download URL: memorycoreclaw-2.2.0.tar.gz
  • Upload date:
  • Size: 55.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for memorycoreclaw-2.2.0.tar.gz
Algorithm Hash digest
SHA256 b54941855d19371615b49383c42543a9e4242081b2b392e1a7f705a9e26003bd
MD5 588301f9fb85fb26b179c52c2fdbdc96
BLAKE2b-256 0a09dc6095ca06a6de1962a7a8aa425bdd39306689d082516df8c8c24fa103cf

See more details on using hashes here.

File details

Details for the file memorycoreclaw-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: memorycoreclaw-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 60.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for memorycoreclaw-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b4d120a2ab5f6004e7b93b0e1043ceda40cd120859c74becfb6a3fcaf35a1c86
MD5 5d6e1e09712466207b982a25c7597bf0
BLAKE2b-256 6a6aa042c4ebeaa82fc8dc15447417fe14789127f7040f4790ce1737ea8775c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page