hot-memory-mcp 0.4.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.
- hot_memory_mcp-0.4.0/.dockerignore +43 -0
- hot_memory_mcp-0.4.0/.github/workflows/ci.yml +74 -0
- hot_memory_mcp-0.4.0/.github/workflows/publish.yml +22 -0
- hot_memory_mcp-0.4.0/.gitignore +52 -0
- hot_memory_mcp-0.4.0/.pre-commit-config.yaml +30 -0
- hot_memory_mcp-0.4.0/ARCHITECTURE.md +337 -0
- hot_memory_mcp-0.4.0/CHANGELOG.md +159 -0
- hot_memory_mcp-0.4.0/CLAUDE.md +131 -0
- hot_memory_mcp-0.4.0/CONTRIBUTING.md +188 -0
- hot_memory_mcp-0.4.0/Dockerfile +26 -0
- hot_memory_mcp-0.4.0/LICENSE +21 -0
- hot_memory_mcp-0.4.0/PKG-INFO +654 -0
- hot_memory_mcp-0.4.0/README.md +623 -0
- hot_memory_mcp-0.4.0/docs/API.md +813 -0
- hot_memory_mcp-0.4.0/docs/examples/cross-session-continuity.md +123 -0
- hot_memory_mcp-0.4.0/docs/examples/pattern-mining.md +144 -0
- hot_memory_mcp-0.4.0/docs/examples/project-onboarding.md +94 -0
- hot_memory_mcp-0.4.0/hooks/memory-log-response.sh +70 -0
- hot_memory_mcp-0.4.0/pyproject.toml +67 -0
- hot_memory_mcp-0.4.0/src/memory_mcp/__init__.py +3 -0
- hot_memory_mcp-0.4.0/src/memory_mcp/cli.py +613 -0
- hot_memory_mcp-0.4.0/src/memory_mcp/config.py +364 -0
- hot_memory_mcp-0.4.0/src/memory_mcp/embeddings.py +570 -0
- hot_memory_mcp-0.4.0/src/memory_mcp/helpers.py +613 -0
- hot_memory_mcp-0.4.0/src/memory_mcp/logging.py +236 -0
- hot_memory_mcp-0.4.0/src/memory_mcp/metrics.py +30 -0
- hot_memory_mcp-0.4.0/src/memory_mcp/migrations.py +447 -0
- hot_memory_mcp-0.4.0/src/memory_mcp/mining.py +278 -0
- hot_memory_mcp-0.4.0/src/memory_mcp/models.py +358 -0
- hot_memory_mcp-0.4.0/src/memory_mcp/project.py +200 -0
- hot_memory_mcp-0.4.0/src/memory_mcp/responses.py +377 -0
- hot_memory_mcp-0.4.0/src/memory_mcp/server.py +2215 -0
- hot_memory_mcp-0.4.0/src/memory_mcp/storage.py +4427 -0
- hot_memory_mcp-0.4.0/src/memory_mcp/text_parsing.py +39 -0
- hot_memory_mcp-0.4.0/tests/__init__.py +0 -0
- hot_memory_mcp-0.4.0/tests/conftest.py +76 -0
- hot_memory_mcp-0.4.0/tests/test_bug_regressions.py +1104 -0
- hot_memory_mcp-0.4.0/tests/test_cli.py +234 -0
- hot_memory_mcp-0.4.0/tests/test_clustering.py +294 -0
- hot_memory_mcp-0.4.0/tests/test_embeddings.py +496 -0
- hot_memory_mcp-0.4.0/tests/test_mining.py +461 -0
- hot_memory_mcp-0.4.0/tests/test_project.py +376 -0
- hot_memory_mcp-0.4.0/tests/test_server.py +855 -0
- hot_memory_mcp-0.4.0/tests/test_storage.py +2733 -0
- hot_memory_mcp-0.4.0/uv.lock +3327 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Git
|
|
2
|
+
.git/
|
|
3
|
+
.gitignore
|
|
4
|
+
|
|
5
|
+
# Python
|
|
6
|
+
__pycache__/
|
|
7
|
+
*.py[cod]
|
|
8
|
+
*$py.class
|
|
9
|
+
*.so
|
|
10
|
+
.Python
|
|
11
|
+
*.egg-info/
|
|
12
|
+
*.egg
|
|
13
|
+
dist/
|
|
14
|
+
build/
|
|
15
|
+
|
|
16
|
+
# Virtual environments
|
|
17
|
+
.venv/
|
|
18
|
+
venv/
|
|
19
|
+
ENV/
|
|
20
|
+
|
|
21
|
+
# IDE
|
|
22
|
+
.idea/
|
|
23
|
+
.vscode/
|
|
24
|
+
*.swp
|
|
25
|
+
*.swo
|
|
26
|
+
|
|
27
|
+
# Testing
|
|
28
|
+
.pytest_cache/
|
|
29
|
+
.coverage
|
|
30
|
+
htmlcov/
|
|
31
|
+
.tox/
|
|
32
|
+
.nox/
|
|
33
|
+
tests/
|
|
34
|
+
|
|
35
|
+
# Project-specific
|
|
36
|
+
.beads/
|
|
37
|
+
.claude/
|
|
38
|
+
*.db
|
|
39
|
+
*.pdf
|
|
40
|
+
|
|
41
|
+
# Cache
|
|
42
|
+
.mypy_cache/
|
|
43
|
+
.ruff_cache/
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
lint:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
|
|
15
|
+
- name: Install uv
|
|
16
|
+
uses: astral-sh/setup-uv@v5
|
|
17
|
+
with:
|
|
18
|
+
version: "latest"
|
|
19
|
+
|
|
20
|
+
- name: Set up Python
|
|
21
|
+
run: uv python install 3.11
|
|
22
|
+
|
|
23
|
+
- name: Install dependencies
|
|
24
|
+
run: uv sync --group dev
|
|
25
|
+
|
|
26
|
+
- name: Run ruff linter
|
|
27
|
+
run: uv run ruff check src/ tests/
|
|
28
|
+
|
|
29
|
+
- name: Run ruff formatter check
|
|
30
|
+
run: uv run ruff format --check src/ tests/
|
|
31
|
+
|
|
32
|
+
test:
|
|
33
|
+
runs-on: ubuntu-latest
|
|
34
|
+
strategy:
|
|
35
|
+
matrix:
|
|
36
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
37
|
+
|
|
38
|
+
steps:
|
|
39
|
+
- uses: actions/checkout@v4
|
|
40
|
+
|
|
41
|
+
- name: Install uv
|
|
42
|
+
uses: astral-sh/setup-uv@v5
|
|
43
|
+
with:
|
|
44
|
+
version: "latest"
|
|
45
|
+
|
|
46
|
+
- name: Set up Python
|
|
47
|
+
env:
|
|
48
|
+
PYTHON_VERSION: ${{ matrix.python-version }}
|
|
49
|
+
run: uv python install "$PYTHON_VERSION"
|
|
50
|
+
|
|
51
|
+
- name: Install dependencies
|
|
52
|
+
run: uv sync --group dev
|
|
53
|
+
|
|
54
|
+
- name: Run tests
|
|
55
|
+
run: uv run pytest -v --tb=short
|
|
56
|
+
|
|
57
|
+
pre-commit:
|
|
58
|
+
runs-on: ubuntu-latest
|
|
59
|
+
steps:
|
|
60
|
+
- uses: actions/checkout@v4
|
|
61
|
+
|
|
62
|
+
- name: Install uv
|
|
63
|
+
uses: astral-sh/setup-uv@v5
|
|
64
|
+
with:
|
|
65
|
+
version: "latest"
|
|
66
|
+
|
|
67
|
+
- name: Set up Python
|
|
68
|
+
run: uv python install 3.11
|
|
69
|
+
|
|
70
|
+
- name: Install pre-commit
|
|
71
|
+
run: uv tool install pre-commit
|
|
72
|
+
|
|
73
|
+
- name: Run pre-commit
|
|
74
|
+
run: uvx pre-commit run --all-files
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
permissions:
|
|
11
|
+
id-token: write # Required for trusted publishing
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
|
|
15
|
+
- name: Install uv
|
|
16
|
+
uses: astral-sh/setup-uv@v4
|
|
17
|
+
|
|
18
|
+
- name: Build package
|
|
19
|
+
run: uv build
|
|
20
|
+
|
|
21
|
+
- name: Publish to PyPI
|
|
22
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
build/
|
|
8
|
+
develop-eggs/
|
|
9
|
+
dist/
|
|
10
|
+
downloads/
|
|
11
|
+
eggs/
|
|
12
|
+
.eggs/
|
|
13
|
+
lib/
|
|
14
|
+
lib64/
|
|
15
|
+
parts/
|
|
16
|
+
sdist/
|
|
17
|
+
var/
|
|
18
|
+
wheels/
|
|
19
|
+
*.egg-info/
|
|
20
|
+
.installed.cfg
|
|
21
|
+
*.egg
|
|
22
|
+
|
|
23
|
+
# Virtual environments
|
|
24
|
+
.venv/
|
|
25
|
+
venv/
|
|
26
|
+
ENV/
|
|
27
|
+
|
|
28
|
+
# IDE
|
|
29
|
+
.idea/
|
|
30
|
+
.vscode/
|
|
31
|
+
*.swp
|
|
32
|
+
*.swo
|
|
33
|
+
|
|
34
|
+
# Testing
|
|
35
|
+
.pytest_cache/
|
|
36
|
+
.coverage
|
|
37
|
+
htmlcov/
|
|
38
|
+
.tox/
|
|
39
|
+
.nox/
|
|
40
|
+
|
|
41
|
+
# Database
|
|
42
|
+
*.db
|
|
43
|
+
|
|
44
|
+
# OS
|
|
45
|
+
.DS_Store
|
|
46
|
+
Thumbs.db
|
|
47
|
+
|
|
48
|
+
# Project-specific
|
|
49
|
+
.beads/
|
|
50
|
+
|
|
51
|
+
# Claude local settings
|
|
52
|
+
.claude/settings.local.json
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
3
|
+
rev: v5.0.0
|
|
4
|
+
hooks:
|
|
5
|
+
- id: trailing-whitespace
|
|
6
|
+
- id: end-of-file-fixer
|
|
7
|
+
- id: check-yaml
|
|
8
|
+
- id: check-added-large-files
|
|
9
|
+
args: ['--maxkb=500']
|
|
10
|
+
- id: check-merge-conflict
|
|
11
|
+
- id: debug-statements
|
|
12
|
+
|
|
13
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
14
|
+
rev: v0.8.6
|
|
15
|
+
hooks:
|
|
16
|
+
# Linter
|
|
17
|
+
- id: ruff
|
|
18
|
+
args: [--fix, --exit-non-zero-on-fix]
|
|
19
|
+
# Formatter (replaces black)
|
|
20
|
+
- id: ruff-format
|
|
21
|
+
|
|
22
|
+
- repo: https://github.com/pre-commit/mirrors-mypy
|
|
23
|
+
rev: v1.14.1
|
|
24
|
+
hooks:
|
|
25
|
+
- id: mypy
|
|
26
|
+
additional_dependencies:
|
|
27
|
+
- pydantic>=2.0
|
|
28
|
+
- pydantic-settings>=2.0
|
|
29
|
+
args: [--ignore-missing-imports, --no-strict-optional]
|
|
30
|
+
files: ^src/
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
# Memory MCP Architecture
|
|
2
|
+
|
|
3
|
+
This document describes the design decisions, architecture patterns, and rationale behind Memory MCP.
|
|
4
|
+
|
|
5
|
+
## Core Design Principle
|
|
6
|
+
|
|
7
|
+
**The Engram Insight**: Frequently-used patterns should be instantly available, not searched for every time.
|
|
8
|
+
|
|
9
|
+
This principle drives every architectural decision. We optimize for the common case where a small set of project knowledge is accessed repeatedly.
|
|
10
|
+
|
|
11
|
+
## Two-Tier Memory Architecture
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
15
|
+
│ Claude / LLM │
|
|
16
|
+
└─────────────────────────────────────────────────────────────┘
|
|
17
|
+
│ │
|
|
18
|
+
▼ (auto-injected) ▼ (tool call)
|
|
19
|
+
┌───────────────────┐ ┌────────────────────────┐
|
|
20
|
+
│ Hot Cache │ │ Cold Storage │
|
|
21
|
+
│ MCP Resource │ │ Vector Database │
|
|
22
|
+
│ │ │ │
|
|
23
|
+
│ - 20 items max │◄────────────►│ - Unlimited capacity │
|
|
24
|
+
│ - Instant recall │ promotion │ - Semantic search │
|
|
25
|
+
│ - Pinnable │ / demotion │ - ~50ms lookup │
|
|
26
|
+
└───────────────────┘ └────────────────────────┘
|
|
27
|
+
▲ ▲
|
|
28
|
+
│ │
|
|
29
|
+
└──────────── Mining Pipeline ───────┘
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Why Two Tiers?
|
|
33
|
+
|
|
34
|
+
| Problem | Solution |
|
|
35
|
+
|---------|----------|
|
|
36
|
+
| Tool calls add latency | Hot cache injected via MCP resource (0ms) |
|
|
37
|
+
| Large context wastes tokens | Only 20 high-value items in hot cache |
|
|
38
|
+
| Manual memory management is tedious | Automatic promotion/demotion based on access |
|
|
39
|
+
|
|
40
|
+
### Hot Cache
|
|
41
|
+
|
|
42
|
+
- **Implementation**: MCP resource at `memory://hot-cache`
|
|
43
|
+
- **Capacity**: 20 items (configurable via `HOT_CACHE_MAX_ITEMS`)
|
|
44
|
+
- **Eviction**: LRU with composite scoring (access count + recency)
|
|
45
|
+
- **Pinning**: Items can be pinned to prevent eviction
|
|
46
|
+
|
|
47
|
+
**Scoring Formula**:
|
|
48
|
+
```
|
|
49
|
+
hot_score = (access_weight × access_count) + (recency_weight × recency_boost)
|
|
50
|
+
recency_boost = 0.5^(days_since_access / halflife_days)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Cold Storage
|
|
54
|
+
|
|
55
|
+
- **Implementation**: SQLite with sqlite-vec extension
|
|
56
|
+
- **Vector Dimension**: 384 (all-MiniLM-L6-v2 default)
|
|
57
|
+
- **Search**: Cosine similarity with composite ranking
|
|
58
|
+
|
|
59
|
+
**Ranking Formula**:
|
|
60
|
+
```
|
|
61
|
+
composite_score = (similarity_weight × similarity) +
|
|
62
|
+
(recency_weight × recency_score) +
|
|
63
|
+
(access_weight × normalized_access)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Data Flow
|
|
67
|
+
|
|
68
|
+
```mermaid
|
|
69
|
+
graph TB
|
|
70
|
+
subgraph Input["Input Layer"]
|
|
71
|
+
direction LR
|
|
72
|
+
R[remember tool]
|
|
73
|
+
L[log_output tool]
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
subgraph Process["Processing"]
|
|
77
|
+
direction TB
|
|
78
|
+
subgraph Store["Store Path"]
|
|
79
|
+
S[Store Memory] --> E[Embed]
|
|
80
|
+
end
|
|
81
|
+
subgraph Mine["Mining Path"]
|
|
82
|
+
O[Output Log] --> MP[Extract Patterns]
|
|
83
|
+
MP --> P{Confidence?}
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
subgraph Persist["Persistence Layer"]
|
|
88
|
+
direction LR
|
|
89
|
+
V[(Vectors)]
|
|
90
|
+
M[(Metadata)]
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
subgraph Retrieve["Retrieval"]
|
|
94
|
+
direction TB
|
|
95
|
+
Q[recall tool] --> VS[Vector Search]
|
|
96
|
+
VS --> RK[Composite Rank]
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
subgraph Cache["Hot Cache Lifecycle"]
|
|
100
|
+
direction LR
|
|
101
|
+
PR[Promote] --> H[Hot Cache]
|
|
102
|
+
H --> DE[Demote]
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
R --> S
|
|
106
|
+
L --> O
|
|
107
|
+
E --> V & M
|
|
108
|
+
P -->|≥0.8| S
|
|
109
|
+
P -->|<0.8| A[approve_candidate]
|
|
110
|
+
A --> S
|
|
111
|
+
RK --> V & M
|
|
112
|
+
RK -->|access 3+| PR
|
|
113
|
+
DE -->|14 days stale| V
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Module Structure
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
src/memory_mcp/
|
|
120
|
+
├── server.py # MCP tools and resources - the API layer
|
|
121
|
+
├── storage.py # SQLite operations, vector search, caching logic
|
|
122
|
+
├── responses.py # Pydantic response models for MCP tools
|
|
123
|
+
├── models.py # Enums and dataclasses (domain models)
|
|
124
|
+
├── migrations.py # Database schema and version migrations
|
|
125
|
+
├── mining.py # Pattern extraction from outputs
|
|
126
|
+
├── config.py # Settings with environment variable loading
|
|
127
|
+
├── cli.py # CLI commands for hooks and administration
|
|
128
|
+
├── embeddings.py # Embedding providers (sentence-transformers, MLX)
|
|
129
|
+
├── text_parsing.py # Content chunking for seeding
|
|
130
|
+
├── logging.py # Structured logging configuration
|
|
131
|
+
└── metrics.py # Metrics collection and observability
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Module Dependencies
|
|
135
|
+
|
|
136
|
+
```mermaid
|
|
137
|
+
graph TB
|
|
138
|
+
subgraph API["API Layer"]
|
|
139
|
+
direction LR
|
|
140
|
+
server[server.py]
|
|
141
|
+
cli[cli.py]
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
subgraph Core["Core Layer"]
|
|
145
|
+
direction LR
|
|
146
|
+
storage[storage.py]
|
|
147
|
+
mining[mining.py]
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
subgraph Support["Support Layer"]
|
|
151
|
+
direction LR
|
|
152
|
+
helpers[helpers.py]
|
|
153
|
+
responses[responses.py]
|
|
154
|
+
embeddings[embeddings.py]
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
subgraph Foundation["Foundation Layer"]
|
|
158
|
+
direction LR
|
|
159
|
+
models[models.py]
|
|
160
|
+
config[config.py]
|
|
161
|
+
migrations[migrations.py]
|
|
162
|
+
logging[logging.py]
|
|
163
|
+
metrics[metrics.py]
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
server --> storage & helpers & responses & logging
|
|
167
|
+
cli --> storage & config
|
|
168
|
+
storage --> models & migrations & embeddings & config
|
|
169
|
+
mining --> storage
|
|
170
|
+
helpers --> models & responses
|
|
171
|
+
responses --> models
|
|
172
|
+
metrics --> logging
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Layer Responsibilities
|
|
176
|
+
|
|
177
|
+
| Module | Responsibility |
|
|
178
|
+
|--------|----------------|
|
|
179
|
+
| `server.py` | MCP tools/resources, request validation, response construction |
|
|
180
|
+
| `storage.py` | Data persistence, vector operations, business logic |
|
|
181
|
+
| `responses.py` | Pydantic models for tool return types |
|
|
182
|
+
| `models.py` | Domain enums (MemoryType, TrustReason) and dataclasses (Memory, Session) |
|
|
183
|
+
| `migrations.py` | Database schema definition and version migrations |
|
|
184
|
+
| `mining.py` | Pattern extraction algorithms |
|
|
185
|
+
| `embeddings.py` | Embedding abstraction (MLX on Apple Silicon, else ST) |
|
|
186
|
+
| `logging.py` | Loguru configuration, stderr output for MCP compatibility |
|
|
187
|
+
| `metrics.py` | Counters, gauges, and metric recording helpers |
|
|
188
|
+
|
|
189
|
+
### Why This Structure?
|
|
190
|
+
|
|
191
|
+
1. **Separated concerns**: Models, responses, and migrations extracted for clarity
|
|
192
|
+
2. **Thin server layer**: Adapts storage operations to MCP protocol
|
|
193
|
+
3. **Swappable embeddings**: Backend detection allows hardware optimization
|
|
194
|
+
4. **Backwards-compatible imports**: Re-exports preserve existing import paths
|
|
195
|
+
|
|
196
|
+
## Key Design Decisions
|
|
197
|
+
|
|
198
|
+
### 1. SQLite + sqlite-vec Over Vector Databases
|
|
199
|
+
|
|
200
|
+
**Chose**: SQLite with sqlite-vec extension
|
|
201
|
+
|
|
202
|
+
**Alternatives considered**: Pinecone, Weaviate, Milvus, Chroma
|
|
203
|
+
|
|
204
|
+
**Rationale**:
|
|
205
|
+
- **Local-first**: No network dependency, instant startup
|
|
206
|
+
- **Simplicity**: Single file database, easy backup/restore
|
|
207
|
+
- **Scale**: Handles thousands of memories efficiently
|
|
208
|
+
- **Portability**: Works everywhere Python works
|
|
209
|
+
|
|
210
|
+
**Trade-off**: Limited to single-user, single-machine scenarios
|
|
211
|
+
|
|
212
|
+
### 2. Sentence Transformers for Embeddings
|
|
213
|
+
|
|
214
|
+
**Chose**: all-MiniLM-L6-v2 (384 dimensions)
|
|
215
|
+
|
|
216
|
+
**Alternatives considered**: OpenAI embeddings, larger BERT models
|
|
217
|
+
|
|
218
|
+
**Rationale**:
|
|
219
|
+
- **Local**: No API calls, no costs, offline capable
|
|
220
|
+
- **Fast**: ~50ms per embedding on CPU
|
|
221
|
+
- **Small**: 90MB model, 384 dimensions
|
|
222
|
+
- **Quality**: Good semantic similarity for short text
|
|
223
|
+
|
|
224
|
+
**Trade-off**: Less powerful than larger models, but sufficient for memory retrieval
|
|
225
|
+
|
|
226
|
+
### 3. Automatic Promotion/Demotion
|
|
227
|
+
|
|
228
|
+
**Chose**: Frequency-based with configurable thresholds
|
|
229
|
+
|
|
230
|
+
**Design**:
|
|
231
|
+
- Promote after 3 accesses (configurable)
|
|
232
|
+
- Demote after 14 days without access (configurable)
|
|
233
|
+
- Evict lowest-scored when cache full
|
|
234
|
+
|
|
235
|
+
**Rationale**: Reduces manual intervention while ensuring hot cache reflects actual usage
|
|
236
|
+
|
|
237
|
+
### 4. Pattern Mining Pipeline
|
|
238
|
+
|
|
239
|
+
**Chose**: Regex-based extraction with occurrence counting
|
|
240
|
+
|
|
241
|
+
**Extracted patterns**:
|
|
242
|
+
- Python imports
|
|
243
|
+
- Shell commands (npm, git, docker, etc.)
|
|
244
|
+
- Project facts ("This project uses X")
|
|
245
|
+
- Code blocks from markdown
|
|
246
|
+
|
|
247
|
+
**Auto-approval**: Patterns with confidence ≥ 0.8 and occurrences ≥ 3 are automatically promoted
|
|
248
|
+
|
|
249
|
+
**Rationale**: Low overhead, high precision for common patterns
|
|
250
|
+
|
|
251
|
+
### 5. Trust Score System
|
|
252
|
+
|
|
253
|
+
**Chose**: Decay-based trust with explicit validation/invalidation
|
|
254
|
+
|
|
255
|
+
**Design**:
|
|
256
|
+
- Manual memories start at 1.0 trust
|
|
257
|
+
- Mined memories start at 0.7 trust
|
|
258
|
+
- Trust decays over time (type-specific half-lives)
|
|
259
|
+
- Explicit validation/invalidation adjusts trust
|
|
260
|
+
|
|
261
|
+
**Rationale**: Older information naturally becomes less reliable; explicit feedback accelerates correction
|
|
262
|
+
|
|
263
|
+
### 6. Knowledge Graph
|
|
264
|
+
|
|
265
|
+
**Chose**: Simple typed relationships stored in SQLite
|
|
266
|
+
|
|
267
|
+
**Relation types**:
|
|
268
|
+
- `relates_to`: General association
|
|
269
|
+
- `depends_on`: Prerequisite
|
|
270
|
+
- `supersedes`: Replaces older info
|
|
271
|
+
- `refines`: More specific version
|
|
272
|
+
- `contradicts`: Conflicting information
|
|
273
|
+
- `elaborates`: More detail
|
|
274
|
+
|
|
275
|
+
**Rationale**: Enables context expansion during recall without complex graph database
|
|
276
|
+
|
|
277
|
+
### 7. Predictive Hot Cache
|
|
278
|
+
|
|
279
|
+
**Chose**: Markov chain of access sequences
|
|
280
|
+
|
|
281
|
+
**Design**:
|
|
282
|
+
- Record (memory_A, memory_B) when accessed together
|
|
283
|
+
- Build transition probabilities
|
|
284
|
+
- Pre-warm cache with predicted next memories after each recall
|
|
285
|
+
|
|
286
|
+
**Rationale**: Learns actual usage patterns without explicit configuration
|
|
287
|
+
|
|
288
|
+
## Configuration Philosophy
|
|
289
|
+
|
|
290
|
+
**Principle**: Maximum value with minimal configuration
|
|
291
|
+
|
|
292
|
+
Default settings are optimized for immediate value:
|
|
293
|
+
- Predictive cache: Enabled by default
|
|
294
|
+
- Auto-approve mining: Enabled with conservative thresholds
|
|
295
|
+
- Auto-promote/demote: Enabled
|
|
296
|
+
|
|
297
|
+
Power users can tune via environment variables, but sensible defaults mean most users never need to.
|
|
298
|
+
|
|
299
|
+
## Error Handling Strategy
|
|
300
|
+
|
|
301
|
+
1. **Graceful degradation**: If embedding fails, memory still stored without vector
|
|
302
|
+
2. **Idempotent operations**: Duplicate stores merge tags and increment access
|
|
303
|
+
3. **Audit logging**: Destructive operations logged for recovery
|
|
304
|
+
4. **No silent failures**: Errors returned in response, not swallowed
|
|
305
|
+
|
|
306
|
+
## Performance Characteristics
|
|
307
|
+
|
|
308
|
+
| Operation | Typical Latency | Notes |
|
|
309
|
+
|-----------|-----------------|-------|
|
|
310
|
+
| Hot cache read | 0ms | Auto-injected by MCP |
|
|
311
|
+
| remember() | 50-100ms | Embedding dominates |
|
|
312
|
+
| recall() | 50-150ms | Vector search + ranking |
|
|
313
|
+
| Mining (24h) | 1-5s | Depends on log volume |
|
|
314
|
+
| Bootstrap | 2-10s | Depends on file count |
|
|
315
|
+
|
|
316
|
+
## Future Considerations
|
|
317
|
+
|
|
318
|
+
### Considered but Deferred
|
|
319
|
+
|
|
320
|
+
1. **Multi-user support**: Would require auth, permissions, conflict resolution
|
|
321
|
+
2. **Distributed storage**: Current single-file model sufficient for local use
|
|
322
|
+
3. **Custom embedding models**: Current model adequate; adding complexity not justified
|
|
323
|
+
4. **LLM-based extraction**: Regex patterns sufficient; LLM adds latency and cost
|
|
324
|
+
|
|
325
|
+
### Potential Enhancements
|
|
326
|
+
|
|
327
|
+
1. **Semantic deduplication**: Merge near-duplicate memories automatically
|
|
328
|
+
2. **Memory aging**: Archive very old, unused memories
|
|
329
|
+
3. **Cross-project sharing**: Share patterns across projects
|
|
330
|
+
4. **Embedding model migration**: Tools to rebuild vectors when changing models
|
|
331
|
+
|
|
332
|
+
## References
|
|
333
|
+
|
|
334
|
+
- [Engram](https://github.com/AnswerDotAI/engram) - Inspiration for hot cache concept
|
|
335
|
+
- [sqlite-vec](https://github.com/asg017/sqlite-vec) - Vector search extension
|
|
336
|
+
- [FastMCP](https://github.com/jlowin/fastmcp) - MCP server framework
|
|
337
|
+
- [sentence-transformers](https://www.sbert.net/) - Embedding models
|