memcurve
<div align="center">
# š§ MemCurve
**Persistent memory for AI assistants ā with forgetting curves, decay, and graph clustering.**
[](https://python.org)
[](LICENSE)
[](https://modelcontextprotocol.io)
[](https://github.com/nathaniel-gordon/memcurve)
<br/>
*CortexGraph MCP server. Stores memories as a weighted knowledge graph, decays stale nodes via configurable half-life, clusters related memories, and surfaces the right context at the right time through activation-pattern retrieval.*
</div>
---
## š§ What Is This?
> **For non-technical readers:** Most AI assistants have no persistent memory ā every conversation starts completely blank. MemCurve gives an AI assistant long-term memory that works like human memory: important things are remembered more strongly, rarely-accessed memories fade over time, and related memories are grouped together so that recalling one makes nearby ones more accessible. It exposes this memory system to AI tools via a standard protocol (MCP), so any compatible assistant can use it.
---
## šļø CortexGraph Architecture
MemCurve implements the **CortexGraph** memory system ā a weighted knowledge graph where nodes are memory entities, edges encode semantic relationships, and node weights decay over time according to configurable half-life schedules. Retrieval uses activation spreading: querying one node activates its neighbors with diminishing strength, surfacing contextually related memories.
```
š¬ Conversation / Tool Call
ā
ā¼
š Entity Extraction & Message Analysis
Detects entities, topics, facts, and relationships
worth persisting in the memory graph
ā
ā¼
š§ CortexGraph (Weighted Knowledge Graph)
āāā Nodes: memories, facts, entities
āāā Edges: semantic relations + co-occurrence weights
āāā Node weights: decay via half-life schedule
ā
āāā ā±ļø Background Decay Process
ā Stale memory weights decay exponentially
ā GC prunes nodes below activation threshold
ā
āāā š Memory Clustering
Related nodes grouped into clusters
for efficient neighborhood retrieval
ā
ā¼
š Activation-Pattern Retrieval
Query activates seed nodes, spreads to neighbors
Returns ranked memory context for generation
```
---
## š¬ Technical Design
**Half-Life Decay** ā Memory node weights decay exponentially over time: `w(t) = wā Ć (½)^(t/Ļ)` where `Ļ` is the configurable half-life. Frequently accessed memories are "touched" (weight refreshed) on each recall, preventing useful information from decaying. The decay function is calculated by `cortexgraph.core.decay.calculate_halflife` and runs on a background scheduler.
**MCP Tool Surface** ā CortexGraph exposes memory operations as MCP tools that any compatible AI client can call:
| Tool | Purpose |
|---|---|
| `save` | Persist a new memory entity to the graph |
| `search` | Semantic search over memory nodes |
| `search_unified` | Combined graph traversal + semantic search |
| `auto_recall_tool` | Context-aware memory retrieval based on current conversation |
| `analyze_message` | Extract entities and facts worth saving from a message |
| `cluster` | Group related memories into topic clusters |
| `consolidate` | Merge redundant or contradictory memory nodes |
| `gc` | Prune decayed nodes below activation threshold |
| `promote` | Boost a memory node's weight (mark as important) |
| `touch` | Refresh a node's decay timer without modifying weight |
**Activation Spreading** ā On `search_unified`, queried seed nodes activate their graph neighbors with weight proportional to edge strength Ć query relevance. This surfaces associated memories without requiring exact semantic match ā related context emerges from graph structure.
**Security Layer** ā The server includes secret scanning on config files (`should_warn_about_secrets`) and enforces secure storage paths (`ensure_secure_storage`) before starting ā preventing accidental exposure of API keys in the memory store.
---
## š Getting Started
```bash
git clone https://github.com/nathaniel-gordon/memcurve
cd memcurve
pip install -e .
```
### Start the MCP Server
```bash
python -m cortexgraph
```
### Visualize the Memory Graph
```bash
python scripts/visualize_graph.py
```
### Convert to MCP Memory Format
```bash
python scripts/convert_to_memory_mcp.py
```
---
## š Project Structure
```
memcurve/
āāā src/cortexgraph/
ā āāā server.py # MCP server entrypoint & tool registration
ā āāā context.py # Shared db & mcp context
ā āāā config.py # Half-life and decay configuration
ā āāā background.py # Background decay scheduler
ā āāā performance.py # Performance monitoring
ā āāā activation/ # Activation spreading & entity extraction
ā ā āāā detectors.py
ā ā āāā entity_extraction.py
ā ā āāā patterns.py
ā āāā tools/ # All MCP tool implementations
ā āāā security/ # Secret scanning & secure storage enforcement
āāā scripts/
```
---
<div align="center">
*Built by [Nathaniel Gordon](https://github.com/nathaniel-gordon)*
</div>
TDQS
Scored across 17 tools
Most tools target distinct actions: analyze_for_recall vs analyze_message are differentiated by intent, and cluster_memories vs consolidate_memories separate detection from action. However, search_memory and search_unified overlap in capability, and auto_recall_process_message could be confused with the analyze_* tools since it also starts with message analysis.
The majority follow a clear verb_noun pattern like save_memory, search_memory, promote_memory, and create_relation. Deviations include the abbreviated 'gc' and the awkward compound 'auto_recall_process_message', which break the otherwise predictable pattern.
At 17 tools, the server is slightly above the ideal 3-15 range but still reasonably scoped for a memory system that handles search, recall, consolidation, promotion, graph relationships, and maintenance. Each tool serves a plausible purpose, though a few analysis/search tools could be merged.
The toolset covers the core memory lifecycle well: save, retrieve, search, reinforce, promote, consolidate, cluster, relate, and garbage collect. Minor gaps exist such as no explicit edit-memory or delete-relation tool, but the provided operations are mostly sufficient for the perceived domain.