yourmemory 1.0.2__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.
- yourmemory-1.0.2/LICENSE +27 -0
- yourmemory-1.0.2/PKG-INFO +306 -0
- yourmemory-1.0.2/README.md +248 -0
- yourmemory-1.0.2/memory_mcp.py +464 -0
- yourmemory-1.0.2/pyproject.toml +53 -0
- yourmemory-1.0.2/setup.cfg +4 -0
- yourmemory-1.0.2/src/__init__.py +0 -0
- yourmemory-1.0.2/src/app.py +30 -0
- yourmemory-1.0.2/src/db/connection.py +62 -0
- yourmemory-1.0.2/src/db/migrate.py +32 -0
- yourmemory-1.0.2/src/db/schema.sql +53 -0
- yourmemory-1.0.2/src/db/sqlite_schema.sql +38 -0
- yourmemory-1.0.2/src/jobs/decay_job.py +75 -0
- yourmemory-1.0.2/src/routes/__init__.py +0 -0
- yourmemory-1.0.2/src/routes/agents.py +45 -0
- yourmemory-1.0.2/src/routes/memories.py +279 -0
- yourmemory-1.0.2/src/routes/retrieve.py +17 -0
- yourmemory-1.0.2/src/services/__init__.py +0 -0
- yourmemory-1.0.2/src/services/agent_registry.py +101 -0
- yourmemory-1.0.2/src/services/api_keys.py +189 -0
- yourmemory-1.0.2/src/services/decay.py +48 -0
- yourmemory-1.0.2/src/services/embed.py +7 -0
- yourmemory-1.0.2/src/services/extract.py +38 -0
- yourmemory-1.0.2/src/services/resolve.py +180 -0
- yourmemory-1.0.2/src/services/retrieve.py +203 -0
- yourmemory-1.0.2/yourmemory.egg-info/PKG-INFO +306 -0
- yourmemory-1.0.2/yourmemory.egg-info/SOURCES.txt +29 -0
- yourmemory-1.0.2/yourmemory.egg-info/dependency_links.txt +1 -0
- yourmemory-1.0.2/yourmemory.egg-info/entry_points.txt +2 -0
- yourmemory-1.0.2/yourmemory.egg-info/requires.txt +12 -0
- yourmemory-1.0.2/yourmemory.egg-info/top_level.txt +2 -0
yourmemory-1.0.2/LICENSE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Copyright (c) 2026 Sachit Misra. All rights reserved.
|
|
2
|
+
|
|
3
|
+
This software, including all source code, algorithms, data structures, scoring
|
|
4
|
+
formulas, and associated documentation (collectively, the "Software"), is the
|
|
5
|
+
exclusive intellectual property of Sachit Misra.
|
|
6
|
+
|
|
7
|
+
Permission is granted, free of charge, to any individual to use, copy, and
|
|
8
|
+
modify the Software for personal, educational, or non-commercial research
|
|
9
|
+
purposes, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
1. ATTRIBUTION — Any use or distribution of the Software, in whole or in part,
|
|
12
|
+
must retain this copyright notice and clearly attribute Sachit Misra as the
|
|
13
|
+
original author.
|
|
14
|
+
|
|
15
|
+
2. NON-COMMERCIAL USE ONLY — The Software, or any derivative work based on it,
|
|
16
|
+
may not be used, sold, sublicensed, or incorporated into any product or
|
|
17
|
+
service for commercial purposes without the prior written consent of
|
|
18
|
+
Sachit Misra. Commercial purposes include, but are not limited to:
|
|
19
|
+
- Selling access to the Software or any service powered by it
|
|
20
|
+
- Incorporating the Software into a commercial product or SaaS offering
|
|
21
|
+
- Using the Software to generate revenue directly or indirectly
|
|
22
|
+
|
|
23
|
+
3. NO WARRANTY — The Software is provided "as is", without warranty of any
|
|
24
|
+
kind, express or implied. Sachit Misra shall not be liable for any claim,
|
|
25
|
+
damages, or other liability arising from the use of the Software.
|
|
26
|
+
|
|
27
|
+
For commercial licensing inquiries, contact: mishrasachit1@gmail.com
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: yourmemory
|
|
3
|
+
Version: 1.0.2
|
|
4
|
+
Summary: Persistent memory for Claude — Ebbinghaus forgetting curve, semantic deduplication, MCP-native
|
|
5
|
+
Author-email: Sachit Misra <mishrasachit1@gmail.com>
|
|
6
|
+
License: Copyright (c) 2026 Sachit Misra. All rights reserved.
|
|
7
|
+
|
|
8
|
+
This software, including all source code, algorithms, data structures, scoring
|
|
9
|
+
formulas, and associated documentation (collectively, the "Software"), is the
|
|
10
|
+
exclusive intellectual property of Sachit Misra.
|
|
11
|
+
|
|
12
|
+
Permission is granted, free of charge, to any individual to use, copy, and
|
|
13
|
+
modify the Software for personal, educational, or non-commercial research
|
|
14
|
+
purposes, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
1. ATTRIBUTION — Any use or distribution of the Software, in whole or in part,
|
|
17
|
+
must retain this copyright notice and clearly attribute Sachit Misra as the
|
|
18
|
+
original author.
|
|
19
|
+
|
|
20
|
+
2. NON-COMMERCIAL USE ONLY — The Software, or any derivative work based on it,
|
|
21
|
+
may not be used, sold, sublicensed, or incorporated into any product or
|
|
22
|
+
service for commercial purposes without the prior written consent of
|
|
23
|
+
Sachit Misra. Commercial purposes include, but are not limited to:
|
|
24
|
+
- Selling access to the Software or any service powered by it
|
|
25
|
+
- Incorporating the Software into a commercial product or SaaS offering
|
|
26
|
+
- Using the Software to generate revenue directly or indirectly
|
|
27
|
+
|
|
28
|
+
3. NO WARRANTY — The Software is provided "as is", without warranty of any
|
|
29
|
+
kind, express or implied. Sachit Misra shall not be liable for any claim,
|
|
30
|
+
damages, or other liability arising from the use of the Software.
|
|
31
|
+
|
|
32
|
+
For commercial licensing inquiries, contact: mishrasachit1@gmail.com
|
|
33
|
+
|
|
34
|
+
Project-URL: Homepage, https://github.com/sachitrafa/cognitive-ai-memory
|
|
35
|
+
Project-URL: Repository, https://github.com/sachitrafa/cognitive-ai-memory
|
|
36
|
+
Keywords: mcp,claude,memory,ebbinghaus,ai,sqlite,postgresql
|
|
37
|
+
Classifier: Programming Language :: Python :: 3
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
40
|
+
Classifier: Operating System :: OS Independent
|
|
41
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
42
|
+
Requires-Python: >=3.11
|
|
43
|
+
Description-Content-Type: text/markdown
|
|
44
|
+
License-File: LICENSE
|
|
45
|
+
Requires-Dist: fastapi
|
|
46
|
+
Requires-Dist: uvicorn[standard]
|
|
47
|
+
Requires-Dist: psycopg2-binary
|
|
48
|
+
Requires-Dist: pgvector
|
|
49
|
+
Requires-Dist: python-dotenv
|
|
50
|
+
Requires-Dist: httpx
|
|
51
|
+
Requires-Dist: apscheduler
|
|
52
|
+
Requires-Dist: mcp
|
|
53
|
+
Requires-Dist: spacy<4.0,>=3.7
|
|
54
|
+
Requires-Dist: sentence-transformers
|
|
55
|
+
Requires-Dist: numpy
|
|
56
|
+
Requires-Dist: python-dateutil
|
|
57
|
+
Dynamic: license-file
|
|
58
|
+
|
|
59
|
+
# YourMemory
|
|
60
|
+
|
|
61
|
+
**+16pp better recall than Mem0 on LoCoMo. 100% stale memory precision. Biologically-inspired memory decay for AI agents.**
|
|
62
|
+
|
|
63
|
+
Persistent memory for Claude that works like human memory — important things stick, forgotten things fade, outdated facts get demoted automatically.
|
|
64
|
+
|
|
65
|
+
> Early stage — feedback and ideas welcome.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Benchmarks
|
|
70
|
+
|
|
71
|
+
Evaluated against Mem0 (free tier) on the public [LoCoMo dataset](https://github.com/snap-research/locomo) (Snap Research) — 10 conversation pairs, 200 QA pairs total.
|
|
72
|
+
|
|
73
|
+
| Metric | YourMemory | Mem0 | Margin |
|
|
74
|
+
|--------|:----------:|:----:|:------:|
|
|
75
|
+
| LoCoMo Recall@5 *(200 QA pairs)* | **34%** | 18% | **+16pp** |
|
|
76
|
+
| Stale Memory Precision *(5 contradiction pairs)* | **100%** | 0% | **+100pp** |
|
|
77
|
+
| Memories pruned *(noise reduction)* | **20%** | 0% | — |
|
|
78
|
+
|
|
79
|
+
Full methodology and per-sample results in [BENCHMARKS.md](BENCHMARKS.md).
|
|
80
|
+
Read the writeup: [I built memory decay for AI agents using the Ebbinghaus forgetting curve](https://dev.to/sachit_mishra_686a94d1bb5/i-built-memory-decay-for-ai-agents-using-the-ebbinghaus-forgetting-curve-1b0e)
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## How it works
|
|
85
|
+
|
|
86
|
+
### Ebbinghaus Forgetting Curve
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
base_λ = DECAY_RATES[category]
|
|
90
|
+
effective_λ = base_λ × (1 - importance × 0.8)
|
|
91
|
+
strength = importance × e^(-effective_λ × days) × (1 + recall_count × 0.2)
|
|
92
|
+
score = cosine_similarity × strength
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Decay rate varies by **category** — failure memories fade fast, strategies persist longer:
|
|
96
|
+
|
|
97
|
+
| Category | base λ | survives without recall | use case |
|
|
98
|
+
|----------|--------|------------------------|----------|
|
|
99
|
+
| `strategy` | 0.10 | ~38 days | What worked — successful patterns |
|
|
100
|
+
| `fact` | 0.16 | ~24 days | User preferences, identity |
|
|
101
|
+
| `assumption` | 0.20 | ~19 days | Inferred context |
|
|
102
|
+
| `failure` | 0.35 | ~11 days | What went wrong — environment-specific errors |
|
|
103
|
+
|
|
104
|
+
Importance additionally modulates the decay rate within each category. Memories recalled frequently gain `recall_count` boosts that counteract decay. Memories below strength `0.05` are pruned automatically.
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Setup
|
|
109
|
+
|
|
110
|
+
**Zero infrastructure required** — uses SQLite out of the box. Two commands and you're done.
|
|
111
|
+
|
|
112
|
+
### 1. Install
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
git clone https://github.com/sachitrafa/cognitive-ai-memory
|
|
116
|
+
cd cognitive-ai-memory
|
|
117
|
+
pip install .
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
This installs all dependencies including the spaCy model and sentence-transformers embedding model. No separate download steps needed.
|
|
121
|
+
|
|
122
|
+
### 2. Wire into Claude
|
|
123
|
+
|
|
124
|
+
Add to `~/.claude/settings.json`:
|
|
125
|
+
|
|
126
|
+
```json
|
|
127
|
+
{
|
|
128
|
+
"mcpServers": {
|
|
129
|
+
"yourmemory": {
|
|
130
|
+
"command": "yourmemory"
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Reload Claude Code (`Cmd+Shift+P` → `Developer: Reload Window`).
|
|
137
|
+
|
|
138
|
+
The database is created automatically at `~/.yourmemory/memories.db` on first use. No `.env` file needed.
|
|
139
|
+
|
|
140
|
+
### 3. Add memory instructions to your project
|
|
141
|
+
|
|
142
|
+
Copy `sample_CLAUDE.md` into your project root as `CLAUDE.md` and replace:
|
|
143
|
+
- `YOUR_NAME` — your name (e.g. `Alice`)
|
|
144
|
+
- `YOUR_USER_ID` — used to namespace memories (e.g. `alice`)
|
|
145
|
+
|
|
146
|
+
Claude will now follow the recall → store → update workflow automatically on every task.
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
### PostgreSQL (optional — for teams or large datasets)
|
|
151
|
+
|
|
152
|
+
If you have PostgreSQL + pgvector, create a `.env` file:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
DATABASE_URL=postgresql://YOUR_USER@localhost:5432/yourmemory
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
The backend is selected automatically — `postgresql://` in `DATABASE_URL` → Postgres + pgvector, anything else → SQLite.
|
|
159
|
+
|
|
160
|
+
**macOS**
|
|
161
|
+
```bash
|
|
162
|
+
brew install postgresql@16 pgvector && brew services start postgresql@16
|
|
163
|
+
createdb yourmemory
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
**Ubuntu / Debian**
|
|
167
|
+
```bash
|
|
168
|
+
sudo apt install postgresql postgresql-contrib postgresql-16-pgvector
|
|
169
|
+
createdb yourmemory
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
> **One-liner setup script** (macOS/Linux): `bash scripts/setup_db.sh` handles install + DB creation automatically.
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## MCP Tools
|
|
177
|
+
|
|
178
|
+
| Tool | When to call |
|
|
179
|
+
|------|-------------|
|
|
180
|
+
| `recall_memory` | Start of every task — surface relevant context |
|
|
181
|
+
| `store_memory` | After learning a new preference, fact, failure, or strategy |
|
|
182
|
+
| `update_memory` | When a recalled memory is outdated or needs merging |
|
|
183
|
+
|
|
184
|
+
`store_memory` accepts an optional `category` parameter to control decay rate:
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
# Failure — decays in ~11 days (environment changes fast)
|
|
188
|
+
store_memory(
|
|
189
|
+
content="OAuth for client X fails — redirect URI must be app.example.com",
|
|
190
|
+
importance=0.6,
|
|
191
|
+
category="failure"
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
# Strategy — decays in ~38 days (successful patterns stay relevant)
|
|
195
|
+
store_memory(
|
|
196
|
+
content="Cursor pagination fixed the 30s timeout on large user queries",
|
|
197
|
+
importance=0.7,
|
|
198
|
+
category="strategy"
|
|
199
|
+
)
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Example session
|
|
203
|
+
|
|
204
|
+
```
|
|
205
|
+
User: "I prefer tabs over spaces in all my Python projects"
|
|
206
|
+
|
|
207
|
+
Claude:
|
|
208
|
+
→ recall_memory("tabs spaces Python preferences") # nothing found
|
|
209
|
+
→ store_memory("Sachit prefers tabs over spaces in Python", importance=0.9, category="fact")
|
|
210
|
+
|
|
211
|
+
Next session:
|
|
212
|
+
→ recall_memory("Python formatting")
|
|
213
|
+
← {"content": "Sachit prefers tabs over spaces in Python", "strength": 0.87}
|
|
214
|
+
→ Claude now knows without being told again
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Decay Job
|
|
220
|
+
|
|
221
|
+
Runs automatically every 24 hours on startup — no cron needed. Memories below strength `0.05` are pruned.
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## REST API
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
# Store
|
|
229
|
+
curl -X POST http://localhost:8000/memories \
|
|
230
|
+
-H "Content-Type: application/json" \
|
|
231
|
+
-d '{"userId":"u1","content":"Prefers dark mode","importance":0.8}'
|
|
232
|
+
|
|
233
|
+
# Retrieve
|
|
234
|
+
curl -X POST http://localhost:8000/retrieve \
|
|
235
|
+
-H "Content-Type: application/json" \
|
|
236
|
+
-d '{"userId":"u1","query":"UI preferences"}'
|
|
237
|
+
|
|
238
|
+
# List all
|
|
239
|
+
curl "http://localhost:8000/memories?userId=u1"
|
|
240
|
+
|
|
241
|
+
# Update
|
|
242
|
+
curl -X PUT http://localhost:8000/memories/42 \
|
|
243
|
+
-H "Content-Type: application/json" \
|
|
244
|
+
-d '{"content":"Prefers dark mode in all apps","importance":0.85}'
|
|
245
|
+
|
|
246
|
+
# Delete
|
|
247
|
+
curl -X DELETE http://localhost:8000/memories/42
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## Stack
|
|
253
|
+
|
|
254
|
+
- **PostgreSQL + pgvector** — vector similarity search
|
|
255
|
+
- **sentence-transformers** — local embeddings (`all-mpnet-base-v2`, 768 dims, no external service needed)
|
|
256
|
+
- **FastAPI** — REST server
|
|
257
|
+
- **APScheduler** — automatic 24h decay job
|
|
258
|
+
- **MCP** — Claude integration via Model Context Protocol
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## Architecture
|
|
263
|
+
|
|
264
|
+
```
|
|
265
|
+
Claude Code
|
|
266
|
+
│
|
|
267
|
+
├── recall_memory(query)
|
|
268
|
+
│ └── embed → cosine similarity → score = sim × strength → top-k
|
|
269
|
+
│
|
|
270
|
+
├── store_memory(content, importance, category?)
|
|
271
|
+
│ └── is_question? → reject
|
|
272
|
+
│ category: fact | assumption | failure | strategy
|
|
273
|
+
│ embed() → INSERT memories
|
|
274
|
+
│
|
|
275
|
+
└── update_memory(id, new_content)
|
|
276
|
+
└── embed(new_content) → UPDATE memories
|
|
277
|
+
|
|
278
|
+
PostgreSQL (pgvector)
|
|
279
|
+
└── memories
|
|
280
|
+
├── embedding vector(768)
|
|
281
|
+
├── importance float
|
|
282
|
+
├── recall_count int
|
|
283
|
+
└── last_accessed_at
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## Dataset Reference
|
|
289
|
+
|
|
290
|
+
Benchmarks use the [LoCoMo](https://github.com/snap-research/locomo) dataset by Snap Research — a public long-context memory benchmark for multi-session dialogue.
|
|
291
|
+
|
|
292
|
+
> Maharana et al. (2024). *LoCoMo: Long Context Multimodal Benchmark for Dialogue.* Snap Research.
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
## License
|
|
297
|
+
|
|
298
|
+
Copyright (c) 2026 **Sachit Misra**. All rights reserved.
|
|
299
|
+
|
|
300
|
+
All source code, algorithms, scoring formulas, data structures, and associated documentation in this repository are the exclusive intellectual property of Sachit Misra.
|
|
301
|
+
|
|
302
|
+
**Non-commercial use only.** Personal, educational, and research use is permitted with attribution. Commercial use — including incorporation into products, SaaS offerings, or revenue-generating services — requires prior written consent.
|
|
303
|
+
|
|
304
|
+
For commercial licensing: mishrasachit1@gmail.com
|
|
305
|
+
|
|
306
|
+
See [LICENSE](LICENSE) for full terms.
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# YourMemory
|
|
2
|
+
|
|
3
|
+
**+16pp better recall than Mem0 on LoCoMo. 100% stale memory precision. Biologically-inspired memory decay for AI agents.**
|
|
4
|
+
|
|
5
|
+
Persistent memory for Claude that works like human memory — important things stick, forgotten things fade, outdated facts get demoted automatically.
|
|
6
|
+
|
|
7
|
+
> Early stage — feedback and ideas welcome.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Benchmarks
|
|
12
|
+
|
|
13
|
+
Evaluated against Mem0 (free tier) on the public [LoCoMo dataset](https://github.com/snap-research/locomo) (Snap Research) — 10 conversation pairs, 200 QA pairs total.
|
|
14
|
+
|
|
15
|
+
| Metric | YourMemory | Mem0 | Margin |
|
|
16
|
+
|--------|:----------:|:----:|:------:|
|
|
17
|
+
| LoCoMo Recall@5 *(200 QA pairs)* | **34%** | 18% | **+16pp** |
|
|
18
|
+
| Stale Memory Precision *(5 contradiction pairs)* | **100%** | 0% | **+100pp** |
|
|
19
|
+
| Memories pruned *(noise reduction)* | **20%** | 0% | — |
|
|
20
|
+
|
|
21
|
+
Full methodology and per-sample results in [BENCHMARKS.md](BENCHMARKS.md).
|
|
22
|
+
Read the writeup: [I built memory decay for AI agents using the Ebbinghaus forgetting curve](https://dev.to/sachit_mishra_686a94d1bb5/i-built-memory-decay-for-ai-agents-using-the-ebbinghaus-forgetting-curve-1b0e)
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## How it works
|
|
27
|
+
|
|
28
|
+
### Ebbinghaus Forgetting Curve
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
base_λ = DECAY_RATES[category]
|
|
32
|
+
effective_λ = base_λ × (1 - importance × 0.8)
|
|
33
|
+
strength = importance × e^(-effective_λ × days) × (1 + recall_count × 0.2)
|
|
34
|
+
score = cosine_similarity × strength
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Decay rate varies by **category** — failure memories fade fast, strategies persist longer:
|
|
38
|
+
|
|
39
|
+
| Category | base λ | survives without recall | use case |
|
|
40
|
+
|----------|--------|------------------------|----------|
|
|
41
|
+
| `strategy` | 0.10 | ~38 days | What worked — successful patterns |
|
|
42
|
+
| `fact` | 0.16 | ~24 days | User preferences, identity |
|
|
43
|
+
| `assumption` | 0.20 | ~19 days | Inferred context |
|
|
44
|
+
| `failure` | 0.35 | ~11 days | What went wrong — environment-specific errors |
|
|
45
|
+
|
|
46
|
+
Importance additionally modulates the decay rate within each category. Memories recalled frequently gain `recall_count` boosts that counteract decay. Memories below strength `0.05` are pruned automatically.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Setup
|
|
51
|
+
|
|
52
|
+
**Zero infrastructure required** — uses SQLite out of the box. Two commands and you're done.
|
|
53
|
+
|
|
54
|
+
### 1. Install
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
git clone https://github.com/sachitrafa/cognitive-ai-memory
|
|
58
|
+
cd cognitive-ai-memory
|
|
59
|
+
pip install .
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
This installs all dependencies including the spaCy model and sentence-transformers embedding model. No separate download steps needed.
|
|
63
|
+
|
|
64
|
+
### 2. Wire into Claude
|
|
65
|
+
|
|
66
|
+
Add to `~/.claude/settings.json`:
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"mcpServers": {
|
|
71
|
+
"yourmemory": {
|
|
72
|
+
"command": "yourmemory"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Reload Claude Code (`Cmd+Shift+P` → `Developer: Reload Window`).
|
|
79
|
+
|
|
80
|
+
The database is created automatically at `~/.yourmemory/memories.db` on first use. No `.env` file needed.
|
|
81
|
+
|
|
82
|
+
### 3. Add memory instructions to your project
|
|
83
|
+
|
|
84
|
+
Copy `sample_CLAUDE.md` into your project root as `CLAUDE.md` and replace:
|
|
85
|
+
- `YOUR_NAME` — your name (e.g. `Alice`)
|
|
86
|
+
- `YOUR_USER_ID` — used to namespace memories (e.g. `alice`)
|
|
87
|
+
|
|
88
|
+
Claude will now follow the recall → store → update workflow automatically on every task.
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
### PostgreSQL (optional — for teams or large datasets)
|
|
93
|
+
|
|
94
|
+
If you have PostgreSQL + pgvector, create a `.env` file:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
DATABASE_URL=postgresql://YOUR_USER@localhost:5432/yourmemory
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The backend is selected automatically — `postgresql://` in `DATABASE_URL` → Postgres + pgvector, anything else → SQLite.
|
|
101
|
+
|
|
102
|
+
**macOS**
|
|
103
|
+
```bash
|
|
104
|
+
brew install postgresql@16 pgvector && brew services start postgresql@16
|
|
105
|
+
createdb yourmemory
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Ubuntu / Debian**
|
|
109
|
+
```bash
|
|
110
|
+
sudo apt install postgresql postgresql-contrib postgresql-16-pgvector
|
|
111
|
+
createdb yourmemory
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
> **One-liner setup script** (macOS/Linux): `bash scripts/setup_db.sh` handles install + DB creation automatically.
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## MCP Tools
|
|
119
|
+
|
|
120
|
+
| Tool | When to call |
|
|
121
|
+
|------|-------------|
|
|
122
|
+
| `recall_memory` | Start of every task — surface relevant context |
|
|
123
|
+
| `store_memory` | After learning a new preference, fact, failure, or strategy |
|
|
124
|
+
| `update_memory` | When a recalled memory is outdated or needs merging |
|
|
125
|
+
|
|
126
|
+
`store_memory` accepts an optional `category` parameter to control decay rate:
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
# Failure — decays in ~11 days (environment changes fast)
|
|
130
|
+
store_memory(
|
|
131
|
+
content="OAuth for client X fails — redirect URI must be app.example.com",
|
|
132
|
+
importance=0.6,
|
|
133
|
+
category="failure"
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
# Strategy — decays in ~38 days (successful patterns stay relevant)
|
|
137
|
+
store_memory(
|
|
138
|
+
content="Cursor pagination fixed the 30s timeout on large user queries",
|
|
139
|
+
importance=0.7,
|
|
140
|
+
category="strategy"
|
|
141
|
+
)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Example session
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
User: "I prefer tabs over spaces in all my Python projects"
|
|
148
|
+
|
|
149
|
+
Claude:
|
|
150
|
+
→ recall_memory("tabs spaces Python preferences") # nothing found
|
|
151
|
+
→ store_memory("Sachit prefers tabs over spaces in Python", importance=0.9, category="fact")
|
|
152
|
+
|
|
153
|
+
Next session:
|
|
154
|
+
→ recall_memory("Python formatting")
|
|
155
|
+
← {"content": "Sachit prefers tabs over spaces in Python", "strength": 0.87}
|
|
156
|
+
→ Claude now knows without being told again
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Decay Job
|
|
162
|
+
|
|
163
|
+
Runs automatically every 24 hours on startup — no cron needed. Memories below strength `0.05` are pruned.
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## REST API
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
# Store
|
|
171
|
+
curl -X POST http://localhost:8000/memories \
|
|
172
|
+
-H "Content-Type: application/json" \
|
|
173
|
+
-d '{"userId":"u1","content":"Prefers dark mode","importance":0.8}'
|
|
174
|
+
|
|
175
|
+
# Retrieve
|
|
176
|
+
curl -X POST http://localhost:8000/retrieve \
|
|
177
|
+
-H "Content-Type: application/json" \
|
|
178
|
+
-d '{"userId":"u1","query":"UI preferences"}'
|
|
179
|
+
|
|
180
|
+
# List all
|
|
181
|
+
curl "http://localhost:8000/memories?userId=u1"
|
|
182
|
+
|
|
183
|
+
# Update
|
|
184
|
+
curl -X PUT http://localhost:8000/memories/42 \
|
|
185
|
+
-H "Content-Type: application/json" \
|
|
186
|
+
-d '{"content":"Prefers dark mode in all apps","importance":0.85}'
|
|
187
|
+
|
|
188
|
+
# Delete
|
|
189
|
+
curl -X DELETE http://localhost:8000/memories/42
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## Stack
|
|
195
|
+
|
|
196
|
+
- **PostgreSQL + pgvector** — vector similarity search
|
|
197
|
+
- **sentence-transformers** — local embeddings (`all-mpnet-base-v2`, 768 dims, no external service needed)
|
|
198
|
+
- **FastAPI** — REST server
|
|
199
|
+
- **APScheduler** — automatic 24h decay job
|
|
200
|
+
- **MCP** — Claude integration via Model Context Protocol
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Architecture
|
|
205
|
+
|
|
206
|
+
```
|
|
207
|
+
Claude Code
|
|
208
|
+
│
|
|
209
|
+
├── recall_memory(query)
|
|
210
|
+
│ └── embed → cosine similarity → score = sim × strength → top-k
|
|
211
|
+
│
|
|
212
|
+
├── store_memory(content, importance, category?)
|
|
213
|
+
│ └── is_question? → reject
|
|
214
|
+
│ category: fact | assumption | failure | strategy
|
|
215
|
+
│ embed() → INSERT memories
|
|
216
|
+
│
|
|
217
|
+
└── update_memory(id, new_content)
|
|
218
|
+
└── embed(new_content) → UPDATE memories
|
|
219
|
+
|
|
220
|
+
PostgreSQL (pgvector)
|
|
221
|
+
└── memories
|
|
222
|
+
├── embedding vector(768)
|
|
223
|
+
├── importance float
|
|
224
|
+
├── recall_count int
|
|
225
|
+
└── last_accessed_at
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## Dataset Reference
|
|
231
|
+
|
|
232
|
+
Benchmarks use the [LoCoMo](https://github.com/snap-research/locomo) dataset by Snap Research — a public long-context memory benchmark for multi-session dialogue.
|
|
233
|
+
|
|
234
|
+
> Maharana et al. (2024). *LoCoMo: Long Context Multimodal Benchmark for Dialogue.* Snap Research.
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## License
|
|
239
|
+
|
|
240
|
+
Copyright (c) 2026 **Sachit Misra**. All rights reserved.
|
|
241
|
+
|
|
242
|
+
All source code, algorithms, scoring formulas, data structures, and associated documentation in this repository are the exclusive intellectual property of Sachit Misra.
|
|
243
|
+
|
|
244
|
+
**Non-commercial use only.** Personal, educational, and research use is permitted with attribution. Commercial use — including incorporation into products, SaaS offerings, or revenue-generating services — requires prior written consent.
|
|
245
|
+
|
|
246
|
+
For commercial licensing: mishrasachit1@gmail.com
|
|
247
|
+
|
|
248
|
+
See [LICENSE](LICENSE) for full terms.
|