mnemon-memory 0.2.0__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.
- mnemon_memory-0.2.0/.github/workflows/ci.yml +40 -0
- mnemon_memory-0.2.0/.gitignore +40 -0
- mnemon_memory-0.2.0/CHANGELOG.md +30 -0
- mnemon_memory-0.2.0/CLAUDE.md +65 -0
- mnemon_memory-0.2.0/LICENSE +21 -0
- mnemon_memory-0.2.0/PKG-INFO +265 -0
- mnemon_memory-0.2.0/README.md +224 -0
- mnemon_memory-0.2.0/pyproject.toml +59 -0
- mnemon_memory-0.2.0/src/mnemon/__init__.py +3 -0
- mnemon_memory-0.2.0/src/mnemon/cli.py +181 -0
- mnemon_memory-0.2.0/src/mnemon/config.py +79 -0
- mnemon_memory-0.2.0/src/mnemon/contradiction.py +183 -0
- mnemon_memory-0.2.0/src/mnemon/embedder.py +84 -0
- mnemon_memory-0.2.0/src/mnemon/hooks/__init__.py +0 -0
- mnemon_memory-0.2.0/src/mnemon/hooks/context_surfacing.py +101 -0
- mnemon_memory-0.2.0/src/mnemon/hooks/framework.py +114 -0
- mnemon_memory-0.2.0/src/mnemon/hooks/handoff_generator.py +149 -0
- mnemon_memory-0.2.0/src/mnemon/hooks/session_extractor.py +198 -0
- mnemon_memory-0.2.0/src/mnemon/llm.py +113 -0
- mnemon_memory-0.2.0/src/mnemon/py.typed +0 -0
- mnemon_memory-0.2.0/src/mnemon/search.py +216 -0
- mnemon_memory-0.2.0/src/mnemon/server.py +324 -0
- mnemon_memory-0.2.0/src/mnemon/server_remote.py +32 -0
- mnemon_memory-0.2.0/src/mnemon/setup.py +167 -0
- mnemon_memory-0.2.0/src/mnemon/store.py +507 -0
- mnemon_memory-0.2.0/src/mnemon/sync.py +125 -0
- mnemon_memory-0.2.0/src/mnemon/vecstore.py +115 -0
- mnemon_memory-0.2.0/tests/__init__.py +0 -0
- mnemon_memory-0.2.0/tests/test_cli.py +377 -0
- mnemon_memory-0.2.0/tests/test_contradiction.py +248 -0
- mnemon_memory-0.2.0/tests/test_embedder.py +174 -0
- mnemon_memory-0.2.0/tests/test_hooks.py +163 -0
- mnemon_memory-0.2.0/tests/test_hooks_extended.py +577 -0
- mnemon_memory-0.2.0/tests/test_llm.py +68 -0
- mnemon_memory-0.2.0/tests/test_search.py +123 -0
- mnemon_memory-0.2.0/tests/test_server.py +680 -0
- mnemon_memory-0.2.0/tests/test_server_remote.py +58 -0
- mnemon_memory-0.2.0/tests/test_setup.py +107 -0
- mnemon_memory-0.2.0/tests/test_store.py +210 -0
- mnemon_memory-0.2.0/tests/test_sync.py +122 -0
- mnemon_memory-0.2.0/tests/test_vecstore.py +80 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.12", "3.13"]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: ${{ matrix.python-version }}
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: pip install -e ".[dev]"
|
|
26
|
+
|
|
27
|
+
- name: Run tests
|
|
28
|
+
run: pytest tests/ -v
|
|
29
|
+
|
|
30
|
+
secrets:
|
|
31
|
+
runs-on: ubuntu-latest
|
|
32
|
+
|
|
33
|
+
steps:
|
|
34
|
+
- uses: actions/checkout@v4
|
|
35
|
+
with:
|
|
36
|
+
fetch-depth: 0
|
|
37
|
+
|
|
38
|
+
- uses: gitleaks/gitleaks-action@v2
|
|
39
|
+
env:
|
|
40
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
dist/
|
|
6
|
+
build/
|
|
7
|
+
.venv/
|
|
8
|
+
.pytest_cache/
|
|
9
|
+
|
|
10
|
+
# Vault data (local only)
|
|
11
|
+
*.sqlite
|
|
12
|
+
*.sqlite-wal
|
|
13
|
+
*.sqlite-shm
|
|
14
|
+
*.vec
|
|
15
|
+
*.vec.npz
|
|
16
|
+
|
|
17
|
+
# GGUF models
|
|
18
|
+
*.gguf
|
|
19
|
+
|
|
20
|
+
# Environment / secrets
|
|
21
|
+
.env
|
|
22
|
+
.env.*
|
|
23
|
+
|
|
24
|
+
# Editors / OS
|
|
25
|
+
.idea/
|
|
26
|
+
.vscode/
|
|
27
|
+
.cursor/
|
|
28
|
+
.DS_Store
|
|
29
|
+
|
|
30
|
+
# Logs / caches
|
|
31
|
+
*.log
|
|
32
|
+
.cache/
|
|
33
|
+
.coverage
|
|
34
|
+
|
|
35
|
+
# Legacy TypeScript
|
|
36
|
+
ts/
|
|
37
|
+
node_modules/
|
|
38
|
+
|
|
39
|
+
# Flow Doctor (testing artifact)
|
|
40
|
+
flow_doctor.db
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.2.0] - 2026-04-09
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Full Python rewrite (was TypeScript/Bun in v0.1.x)
|
|
7
|
+
- 13 MCP tools: search, get, timeline, save, pin, forget, status, sweep, related, rebuild, check_contradictions, profile_get, profile_update
|
|
8
|
+
- Hybrid BM25 + vector search with Reciprocal Rank Fusion and MMR diversity filtering
|
|
9
|
+
- Composite scoring: 0.5 * relevance + 0.25 * recency + 0.25 * confidence
|
|
10
|
+
- FastEmbed embeddings (bge-small-en-v1.5, 384d ONNX — no PyTorch needed)
|
|
11
|
+
- Memory lifecycle: content-type-based half-life decay, pinning, archival via sweep
|
|
12
|
+
- Contradiction detection with confidence decay (vector similarity + optional LLM classification)
|
|
13
|
+
- Claude Code hooks: context surfacing (UserPromptSubmit), session extraction (Stop), handoff generation (Stop)
|
|
14
|
+
- Auto-configure command: `mnemon setup claude-code|cursor|gemini|hooks`
|
|
15
|
+
- Remote Streamable HTTP server via FastMCP native transport
|
|
16
|
+
- S3 vault sync (push/pull via AWS CLI)
|
|
17
|
+
- CLI: serve, serve-remote, status, search, save, forget, sync, setup
|
|
18
|
+
- Optional local LLM (QMD-1.7B via llama-cpp-python) for query expansion, extraction, contradiction detection
|
|
19
|
+
- 253 tests, 90% coverage
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- Rewritten from TypeScript (Bun) to Python (>=3.10)
|
|
23
|
+
- Storage: SQLite + FTS5 + numpy vector store (was SQLite + FTS5 + TypeScript vector store)
|
|
24
|
+
- Embedding: FastEmbed bge-small-en-v1.5 (was EmbeddingGemma-300M)
|
|
25
|
+
- Build: hatchling (was Bun bundler)
|
|
26
|
+
- Package distribution: PyPI (was npm)
|
|
27
|
+
|
|
28
|
+
## [0.1.x] - 2026-04-08
|
|
29
|
+
|
|
30
|
+
Initial TypeScript implementation (deprecated, replaced by Python rewrite in v0.2.0).
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# mnemon
|
|
2
|
+
|
|
3
|
+
Universal long-term memory layer for AI agents via MCP.
|
|
4
|
+
|
|
5
|
+
## Stack
|
|
6
|
+
|
|
7
|
+
- **Runtime:** Python >= 3.10
|
|
8
|
+
- **Storage:** SQLite + FTS5 + in-process vector store (single-file vault at `~/.mnemon/default.sqlite`)
|
|
9
|
+
- **Embedding:** FastEmbed with bge-small-en-v1.5 (384d, ONNX, ~13MB)
|
|
10
|
+
- **LLM (optional):** QMD-query-expansion-1.7B (GGUF via llama-cpp-python, for extraction + expansion)
|
|
11
|
+
- **MCP:** FastMCP (stdio + Streamable HTTP transports)
|
|
12
|
+
- **Package:** hatchling build backend, `pip install -e ".[dev]"` for development
|
|
13
|
+
|
|
14
|
+
## Key files
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
src/mnemon/
|
|
18
|
+
store.py # SQLite storage — content, documents, FTS5, relations
|
|
19
|
+
vecstore.py # In-process vector store — brute-force cosine over numpy arrays
|
|
20
|
+
embedder.py # FastEmbed bge-small-en-v1.5 wrapper
|
|
21
|
+
search.py # BM25 + vector + query expansion + RRF fusion + MMR
|
|
22
|
+
llm.py # QMD-1.7B via llama-cpp-python (optional)
|
|
23
|
+
contradiction.py # Contradiction detection + confidence decay
|
|
24
|
+
config.py # Content types, half-lives, scoring constants
|
|
25
|
+
server.py # MCP server (stdio) — 13 tools
|
|
26
|
+
server_remote.py # Remote HTTP server (Streamable HTTP)
|
|
27
|
+
sync.py # S3 vault sync (push/pull via AWS CLI)
|
|
28
|
+
setup.py # Auto-configure Claude Code, Cursor, Gemini
|
|
29
|
+
cli.py # CLI dispatcher
|
|
30
|
+
__init__.py # Version
|
|
31
|
+
hooks/
|
|
32
|
+
framework.py # Hook framework — stdin/stdout, dedup, noise filtering
|
|
33
|
+
context_surfacing.py # UserPromptSubmit — search + inject context
|
|
34
|
+
session_extractor.py # Stop — extract observations (LLM or regex)
|
|
35
|
+
handoff_generator.py # Stop — session summary (LLM or template)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Commands
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# Development
|
|
42
|
+
pip install -e ".[dev]" # Install with dev deps
|
|
43
|
+
pytest # Run tests (102 tests)
|
|
44
|
+
pytest -v # Verbose output
|
|
45
|
+
pytest tests/test_store.py # Single file
|
|
46
|
+
|
|
47
|
+
# CLI
|
|
48
|
+
mnemon serve # MCP server (stdio)
|
|
49
|
+
mnemon serve-remote # HTTP server (Streamable HTTP)
|
|
50
|
+
mnemon status # Vault health
|
|
51
|
+
mnemon search <query> # Search memories
|
|
52
|
+
mnemon save <title> <content> # Save a memory
|
|
53
|
+
mnemon setup <target> # Configure (claude-code, cursor, gemini, hooks)
|
|
54
|
+
mnemon sync <push|pull> # S3 vault sync
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Testing
|
|
58
|
+
|
|
59
|
+
All tests must pass before committing. Tests use temporary SQLite databases and mock external dependencies (LLM, embeddings, AWS CLI).
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pytest # Quick check
|
|
63
|
+
pytest -v # See individual test names
|
|
64
|
+
pytest --tb=short # Shorter tracebacks on failure
|
|
65
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Brian McMahon
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mnemon-memory
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Universal long-term memory layer for AI agents via MCP
|
|
5
|
+
Project-URL: Homepage, https://github.com/cipher813/mnemon
|
|
6
|
+
Project-URL: Repository, https://github.com/cipher813/mnemon
|
|
7
|
+
Project-URL: Issues, https://github.com/cipher813/mnemon/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/cipher813/mnemon/blob/main/CHANGELOG.md
|
|
9
|
+
Author-email: Brian McMahon <cipher813@gmail.com>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: agents,ai,llm,mcp,memory,sqlite,vector-search
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Requires-Dist: fastembed>=0.3
|
|
23
|
+
Requires-Dist: mcp>=1.27
|
|
24
|
+
Requires-Dist: numpy>=1.24
|
|
25
|
+
Provides-Extra: all
|
|
26
|
+
Requires-Dist: httpx>=0.27; extra == 'all'
|
|
27
|
+
Requires-Dist: huggingface-hub>=0.20; extra == 'all'
|
|
28
|
+
Requires-Dist: llama-cpp-python>=0.3; extra == 'all'
|
|
29
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'all'
|
|
30
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'all'
|
|
31
|
+
Requires-Dist: pytest>=8.0; extra == 'all'
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: httpx>=0.27; extra == 'dev'
|
|
34
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
35
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
36
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
37
|
+
Provides-Extra: llm
|
|
38
|
+
Requires-Dist: huggingface-hub>=0.20; extra == 'llm'
|
|
39
|
+
Requires-Dist: llama-cpp-python>=0.3; extra == 'llm'
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
|
|
42
|
+
# mnemon
|
|
43
|
+
|
|
44
|
+
[]()
|
|
45
|
+
[](LICENSE)
|
|
46
|
+
[]()
|
|
47
|
+
[]()
|
|
48
|
+
[](https://modelcontextprotocol.io)
|
|
49
|
+
[](https://pypi.org/project/mnemon-memory/)
|
|
50
|
+
|
|
51
|
+
> Universal long-term memory layer for AI agents via [MCP](https://modelcontextprotocol.io).
|
|
52
|
+
|
|
53
|
+
mnemon gives AI agents persistent, searchable memory that survives across sessions. It stores memories in a local SQLite vault with hybrid BM25 + vector search, automatic confidence decay, contradiction detection, and the Model Context Protocol for seamless integration with Claude Code, Cursor, and other MCP clients.
|
|
54
|
+
|
|
55
|
+
## Table of Contents
|
|
56
|
+
|
|
57
|
+
- [Install](#install)
|
|
58
|
+
- [Quick Start](#quick-start)
|
|
59
|
+
- [MCP Tools](#mcp-tools)
|
|
60
|
+
- [Memory Types](#memory-types)
|
|
61
|
+
- [Claude Code Hooks](#claude-code-hooks)
|
|
62
|
+
- [Remote Server](#remote-server)
|
|
63
|
+
- [S3 Vault Sync](#s3-vault-sync)
|
|
64
|
+
- [Architecture](#architecture)
|
|
65
|
+
- [Configuration](#configuration)
|
|
66
|
+
- [Development](#development)
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Install
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pip install mnemon-memory
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
With optional LLM support (local 1.7B model for query expansion, contradiction detection, and smarter session extraction):
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
pip install "mnemon-memory[llm]"
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
From source:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
git clone https://github.com/cipher813/mnemon.git
|
|
86
|
+
cd mnemon
|
|
87
|
+
pip install -e ".[dev]"
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Quick Start
|
|
91
|
+
|
|
92
|
+
### 1. Configure your client
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# Auto-configure Claude Code (MCP server + memory hooks)
|
|
96
|
+
mnemon setup claude-code
|
|
97
|
+
|
|
98
|
+
# Or configure Cursor
|
|
99
|
+
mnemon setup cursor
|
|
100
|
+
|
|
101
|
+
# Or just the hooks (if MCP is already configured)
|
|
102
|
+
mnemon setup hooks
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### 2. Use it
|
|
106
|
+
|
|
107
|
+
Once configured, mnemon works automatically:
|
|
108
|
+
|
|
109
|
+
- **Context surfacing**: relevant memories are injected before each prompt
|
|
110
|
+
- **Session extraction**: decisions, preferences, and observations are saved at session end
|
|
111
|
+
- **Handoff generation**: session summaries maintain continuity across sessions
|
|
112
|
+
|
|
113
|
+
You can also interact with memories directly via MCP tools or CLI:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
mnemon search "deployment architecture"
|
|
117
|
+
mnemon save "DB migration plan" "Migrate from PostgreSQL to DynamoDB in Q3"
|
|
118
|
+
mnemon forget 42
|
|
119
|
+
mnemon status
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## MCP Tools
|
|
123
|
+
|
|
124
|
+
### Retrieval
|
|
125
|
+
|
|
126
|
+
| Tool | Description |
|
|
127
|
+
|------|-------------|
|
|
128
|
+
| `memory_search` | Hybrid BM25 + vector search with composite scoring (relevance + recency + confidence) |
|
|
129
|
+
| `memory_get` | Fetch a specific memory by ID with full content |
|
|
130
|
+
| `memory_timeline` | Recent memories in reverse chronological order |
|
|
131
|
+
| `memory_related` | Find memories related to a given memory via the relationship graph |
|
|
132
|
+
|
|
133
|
+
### Mutation
|
|
134
|
+
|
|
135
|
+
| Tool | Description |
|
|
136
|
+
|------|-------------|
|
|
137
|
+
| `memory_save` | Store a new memory with content type classification and auto-embedding |
|
|
138
|
+
| `memory_pin` | Pin a memory to boost confidence and prevent archival |
|
|
139
|
+
| `memory_forget` | Soft-delete a memory (marked as invalidated, not physically removed) |
|
|
140
|
+
|
|
141
|
+
### Lifecycle
|
|
142
|
+
|
|
143
|
+
| Tool | Description |
|
|
144
|
+
|------|-------------|
|
|
145
|
+
| `memory_status` | Vault health stats — counts by type, vectors, pinned/invalidated |
|
|
146
|
+
| `memory_sweep` | Archive stale memories past their half-life (dry-run by default) |
|
|
147
|
+
| `memory_rebuild` | Re-embed all documents (use after upgrading embedding model) |
|
|
148
|
+
|
|
149
|
+
### Intelligence
|
|
150
|
+
|
|
151
|
+
| Tool | Description |
|
|
152
|
+
|------|-------------|
|
|
153
|
+
| `memory_check_contradictions` | Check a memory for conflicts using vector similarity + LLM classification |
|
|
154
|
+
| `profile_get` | Synthesized user profile from stored preferences and decisions |
|
|
155
|
+
| `profile_update` | Manually add a fact to the user profile |
|
|
156
|
+
|
|
157
|
+
## Memory Types
|
|
158
|
+
|
|
159
|
+
Each memory has a content type that determines its default confidence and decay half-life:
|
|
160
|
+
|
|
161
|
+
| Type | Default Confidence | Half-Life | Use for |
|
|
162
|
+
|------|-------------------|-----------|---------|
|
|
163
|
+
| `decision` | 0.85 | Never | Architectural choices, design decisions |
|
|
164
|
+
| `preference` | 0.80 | Never | User workflow habits, style preferences |
|
|
165
|
+
| `antipattern` | 0.80 | Never | Things that failed, approaches to avoid |
|
|
166
|
+
| `observation` | 0.70 | 90 days | Learned facts, discovered behaviors |
|
|
167
|
+
| `research` | 0.70 | 90 days | Investigation results, findings |
|
|
168
|
+
| `project` | 0.65 | 120 days | Project status, goals, context |
|
|
169
|
+
| `handoff` | 0.60 | 30 days | Session summaries for continuity |
|
|
170
|
+
| `note` | 0.50 | 60 days | General notes, default type |
|
|
171
|
+
|
|
172
|
+
Memories with access activity decay slower — each access extends the effective half-life by 10%, up to 3x the base value.
|
|
173
|
+
|
|
174
|
+
## Claude Code Hooks
|
|
175
|
+
|
|
176
|
+
When configured via `mnemon setup claude-code`, three hooks are installed:
|
|
177
|
+
|
|
178
|
+
| Hook | Event | Timeout | Description |
|
|
179
|
+
|------|-------|---------|-------------|
|
|
180
|
+
| Context surfacing | `UserPromptSubmit` | 8s | Searches vault and injects relevant memories as context |
|
|
181
|
+
| Session extractor | `Stop` | 30s | Extracts decisions, preferences, and observations from the transcript |
|
|
182
|
+
| Handoff generator | `Stop` | 30s | Creates a session summary for the next session |
|
|
183
|
+
|
|
184
|
+
The extractor and handoff generator use LLM-based extraction when `mnemon[llm]` is installed, with regex/heuristic fallback otherwise.
|
|
185
|
+
|
|
186
|
+
## Remote Server
|
|
187
|
+
|
|
188
|
+
For use with Claude.ai web or iOS (any Streamable HTTP MCP client):
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
# Start remote server
|
|
192
|
+
mnemon serve-remote
|
|
193
|
+
|
|
194
|
+
# With authentication (at proxy/infra level)
|
|
195
|
+
MNEMON_TOKEN=your-secret-token mnemon serve-remote
|
|
196
|
+
|
|
197
|
+
# Custom port
|
|
198
|
+
PORT=9000 mnemon serve-remote
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
The remote server exposes the same MCP tools as stdio mode via FastMCP's native Streamable HTTP transport at `http://localhost:8502/mcp`.
|
|
202
|
+
|
|
203
|
+
## S3 Vault Sync
|
|
204
|
+
|
|
205
|
+
Sync your vault across machines via S3:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
# Push local vault to S3
|
|
209
|
+
MNEMON_S3_BUCKET=my-bucket mnemon sync push
|
|
210
|
+
|
|
211
|
+
# Pull vault from S3
|
|
212
|
+
MNEMON_S3_BUCKET=my-bucket mnemon sync pull
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
| Env var | Default | Description |
|
|
216
|
+
|---------|---------|-------------|
|
|
217
|
+
| `MNEMON_S3_BUCKET` | (required) | S3 bucket name |
|
|
218
|
+
| `MNEMON_S3_PREFIX` | `mnemon/vaults` | S3 key prefix |
|
|
219
|
+
| `MNEMON_VAULT_NAME` | `default` | Vault name |
|
|
220
|
+
|
|
221
|
+
Requires the AWS CLI (`aws`) on your PATH with valid credentials.
|
|
222
|
+
|
|
223
|
+
## Architecture
|
|
224
|
+
|
|
225
|
+
```
|
|
226
|
+
~/.mnemon/
|
|
227
|
+
default.sqlite SQLite vault (FTS5 + WAL mode)
|
|
228
|
+
default.vec.npz Companion vector store (numpy, brute-force cosine)
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
- **Storage**: SQLite with FTS5 full-text search, content-addressable deduplication (SHA-256)
|
|
232
|
+
- **Search**: Hybrid BM25 + vector (384d, bge-small-en-v1.5 via FastEmbed) fused with Reciprocal Rank Fusion
|
|
233
|
+
- **Scoring**: Composite score = 0.5 * relevance + 0.25 * recency + 0.25 * confidence
|
|
234
|
+
- **Diversity**: MMR filtering (Jaccard bigram similarity > 0.6 demoted by 50%)
|
|
235
|
+
- **Intelligence** (optional): Local 1.7B LLM (QMD-query-expansion) for query expansion, contradiction detection, session extraction — zero API cost
|
|
236
|
+
- **Transport**: MCP stdio (local) and Streamable HTTP (remote)
|
|
237
|
+
|
|
238
|
+
## Configuration
|
|
239
|
+
|
|
240
|
+
| Env var | Default | Description |
|
|
241
|
+
|---------|---------|-------------|
|
|
242
|
+
| `MNEMON_VAULT_DIR` | `~/.mnemon` | Vault directory |
|
|
243
|
+
| `MNEMON_TOKEN` | (none) | Bearer token for remote server auth |
|
|
244
|
+
| `MNEMON_MODEL_DIR` | `~/.mnemon/models` | Directory for LLM model files |
|
|
245
|
+
| `PORT` | `8502` | Remote server port |
|
|
246
|
+
|
|
247
|
+
## Development
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
# Install with dev dependencies
|
|
251
|
+
pip install -e ".[dev]"
|
|
252
|
+
|
|
253
|
+
# Run tests (253 tests)
|
|
254
|
+
pytest
|
|
255
|
+
|
|
256
|
+
# Run tests with coverage
|
|
257
|
+
pytest --cov=mnemon --cov-report=term-missing
|
|
258
|
+
|
|
259
|
+
# Run a specific test file
|
|
260
|
+
pytest tests/test_store.py -v
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## License
|
|
264
|
+
|
|
265
|
+
MIT
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# mnemon
|
|
2
|
+
|
|
3
|
+
[]()
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
[]()
|
|
6
|
+
[]()
|
|
7
|
+
[](https://modelcontextprotocol.io)
|
|
8
|
+
[](https://pypi.org/project/mnemon-memory/)
|
|
9
|
+
|
|
10
|
+
> Universal long-term memory layer for AI agents via [MCP](https://modelcontextprotocol.io).
|
|
11
|
+
|
|
12
|
+
mnemon gives AI agents persistent, searchable memory that survives across sessions. It stores memories in a local SQLite vault with hybrid BM25 + vector search, automatic confidence decay, contradiction detection, and the Model Context Protocol for seamless integration with Claude Code, Cursor, and other MCP clients.
|
|
13
|
+
|
|
14
|
+
## Table of Contents
|
|
15
|
+
|
|
16
|
+
- [Install](#install)
|
|
17
|
+
- [Quick Start](#quick-start)
|
|
18
|
+
- [MCP Tools](#mcp-tools)
|
|
19
|
+
- [Memory Types](#memory-types)
|
|
20
|
+
- [Claude Code Hooks](#claude-code-hooks)
|
|
21
|
+
- [Remote Server](#remote-server)
|
|
22
|
+
- [S3 Vault Sync](#s3-vault-sync)
|
|
23
|
+
- [Architecture](#architecture)
|
|
24
|
+
- [Configuration](#configuration)
|
|
25
|
+
- [Development](#development)
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install mnemon-memory
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
With optional LLM support (local 1.7B model for query expansion, contradiction detection, and smarter session extraction):
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install "mnemon-memory[llm]"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
From source:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
git clone https://github.com/cipher813/mnemon.git
|
|
45
|
+
cd mnemon
|
|
46
|
+
pip install -e ".[dev]"
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Quick Start
|
|
50
|
+
|
|
51
|
+
### 1. Configure your client
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# Auto-configure Claude Code (MCP server + memory hooks)
|
|
55
|
+
mnemon setup claude-code
|
|
56
|
+
|
|
57
|
+
# Or configure Cursor
|
|
58
|
+
mnemon setup cursor
|
|
59
|
+
|
|
60
|
+
# Or just the hooks (if MCP is already configured)
|
|
61
|
+
mnemon setup hooks
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 2. Use it
|
|
65
|
+
|
|
66
|
+
Once configured, mnemon works automatically:
|
|
67
|
+
|
|
68
|
+
- **Context surfacing**: relevant memories are injected before each prompt
|
|
69
|
+
- **Session extraction**: decisions, preferences, and observations are saved at session end
|
|
70
|
+
- **Handoff generation**: session summaries maintain continuity across sessions
|
|
71
|
+
|
|
72
|
+
You can also interact with memories directly via MCP tools or CLI:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
mnemon search "deployment architecture"
|
|
76
|
+
mnemon save "DB migration plan" "Migrate from PostgreSQL to DynamoDB in Q3"
|
|
77
|
+
mnemon forget 42
|
|
78
|
+
mnemon status
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## MCP Tools
|
|
82
|
+
|
|
83
|
+
### Retrieval
|
|
84
|
+
|
|
85
|
+
| Tool | Description |
|
|
86
|
+
|------|-------------|
|
|
87
|
+
| `memory_search` | Hybrid BM25 + vector search with composite scoring (relevance + recency + confidence) |
|
|
88
|
+
| `memory_get` | Fetch a specific memory by ID with full content |
|
|
89
|
+
| `memory_timeline` | Recent memories in reverse chronological order |
|
|
90
|
+
| `memory_related` | Find memories related to a given memory via the relationship graph |
|
|
91
|
+
|
|
92
|
+
### Mutation
|
|
93
|
+
|
|
94
|
+
| Tool | Description |
|
|
95
|
+
|------|-------------|
|
|
96
|
+
| `memory_save` | Store a new memory with content type classification and auto-embedding |
|
|
97
|
+
| `memory_pin` | Pin a memory to boost confidence and prevent archival |
|
|
98
|
+
| `memory_forget` | Soft-delete a memory (marked as invalidated, not physically removed) |
|
|
99
|
+
|
|
100
|
+
### Lifecycle
|
|
101
|
+
|
|
102
|
+
| Tool | Description |
|
|
103
|
+
|------|-------------|
|
|
104
|
+
| `memory_status` | Vault health stats — counts by type, vectors, pinned/invalidated |
|
|
105
|
+
| `memory_sweep` | Archive stale memories past their half-life (dry-run by default) |
|
|
106
|
+
| `memory_rebuild` | Re-embed all documents (use after upgrading embedding model) |
|
|
107
|
+
|
|
108
|
+
### Intelligence
|
|
109
|
+
|
|
110
|
+
| Tool | Description |
|
|
111
|
+
|------|-------------|
|
|
112
|
+
| `memory_check_contradictions` | Check a memory for conflicts using vector similarity + LLM classification |
|
|
113
|
+
| `profile_get` | Synthesized user profile from stored preferences and decisions |
|
|
114
|
+
| `profile_update` | Manually add a fact to the user profile |
|
|
115
|
+
|
|
116
|
+
## Memory Types
|
|
117
|
+
|
|
118
|
+
Each memory has a content type that determines its default confidence and decay half-life:
|
|
119
|
+
|
|
120
|
+
| Type | Default Confidence | Half-Life | Use for |
|
|
121
|
+
|------|-------------------|-----------|---------|
|
|
122
|
+
| `decision` | 0.85 | Never | Architectural choices, design decisions |
|
|
123
|
+
| `preference` | 0.80 | Never | User workflow habits, style preferences |
|
|
124
|
+
| `antipattern` | 0.80 | Never | Things that failed, approaches to avoid |
|
|
125
|
+
| `observation` | 0.70 | 90 days | Learned facts, discovered behaviors |
|
|
126
|
+
| `research` | 0.70 | 90 days | Investigation results, findings |
|
|
127
|
+
| `project` | 0.65 | 120 days | Project status, goals, context |
|
|
128
|
+
| `handoff` | 0.60 | 30 days | Session summaries for continuity |
|
|
129
|
+
| `note` | 0.50 | 60 days | General notes, default type |
|
|
130
|
+
|
|
131
|
+
Memories with access activity decay slower — each access extends the effective half-life by 10%, up to 3x the base value.
|
|
132
|
+
|
|
133
|
+
## Claude Code Hooks
|
|
134
|
+
|
|
135
|
+
When configured via `mnemon setup claude-code`, three hooks are installed:
|
|
136
|
+
|
|
137
|
+
| Hook | Event | Timeout | Description |
|
|
138
|
+
|------|-------|---------|-------------|
|
|
139
|
+
| Context surfacing | `UserPromptSubmit` | 8s | Searches vault and injects relevant memories as context |
|
|
140
|
+
| Session extractor | `Stop` | 30s | Extracts decisions, preferences, and observations from the transcript |
|
|
141
|
+
| Handoff generator | `Stop` | 30s | Creates a session summary for the next session |
|
|
142
|
+
|
|
143
|
+
The extractor and handoff generator use LLM-based extraction when `mnemon[llm]` is installed, with regex/heuristic fallback otherwise.
|
|
144
|
+
|
|
145
|
+
## Remote Server
|
|
146
|
+
|
|
147
|
+
For use with Claude.ai web or iOS (any Streamable HTTP MCP client):
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
# Start remote server
|
|
151
|
+
mnemon serve-remote
|
|
152
|
+
|
|
153
|
+
# With authentication (at proxy/infra level)
|
|
154
|
+
MNEMON_TOKEN=your-secret-token mnemon serve-remote
|
|
155
|
+
|
|
156
|
+
# Custom port
|
|
157
|
+
PORT=9000 mnemon serve-remote
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
The remote server exposes the same MCP tools as stdio mode via FastMCP's native Streamable HTTP transport at `http://localhost:8502/mcp`.
|
|
161
|
+
|
|
162
|
+
## S3 Vault Sync
|
|
163
|
+
|
|
164
|
+
Sync your vault across machines via S3:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
# Push local vault to S3
|
|
168
|
+
MNEMON_S3_BUCKET=my-bucket mnemon sync push
|
|
169
|
+
|
|
170
|
+
# Pull vault from S3
|
|
171
|
+
MNEMON_S3_BUCKET=my-bucket mnemon sync pull
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
| Env var | Default | Description |
|
|
175
|
+
|---------|---------|-------------|
|
|
176
|
+
| `MNEMON_S3_BUCKET` | (required) | S3 bucket name |
|
|
177
|
+
| `MNEMON_S3_PREFIX` | `mnemon/vaults` | S3 key prefix |
|
|
178
|
+
| `MNEMON_VAULT_NAME` | `default` | Vault name |
|
|
179
|
+
|
|
180
|
+
Requires the AWS CLI (`aws`) on your PATH with valid credentials.
|
|
181
|
+
|
|
182
|
+
## Architecture
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
~/.mnemon/
|
|
186
|
+
default.sqlite SQLite vault (FTS5 + WAL mode)
|
|
187
|
+
default.vec.npz Companion vector store (numpy, brute-force cosine)
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
- **Storage**: SQLite with FTS5 full-text search, content-addressable deduplication (SHA-256)
|
|
191
|
+
- **Search**: Hybrid BM25 + vector (384d, bge-small-en-v1.5 via FastEmbed) fused with Reciprocal Rank Fusion
|
|
192
|
+
- **Scoring**: Composite score = 0.5 * relevance + 0.25 * recency + 0.25 * confidence
|
|
193
|
+
- **Diversity**: MMR filtering (Jaccard bigram similarity > 0.6 demoted by 50%)
|
|
194
|
+
- **Intelligence** (optional): Local 1.7B LLM (QMD-query-expansion) for query expansion, contradiction detection, session extraction — zero API cost
|
|
195
|
+
- **Transport**: MCP stdio (local) and Streamable HTTP (remote)
|
|
196
|
+
|
|
197
|
+
## Configuration
|
|
198
|
+
|
|
199
|
+
| Env var | Default | Description |
|
|
200
|
+
|---------|---------|-------------|
|
|
201
|
+
| `MNEMON_VAULT_DIR` | `~/.mnemon` | Vault directory |
|
|
202
|
+
| `MNEMON_TOKEN` | (none) | Bearer token for remote server auth |
|
|
203
|
+
| `MNEMON_MODEL_DIR` | `~/.mnemon/models` | Directory for LLM model files |
|
|
204
|
+
| `PORT` | `8502` | Remote server port |
|
|
205
|
+
|
|
206
|
+
## Development
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
# Install with dev dependencies
|
|
210
|
+
pip install -e ".[dev]"
|
|
211
|
+
|
|
212
|
+
# Run tests (253 tests)
|
|
213
|
+
pytest
|
|
214
|
+
|
|
215
|
+
# Run tests with coverage
|
|
216
|
+
pytest --cov=mnemon --cov-report=term-missing
|
|
217
|
+
|
|
218
|
+
# Run a specific test file
|
|
219
|
+
pytest tests/test_store.py -v
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## License
|
|
223
|
+
|
|
224
|
+
MIT
|