Update README for v4.1 with decay feature and benchmarks
Browse files
README.md
CHANGED
|
@@ -1,228 +1,76 @@
|
|
| 1 |
-
|
| 2 |
-
license: mit
|
| 3 |
-
library_name: mnemo
|
| 4 |
-
tags:
|
| 5 |
-
- mnemo
|
| 6 |
-
- memory
|
| 7 |
-
- ai-memory
|
| 8 |
-
- llm-memory
|
| 9 |
-
- semantic-memory
|
| 10 |
-
- rag
|
| 11 |
-
- retrieval
|
| 12 |
-
- langchain
|
| 13 |
-
- llamaindex
|
| 14 |
-
- mcp
|
| 15 |
-
- agent-memory
|
| 16 |
-
- chatbot-memory
|
| 17 |
-
- mem0
|
| 18 |
-
- vector-search
|
| 19 |
-
- knowledge-graph
|
| 20 |
-
- smart-injection
|
| 21 |
-
- context-check
|
| 22 |
-
pipeline_tag: feature-extraction
|
| 23 |
-
---
|
| 24 |
-
|
| 25 |
-
# 🧠 Mnemo - AI Memory System
|
| 26 |
-
|
| 27 |
-
**Open-source memory for LLMs, chatbots, and AI agents**
|
| 28 |
-
|
| 29 |
-
> 21x faster than mem0 • Smart memory injection • Real embeddings • No API keys
|
| 30 |
-
|
| 31 |
-
## ✨ What's New in v2.0
|
| 32 |
-
|
| 33 |
-
- **🎯 Smart Memory Injection** - Context-check algorithm with 90% accuracy decides WHEN to inject memory
|
| 34 |
-
- **🧬 Real Embeddings** - sentence-transformers support (with hash fallback)
|
| 35 |
-
- **📊 Benchmark Tested** - Validated on medical AI bias detection tasks
|
| 36 |
-
|
| 37 |
-
## 📦 Install
|
| 38 |
-
|
| 39 |
-
```bash
|
| 40 |
-
pip install mnemo-memory
|
| 41 |
-
```
|
| 42 |
-
|
| 43 |
-
Or with all features:
|
| 44 |
-
```bash
|
| 45 |
-
pip install mnemo-memory[all] # Includes sentence-transformers, faiss-cpu
|
| 46 |
-
```
|
| 47 |
-
|
| 48 |
-
## 🚀 Quick Start
|
| 49 |
-
|
| 50 |
-
```python
|
| 51 |
-
from mnemo import Mnemo
|
| 52 |
-
|
| 53 |
-
memory = Mnemo()
|
| 54 |
-
memory.add("User prefers Python and dark mode")
|
| 55 |
-
memory.add("Project deadline is March 15th")
|
| 56 |
|
| 57 |
-
|
| 58 |
-
results = memory.search("user preferences")
|
| 59 |
-
print(results[0].content) # "User prefers Python and dark mode"
|
| 60 |
-
```
|
| 61 |
-
|
| 62 |
-
## 🎯 Smart Memory Injection (NEW!)
|
| 63 |
|
| 64 |
-
|
| 65 |
|
| 66 |
```python
|
|
|
|
| 67 |
from mnemo import Mnemo
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
# Check if query needs memory
|
| 74 |
-
query1 = "What is machine learning?"
|
| 75 |
-
query2 = "Based on your previous analysis, explain the patterns"
|
| 76 |
-
|
| 77 |
-
m.should_inject(query1) # False - standalone question
|
| 78 |
-
m.should_inject(query2) # True - references prior context
|
| 79 |
-
|
| 80 |
-
# Get formatted context for injection
|
| 81 |
-
if m.should_inject(query2):
|
| 82 |
-
context = m.get_context("previous analysis")
|
| 83 |
-
prompt = f"{context}\n\nQuestion: {query2}"
|
| 84 |
```
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
| Query Type | Example | Action |
|
| 89 |
-
|------------|---------|--------|
|
| 90 |
-
| References prior | "Based on your previous analysis..." | ✓ Inject |
|
| 91 |
-
| Comparison | "Compare this to earlier findings" | ✓ Inject |
|
| 92 |
-
| Synthesis | "Synthesize all the patterns" | ✓ Inject |
|
| 93 |
-
| Standalone | "What is Python?" | ✗ Skip |
|
| 94 |
-
| New topic | "This is a NEW problem..." | ✗ Skip |
|
| 95 |
-
|
| 96 |
-
## 🔬 Benchmark Results
|
| 97 |
-
|
| 98 |
-
Tested on NRA-19 Medical AI Bias Detection benchmark:
|
| 99 |
|
| 100 |
-
###
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
| Never inject | 41/100 | 30% |
|
| 107 |
-
| Similarity only | 37/100 | 50% |
|
| 108 |
|
| 109 |
-
|
| 110 |
|
| 111 |
-
|
|
| 112 |
-
|
| 113 |
-
|
|
| 114 |
-
|
|
| 115 |
-
|
|
| 116 |
|
| 117 |
-
|
| 118 |
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
```json
|
| 124 |
-
{
|
| 125 |
-
"mcpServers": {
|
| 126 |
-
"mnemo": {
|
| 127 |
-
"command": "uvx",
|
| 128 |
-
"args": ["mnemo-memory"]
|
| 129 |
-
}
|
| 130 |
-
}
|
| 131 |
-
}
|
| 132 |
-
```
|
| 133 |
|
| 134 |
-
|
|
|
|
| 135 |
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
| `add_memory` | Store a new memory |
|
| 139 |
-
| `search_memory` | Search stored memories |
|
| 140 |
-
| `should_inject` | Check if memory should be used |
|
| 141 |
-
| `get_context` | Get formatted context for injection |
|
| 142 |
-
| `get_stats` | Get system statistics |
|
| 143 |
|
| 144 |
-
|
|
|
|
| 145 |
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
| Search latency | 5.73ms | **0.27ms** |
|
| 149 |
-
| API keys required | Yes | **No** |
|
| 150 |
-
| Works offline | No | **Yes** |
|
| 151 |
-
| Smart injection | No | **Yes** |
|
| 152 |
-
| Embedding options | API only | **Local + API** |
|
| 153 |
|
| 154 |
-
|
|
|
|
| 155 |
|
|
|
|
|
|
|
| 156 |
```
|
| 157 |
-
┌─────────────────────────────────────────────────────────────┐
|
| 158 |
-
│ Mnemo │
|
| 159 |
-
├─────────────────────────────────────────────────────────────┤
|
| 160 |
-
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
|
| 161 |
-
│ │ Semantic │ │ BM25 │ │ Graph │ │
|
| 162 |
-
│ │ Search │ │ Search │ │ Search │ │
|
| 163 |
-
│ │ (FAISS) │ │ (Keywords) │ │ (NetworkX) │ │
|
| 164 |
-
│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │
|
| 165 |
-
│ │ │ │ │
|
| 166 |
-
│ └────────────────┴────────────────┘ │
|
| 167 |
-
│ │ │
|
| 168 |
-
│ ┌──────┴──────┐ │
|
| 169 |
-
│ │ Ranker │ ← Feedback Learning │
|
| 170 |
-
│ └──────┬──────┘ │
|
| 171 |
-
│ │ │
|
| 172 |
-
│ ┌───────────┴───────────┐ │
|
| 173 |
-
│ │ Smart Injection │ │
|
| 174 |
-
│ │ (Context-Check) │ │
|
| 175 |
-
│ └───────────────────────┘ │
|
| 176 |
-
└─────────────────────────────────────────────────────────────┘
|
| 177 |
-
```
|
| 178 |
-
|
| 179 |
-
## 📝 API Reference
|
| 180 |
|
| 181 |
-
|
| 182 |
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
semantic_weight: float = 0.5,
|
| 190 |
-
bm25_weight: float = 0.3,
|
| 191 |
-
graph_weight: float = 0.2,
|
| 192 |
-
use_real_embeddings: bool = True
|
| 193 |
-
)
|
| 194 |
-
|
| 195 |
-
def add(content: str, metadata: dict = None) -> str
|
| 196 |
-
def search(query: str, top_k: int = 5) -> List[SearchResult]
|
| 197 |
-
def should_inject(query: str, context: str = "") -> bool
|
| 198 |
-
def get_context(query: str, top_k: int = 3) -> str
|
| 199 |
-
def feedback(query: str, memory_id: str, relevance: float)
|
| 200 |
-
def get_stats() -> dict
|
| 201 |
-
def clear()
|
| 202 |
-
```
|
| 203 |
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
```python
|
| 207 |
-
@dataclass
|
| 208 |
-
class SearchResult:
|
| 209 |
-
id: str
|
| 210 |
-
content: str
|
| 211 |
-
score: float
|
| 212 |
-
strategy_scores: Dict[str, float]
|
| 213 |
-
metadata: Dict
|
| 214 |
-
```
|
| 215 |
-
|
| 216 |
-
## 🔗 Links
|
| 217 |
|
| 218 |
- [Demo Space](https://huggingface.co/spaces/AthelaPerk/mnemo)
|
| 219 |
- [MCP Server](https://huggingface.co/spaces/AthelaPerk/mnemo-mcp)
|
| 220 |
-
- [GitHub Issues](https://github.com/AthelaPerk/mnemo/issues)
|
| 221 |
-
|
| 222 |
-
## 📄 License
|
| 223 |
-
|
| 224 |
-
MIT License - Use freely in your projects!
|
| 225 |
-
|
| 226 |
-
---
|
| 227 |
|
| 228 |
-
|
|
|
|
| 1 |
+
# 🧠 Mnemo v4.1 - SLM-Inspired Memory System
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
Memory augmentation library for LLMs based on the Semantic-Loop Memory architecture.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
## Installation
|
| 6 |
|
| 7 |
```python
|
| 8 |
+
# Download mnemo.py from this repo
|
| 9 |
from mnemo import Mnemo
|
| 10 |
|
| 11 |
+
mnemo = Mnemo()
|
| 12 |
+
mnemo.add("User prefers Python for data analysis")
|
| 13 |
+
results = mnemo.search("programming language")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
```
|
| 15 |
|
| 16 |
+
## Features
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
### Core
|
| 19 |
+
- **Three-Tier Memory**: Working (50 items) → Token Loops → Semantic (persistent)
|
| 20 |
+
- **Neural Links**: 8 link types with different creation thresholds and decay rates
|
| 21 |
+
- **Memory Utility Predictor**: Decides WHEN to inject memory (90% accuracy)
|
| 22 |
+
- **Self-Tuning**: Auto-adjusts thresholds based on feedback
|
| 23 |
|
| 24 |
+
### v4.1 New
|
| 25 |
+
- **Memory Decay**: Unused memories lose 1% quality per day
|
| 26 |
+
- **Auto-Pruning**: Removes stale memories (quality < 0.15, unused > 30 days)
|
| 27 |
+
- **Link Cleanup**: Orphaned links removed when memories are pruned
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
## Benchmark Results
|
| 30 |
|
| 31 |
+
| Test | Without Memory | With Mnemo | Improvement |
|
| 32 |
+
|------|----------------|------------|-------------|
|
| 33 |
+
| Novel retrieval | 5% | 85% | +80% |
|
| 34 |
+
| Code retrieval | 60% | 88% | +28% |
|
| 35 |
+
| ROS continuous learning | 25% | 75% | +50% |
|
| 36 |
|
| 37 |
+
## API
|
| 38 |
|
| 39 |
+
```python
|
| 40 |
+
# Initialize
|
| 41 |
+
mnemo = Mnemo()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
# Add memory
|
| 44 |
+
mnemo.add(content, namespace="default", metadata={})
|
| 45 |
|
| 46 |
+
# Search
|
| 47 |
+
results = mnemo.search(query, top_k=5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
# Get context for LLM injection
|
| 50 |
+
context = mnemo.get_context(query, top_k=3)
|
| 51 |
|
| 52 |
+
# Check if injection would help
|
| 53 |
+
should_inject = mnemo.should_inject(query)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
+
# Run maintenance (decay + prune)
|
| 56 |
+
mnemo.maintenance_cycle()
|
| 57 |
|
| 58 |
+
# Get statistics
|
| 59 |
+
stats = mnemo.get_stats()
|
| 60 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
## Parameters
|
| 63 |
|
| 64 |
+
| Parameter | Default | Description |
|
| 65 |
+
|-----------|---------|-------------|
|
| 66 |
+
| similarity_threshold | 0.10 | Min score for search results |
|
| 67 |
+
| quality_threshold | 0.35 | Min quality for new memories |
|
| 68 |
+
| memory_decay_rate | 0.01 | Daily quality decay (1%) |
|
| 69 |
+
| memory_stale_days | 30 | Days before eligible for pruning |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
+
## Links
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
- [Demo Space](https://huggingface.co/spaces/AthelaPerk/mnemo)
|
| 74 |
- [MCP Server](https://huggingface.co/spaces/AthelaPerk/mnemo-mcp)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
+
MIT License
|