mcp-super-memory 0.4.8 → 0.5.1
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.
- package/README.md +107 -35
- package/dist/embedding.d.ts +13 -1
- package/dist/embedding.d.ts.map +1 -1
- package/dist/embedding.js +125 -12
- package/dist/embedding.js.map +1 -1
- package/dist/memoryGraph.d.ts +11 -1
- package/dist/memoryGraph.d.ts.map +1 -1
- package/dist/memoryGraph.js +320 -60
- package/dist/memoryGraph.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +11 -8
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# mcp-super-memory
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/mcp-super-memory)
|
|
4
|
+
[](https://nodejs.org/)
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
6
6
|
|
|
7
7
|
**N:M associative memory graph for LLM agents — delivered as an MCP server.**
|
|
@@ -63,7 +63,9 @@ Search `"Newton"` → matches `[Newton]`, `[apple]` keys (1-hop) → follows sha
|
|
|
63
63
|
| Time decay | ✅ depth-weighted | ❌ | ❌ | ❌ |
|
|
64
64
|
| Key types | ✅ concept/name/proper_noun | ❌ | ❌ | ❌ |
|
|
65
65
|
| Key merge (IDF) | ✅ | ❌ | ❌ | ❌ |
|
|
66
|
-
|
|
|
66
|
+
| Hybrid retrieval (BM25 + dense + RRF) | ✅ | ❌ | partial | ❌ |
|
|
67
|
+
| Dual-path dense recall | ✅ key + content | ❌ | ❌ | ❌ |
|
|
68
|
+
| Hebbian link learning | ✅ | ❌ | ❌ | ❌ |
|
|
67
69
|
|
|
68
70
|
### Depth System
|
|
69
71
|
|
|
@@ -83,7 +85,7 @@ Not all keys should behave the same. Names shouldn't match semantically — "동
|
|
|
83
85
|
|
|
84
86
|
| Type | Matching | Use Case |
|
|
85
87
|
|------|----------|----------|
|
|
86
|
-
| `concept` (default) | Embedding similarity ≥ 0.
|
|
88
|
+
| `concept` (default) | Embedding similarity ≥ threshold (0.28 OpenAI / 0.60 local) | Topics, categories, attributes |
|
|
87
89
|
| `name` | Exact match only | Person names |
|
|
88
90
|
| `proper_noun` | Exact match only | Brands, places |
|
|
89
91
|
|
|
@@ -108,14 +110,26 @@ Add key "파이썬" → finds existing "Python" (similarity 0.87 > threshold 0.
|
|
|
108
110
|
|
|
109
111
|
Prevents key space fragmentation. Same concept across languages or phrasing stays unified.
|
|
110
112
|
|
|
111
|
-
###
|
|
113
|
+
### Hybrid Retrieval (BM25 + dense, RRF-fused)
|
|
112
114
|
|
|
113
|
-
Recall
|
|
115
|
+
Recall is not a single similarity scan. Three signals run in parallel and are fused with **Reciprocal Rank Fusion** (`RRF_K = 60`):
|
|
114
116
|
|
|
115
|
-
- **
|
|
116
|
-
- **Path
|
|
117
|
+
- **BM25 (sparse):** lexical full-text search over memory content (MiniSearch, fuzzy + prefix). Catches exact terms, names, and rare tokens that embeddings blur.
|
|
118
|
+
- **Dense Path A (key matching):** query embedding → match keys → follow links → memories. Score = `keySim × IDF × linkWeight`, summed across all matching keys.
|
|
119
|
+
- **Dense Path B (content matching):** query embedding → directly compare against memory content embeddings. Finds memories even when they weren't tagged with the right keys.
|
|
117
120
|
|
|
118
|
-
|
|
121
|
+
Sparse and dense rank lists are merged by RRF, then modulated by depth and time before 2-hop expansion. Combining lexical and semantic signals is more robust than either alone.
|
|
122
|
+
|
|
123
|
+
### Hebbian Link Learning
|
|
124
|
+
|
|
125
|
+
Recall is a **write**, not just a read. Every recall reshapes the graph:
|
|
126
|
+
|
|
127
|
+
- Links whose key **actually matched the query** and led to a **returned** memory are **reinforced** (`+0.1`, capped at `3.0`).
|
|
128
|
+
- Links explored (matched key) but whose memory was **not returned** are **decayed** (`−0.005`, floored at `0.1`).
|
|
129
|
+
|
|
130
|
+
Reinforcement is scoped to the keys that *fired* for this query — not to every key of a returned memory. This is the literal Hebbian rule ("fire together, wire together") and it matters: reinforcing a returned memory's unrelated keys would let a stray association grow every time that memory surfaced for a *different* key, slowly polluting the graph. Weights are clamped to `[0.1, 3.0]`, so a hot memory's pull is bounded and the graph can recover from a bad reinforcement via subsequent decay.
|
|
131
|
+
|
|
132
|
+
Link weights feed directly back into scoring (`keySim × IDF × linkWeight`), so connections that repeatedly co-fire grow stronger and stale ones fade — the graph learns which associations actually matter from access patterns.
|
|
119
133
|
|
|
120
134
|
---
|
|
121
135
|
|
|
@@ -138,29 +152,62 @@ Scores from both paths are summed. This ensures memories are found even when the
|
|
|
138
152
|
└─────────────────────────────────────────────────────────┘
|
|
139
153
|
```
|
|
140
154
|
|
|
141
|
-
**Recall algorithm (2-hop):**
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
155
|
+
**Recall algorithm (hybrid, 2-hop):**
|
|
156
|
+
|
|
157
|
+
Three retrieval signals run in parallel, then get fused and expanded:
|
|
158
|
+
|
|
159
|
+
1. **BM25 (sparse):** lexical search over memory content (MiniSearch, fuzzy `0.2` + prefix). Keep top 50.
|
|
160
|
+
2. **Dense Path A (keys):** embed query → match keys (concept: cosine ≥ threshold; name/proper_noun: substring match → score `1.0`) → take top 10 keys → follow links. Score = `keySim × IDF × linkWeight`, summed across matching keys.
|
|
161
|
+
3. **Dense Path B (content):** compare query embedding directly against memory content embeddings (cosine ≥ threshold).
|
|
162
|
+
4. **RRF fusion:** merge the BM25 and dense rank lists via `score += 1 / (RRF_K + rank + 1)` (`RRF_K = 60`).
|
|
163
|
+
5. **Depth & time modulation:** `score × (0.9 + depth × 0.1) × timeFactor`, where `timeFactor` is a depth-weighted 30-day half-life decay (deep memories decay slower).
|
|
164
|
+
6. **2-hop expansion:** for each fused memory, follow *its* keys to associated memories (`× HOP_DECAY(0.3) × IDF × linkWeight`) and traverse explicit `related_to` links (bidirectional, `× HOP_DECAY`).
|
|
165
|
+
7. **Hebbian update:** reinforce matched-key links of returned memories (`+0.1`), decay explored-but-unreturned links (`−0.005`).
|
|
166
|
+
8. Return ranked results with `hop` field (`1` = direct, `2` = associative).
|
|
167
|
+
|
|
168
|
+
### Similarity thresholds (calibrated per embedding model)
|
|
169
|
+
|
|
170
|
+
Embedding backends have very different cosine distributions, so a single threshold set cannot serve all of them. The thresholds below are calibrated per model (`getThresholdProfile()` in `src/embedding.ts`):
|
|
171
|
+
|
|
172
|
+
| Threshold | OpenAI | Local BGE (en) | Local e5 (multilingual) |
|
|
173
|
+
|-----------|--------|----------------|--------------------------|
|
|
174
|
+
| Key recall (query↔key cosine) | 0.28 | 0.60 | 0.85 |
|
|
175
|
+
| Content recall (query↔content cosine) | 0.28 | 0.50 | 0.80 |
|
|
176
|
+
| Key auto-link | 0.50 | 0.60 | 0.93 |
|
|
177
|
+
| Key merge | 0.85 | 0.85 | 0.97 |
|
|
178
|
+
| Memory dedup | 0.90 | 0.90 | 0.985 |
|
|
179
|
+
|
|
180
|
+
**Why e5 differs so much:** multilingual-e5 packs embeddings into a narrow high-cosine band (~0.86–0.99). Same-word query↔key pairs (asymmetric `query:`/`passage:` prefixes) still separate cleanly (~0.89 vs ≤0.82), but key↔key and content↔content do **not** — distinct facts like *"A uses Postgres"* and *"B uses Mongo"* sit at ~0.96, dangerously close to true paraphrases (~0.99). Hence e5's merge/dedup/auto-link thresholds are pushed high to avoid silently collapsing distinct memories.
|
|
181
|
+
|
|
182
|
+
**Drift escape hatch:** if you switch models or your data's character drifts, override any threshold without code changes:
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
SUPER_MEMORY_KEY_RECALL=0.82
|
|
186
|
+
SUPER_MEMORY_MEMORY_DEDUP=0.99
|
|
187
|
+
# also: _KEY_MERGE, _KEY_AUTOLINK, _CONTENT_RECALL (values in [0,1])
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
An uncalibrated `LOCAL_EMBEDDING_MODEL` falls back to the BGE profile **and logs a warning** so the miscalibration is never silent.
|
|
191
|
+
|
|
192
|
+
> **Multilingual note:** cross-lingual *content* matching has a same-language bias (a Korean query scores Korean memories higher regardless of meaning). The reliable cross-lingual path is the **key graph** — tag memories with keys in multiple languages (e.g. `["딸기", "strawberry"]`) so recall hits the key exactly instead of relying on biased content similarity.
|
|
148
193
|
|
|
149
194
|
---
|
|
150
195
|
|
|
151
196
|
## MCP Tools
|
|
152
197
|
|
|
153
|
-
The memory system exposes
|
|
198
|
+
The memory system exposes 10 tools via MCP:
|
|
154
199
|
|
|
155
200
|
| Tool | Description |
|
|
156
|
-
|
|
157
|
-
| `recall(query, top_k)` |
|
|
158
|
-
| `remember(content, keys, key_types?)` | Save memory with key concepts and optional type annotations |
|
|
159
|
-
| `correct(memory_id, content, keys?)` | Versioned update — old memory preserved but weakened |
|
|
201
|
+
| --- | --- |
|
|
202
|
+
| `recall(query, top_k, namespace?, expand?)` | Hybrid search (BM25 + dense key/content, RRF-fused) with 2-hop associative traversal |
|
|
203
|
+
| `remember(content, keys, key_types?, namespace?, ttl_seconds?, related_to?)` | Save memory with key concepts and optional type annotations |
|
|
204
|
+
| `correct(memory_id, content, keys?, key_types?, related_to?)` | Versioned update — old memory preserved but weakened |
|
|
160
205
|
| `related(memory_id)` | Find memories sharing keys (associative exploration) |
|
|
161
206
|
| `forget(memory_id)` | Permanently delete |
|
|
162
207
|
| `get_conversation(session_id, turn?)` | Load original conversation turns |
|
|
163
|
-
| `list_memories()` | List all stored memories with keys, depth, access count |
|
|
208
|
+
| `list_memories(namespace?)` | List all stored memories with keys, depth, access count |
|
|
209
|
+
| `remember_batch(items)` | Save multiple memories in one call |
|
|
210
|
+
| `cleanup_expired()` | Delete memories whose TTL has expired |
|
|
164
211
|
| `memory_stats()` | Get current key/memory/link counts |
|
|
165
212
|
|
|
166
213
|
A system prompt template is also available via `memory_system_prompt` MCP prompt — include it to instruct the agent to recall silently, use diverse keys, and never mention the memory system to users.
|
|
@@ -178,8 +225,8 @@ Add to `claude_desktop_config.json`:
|
|
|
178
225
|
{
|
|
179
226
|
"mcpServers": {
|
|
180
227
|
"mcp-super-memory": {
|
|
181
|
-
"command": "
|
|
182
|
-
"args": ["mcp-super-memory"],
|
|
228
|
+
"command": "npx",
|
|
229
|
+
"args": ["-y", "mcp-super-memory"],
|
|
183
230
|
"env": {
|
|
184
231
|
"OPENAI_API_KEY": "your-openai-api-key"
|
|
185
232
|
}
|
|
@@ -193,8 +240,8 @@ Add to `claude_desktop_config.json`:
|
|
|
193
240
|
{
|
|
194
241
|
"mcpServers": {
|
|
195
242
|
"mcp-super-memory": {
|
|
196
|
-
"command": "
|
|
197
|
-
"args": ["mcp-super-memory
|
|
243
|
+
"command": "npx",
|
|
244
|
+
"args": ["-y", "mcp-super-memory"],
|
|
198
245
|
"env": {
|
|
199
246
|
"EMBEDDING_BACKEND": "local"
|
|
200
247
|
}
|
|
@@ -207,10 +254,10 @@ Add to `claude_desktop_config.json`:
|
|
|
207
254
|
|
|
208
255
|
```bash
|
|
209
256
|
# OpenAI embeddings
|
|
210
|
-
claude mcp add mcp-super-memory -e OPENAI_API_KEY=your-openai-api-key --
|
|
257
|
+
claude mcp add mcp-super-memory -e OPENAI_API_KEY=your-openai-api-key -- npx -y mcp-super-memory
|
|
211
258
|
|
|
212
259
|
# Local embeddings (no API key required)
|
|
213
|
-
claude mcp add mcp-super-memory -e EMBEDDING_BACKEND=local --
|
|
260
|
+
claude mcp add mcp-super-memory -e EMBEDDING_BACKEND=local -- npx -y mcp-super-memory
|
|
214
261
|
```
|
|
215
262
|
|
|
216
263
|
### Manual / Development
|
|
@@ -218,6 +265,7 @@ claude mcp add mcp-super-memory -e EMBEDDING_BACKEND=local -- uvx "mcp-super-mem
|
|
|
218
265
|
```bash
|
|
219
266
|
git clone https://github.com/donggyun112/mcp-super-memory
|
|
220
267
|
cd super-memory
|
|
268
|
+
pnpm install
|
|
221
269
|
```
|
|
222
270
|
|
|
223
271
|
Create `.env`:
|
|
@@ -229,19 +277,25 @@ OPENAI_EMBEDDING_MODEL=text-embedding-3-small
|
|
|
229
277
|
Or use local embeddings (no API key required):
|
|
230
278
|
```
|
|
231
279
|
EMBEDDING_BACKEND=local
|
|
232
|
-
LOCAL_EMBEDDING_MODEL=
|
|
280
|
+
LOCAL_EMBEDDING_MODEL=fast-multilingual-e5-large # default; best fit for Korean/multilingual keys
|
|
233
281
|
```
|
|
234
282
|
|
|
235
|
-
|
|
283
|
+
If `OPENAI_API_KEY` is not set and `EMBEDDING_BACKEND` is unset, the server automatically uses the local `fastembed` backend.
|
|
284
|
+
For English-only use or lower local resource usage, set `LOCAL_EMBEDDING_MODEL=fast-bge-base-en-v1.5` or `fast-bge-small-en-v1.5`.
|
|
285
|
+
|
|
286
|
+
> **Switching backends is safe.** If you change the embedding backend/model, on next startup the graph **auto-migrates** — every key and memory is re-embedded with the new backend while content, links, depth, and access history are preserved (a `graph.json.bak.<dim>d` backup is written first). Disable with `SUPER_MEMORY_AUTO_MIGRATE=false`. Re-embedding via OpenAI incurs one-time API cost proportional to your memory count.
|
|
236
287
|
|
|
237
288
|
```bash
|
|
238
|
-
|
|
239
|
-
|
|
289
|
+
pnpm dev
|
|
290
|
+
# or:
|
|
291
|
+
pnpm build
|
|
292
|
+
pnpm start
|
|
240
293
|
```
|
|
241
294
|
|
|
242
295
|
**Requirements:**
|
|
243
|
-
-
|
|
244
|
-
-
|
|
296
|
+
- Node.js 20+
|
|
297
|
+
- pnpm for local development
|
|
298
|
+
- OpenAI API key for OpenAI embeddings, or `fastembed` for local embeddings
|
|
245
299
|
|
|
246
300
|
---
|
|
247
301
|
|
|
@@ -250,12 +304,14 @@ uv run mcp-super-memory
|
|
|
250
304
|
All data is local. No external database required.
|
|
251
305
|
|
|
252
306
|
```
|
|
253
|
-
|
|
307
|
+
~/.super-memory/
|
|
254
308
|
├── graph.json # keys, memories, links
|
|
255
309
|
└── conversations/
|
|
256
310
|
└── {session_id}.jsonl # original conversation turns
|
|
257
311
|
```
|
|
258
312
|
|
|
313
|
+
Set `SUPER_MEMORY_DATA_DIR` to use a different storage directory.
|
|
314
|
+
|
|
259
315
|
---
|
|
260
316
|
|
|
261
317
|
## Limitations
|
|
@@ -263,6 +319,22 @@ data/
|
|
|
263
319
|
- **Linear scan** — suitable for personal use (~10k memories). FAISS/ChromaDB integration planned for larger scale.
|
|
264
320
|
- **2-hop max** — deeper associative chains require `related()` tool calls by the agent.
|
|
265
321
|
- **Agent quality matters** — key selection on `remember` affects retrieval quality. System prompt tuning is important.
|
|
322
|
+
- **Cross-lingual content bias** — with multilingual e5, raw content similarity favors same-language memories regardless of meaning. Tag memories with multilingual keys so the key graph (not biased content cosine) carries cross-lingual recall.
|
|
323
|
+
- **Threshold calibration** — thresholds are tuned per embedding model. A new/uncalibrated model falls back to the BGE profile (with a warning); recalibrate via the `SUPER_MEMORY_*` env overrides.
|
|
324
|
+
|
|
325
|
+
---
|
|
326
|
+
|
|
327
|
+
## Testing
|
|
328
|
+
|
|
329
|
+
```bash
|
|
330
|
+
pnpm test # unit tests (fast, no model download)
|
|
331
|
+
tsx test/scenarios.ts # 21 end-to-end behavioral checks (local e5)
|
|
332
|
+
tsx test/robustness.ts # threshold overrides + Hebbian pollution bounds
|
|
333
|
+
tsx test/migration.ts # backend/dimension switch auto-migration (no brick)
|
|
334
|
+
tsx test/live-multilingual.ts # interactive multilingual recall demo
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
`scenarios.ts` and `robustness.ts` exercise the real local embedding backend (direct/associative/cross-lingual recall, versioning, depth growth, dedup, TTL, Hebbian learning, namespace isolation). They double as a recalibration harness when tuning thresholds for a new model.
|
|
266
338
|
|
|
267
339
|
---
|
|
268
340
|
|
package/dist/embedding.d.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
export declare const OPENAI_API_KEY: string;
|
|
2
2
|
export declare const OPENAI_EMBEDDING_MODEL: string;
|
|
3
3
|
export declare const EMBEDDING_BACKEND: string;
|
|
4
|
-
export declare
|
|
4
|
+
export declare const LOCAL_EMBEDDING_MODEL: string;
|
|
5
|
+
export declare const LOCAL_EMBEDDING_CACHE_DIR: string;
|
|
6
|
+
type EmbeddingInputType = "passage" | "query";
|
|
7
|
+
export interface ThresholdProfile {
|
|
8
|
+
keyMerge: number;
|
|
9
|
+
memoryDedup: number;
|
|
10
|
+
keyAutoLink: number;
|
|
11
|
+
keyRecall: number;
|
|
12
|
+
contentRecall: number;
|
|
13
|
+
}
|
|
14
|
+
export declare function getThresholdProfile(): ThresholdProfile;
|
|
15
|
+
export declare function embedTextAsync(text: string, inputType?: EmbeddingInputType): Promise<number[]>;
|
|
16
|
+
export {};
|
|
5
17
|
//# sourceMappingURL=embedding.d.ts.map
|
package/dist/embedding.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embedding.d.ts","sourceRoot":"","sources":["../src/embedding.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,cAAc,QAAmC,CAAC;AAC/D,eAAO,MAAM,sBAAsB,QAC6B,CAAC;
|
|
1
|
+
{"version":3,"file":"embedding.d.ts","sourceRoot":"","sources":["../src/embedding.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,cAAc,QAAmC,CAAC;AAC/D,eAAO,MAAM,sBAAsB,QAC6B,CAAC;AAGjE,eAAO,MAAM,iBAAiB,QACqB,CAAC;AACpD,eAAO,MAAM,qBAAqB,QACiC,CAAC;AACpE,eAAO,MAAM,yBAAyB,QACkB,CAAC;AAGzD,KAAK,kBAAkB,GAAG,SAAS,GAAG,OAAO,CAAC;AAmE9C,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACvB;AAkDD,wBAAgB,mBAAmB,IAAI,gBAAgB,CAYtD;AA6CD,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,EACZ,SAAS,GAAE,kBAA8B,GACxC,OAAO,CAAC,MAAM,EAAE,CAAC,CAqBnB"}
|
package/dist/embedding.js
CHANGED
|
@@ -3,10 +3,25 @@ config();
|
|
|
3
3
|
import OpenAI from "openai";
|
|
4
4
|
export const OPENAI_API_KEY = process.env.OPENAI_API_KEY ?? "";
|
|
5
5
|
export const OPENAI_EMBEDDING_MODEL = process.env.OPENAI_EMBEDDING_MODEL ?? "text-embedding-3-small";
|
|
6
|
-
const LOCAL_EMBEDDING_MODEL = process.env.LOCAL_EMBEDDING_MODEL ?? "paraphrase-multilingual-MiniLM-L12-v2";
|
|
7
6
|
const _DEFAULT_BACKEND = OPENAI_API_KEY ? "openai" : "local";
|
|
8
7
|
export const EMBEDDING_BACKEND = process.env.EMBEDDING_BACKEND ?? _DEFAULT_BACKEND;
|
|
8
|
+
export const LOCAL_EMBEDDING_MODEL = process.env.LOCAL_EMBEDDING_MODEL ?? "fast-multilingual-e5-large";
|
|
9
|
+
export const LOCAL_EMBEDDING_CACHE_DIR = process.env.LOCAL_EMBEDDING_CACHE_DIR ?? "local_cache";
|
|
9
10
|
const EMBED_RETRIES = 3;
|
|
11
|
+
const LOCAL_MODEL_ALIASES = {
|
|
12
|
+
"fast-multilingual-e5-large": "MLE5Large",
|
|
13
|
+
"multilingual-e5-large": "MLE5Large",
|
|
14
|
+
mle5large: "MLE5Large",
|
|
15
|
+
"fast-bge-base-en-v1.5": "BGEBaseENV15",
|
|
16
|
+
"bge-base-en-v1.5": "BGEBaseENV15",
|
|
17
|
+
bgebaseenv15: "BGEBaseENV15",
|
|
18
|
+
"fast-bge-small-en-v1.5": "BGESmallENV15",
|
|
19
|
+
"bge-small-en-v1.5": "BGESmallENV15",
|
|
20
|
+
bgesmallenv15: "BGESmallENV15",
|
|
21
|
+
"fast-all-minilm-l6-v2": "AllMiniLML6V2",
|
|
22
|
+
"all-minilm-l6-v2": "AllMiniLML6V2",
|
|
23
|
+
allminilml6v2: "AllMiniLML6V2",
|
|
24
|
+
};
|
|
10
25
|
let _openaiClient = null;
|
|
11
26
|
function getOpenAIClient() {
|
|
12
27
|
if (!_openaiClient) {
|
|
@@ -14,30 +29,128 @@ function getOpenAIClient() {
|
|
|
14
29
|
}
|
|
15
30
|
return _openaiClient;
|
|
16
31
|
}
|
|
32
|
+
function errorMessage(err) {
|
|
33
|
+
return err instanceof Error ? err.message : String(err);
|
|
34
|
+
}
|
|
35
|
+
function normalizeModelName(modelName) {
|
|
36
|
+
return modelName
|
|
37
|
+
.trim()
|
|
38
|
+
.replace(/^EmbeddingModel\./i, "")
|
|
39
|
+
.toLowerCase()
|
|
40
|
+
.replace(/[\s_]/g, "-");
|
|
41
|
+
}
|
|
42
|
+
function resolveLocalModel(modelName, embeddingModel) {
|
|
43
|
+
const normalized = normalizeModelName(modelName);
|
|
44
|
+
const aliasKey = LOCAL_MODEL_ALIASES[normalized];
|
|
45
|
+
if (aliasKey && aliasKey in embeddingModel)
|
|
46
|
+
return embeddingModel[aliasKey];
|
|
47
|
+
for (const [key, value] of Object.entries(embeddingModel)) {
|
|
48
|
+
if (key.toLowerCase() === modelName.trim().toLowerCase())
|
|
49
|
+
return value;
|
|
50
|
+
if (value.toLowerCase() === normalized)
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
const supported = Object.values(embeddingModel)
|
|
54
|
+
.filter((value) => value !== embeddingModel.CUSTOM)
|
|
55
|
+
.join(", ");
|
|
56
|
+
throw new Error(`Unsupported LOCAL_EMBEDDING_MODEL "${modelName}". Supported values: ${supported}`);
|
|
57
|
+
}
|
|
58
|
+
const THRESHOLD_PROFILES = {
|
|
59
|
+
openai: { keyMerge: 0.85, memoryDedup: 0.9, keyAutoLink: 0.5, keyRecall: 0.28, contentRecall: 0.28 },
|
|
60
|
+
bge: { keyMerge: 0.85, memoryDedup: 0.9, keyAutoLink: 0.6, keyRecall: 0.6, contentRecall: 0.5 },
|
|
61
|
+
// e5: query↔key is asymmetric (query/passage prefixes) and separates well —
|
|
62
|
+
// exact-term matches land ~0.886+, distinct words ≤0.82, so keyRecall 0.85
|
|
63
|
+
// catches real key hits. But key↔key and content↔key are both passage-embedded
|
|
64
|
+
// and do NOT separate, so keyMerge/keyAutoLink stay high to prevent collapse.
|
|
65
|
+
// memoryDedup 0.985: e5 packs distinct-but-similar facts ("A uses Postgres" vs
|
|
66
|
+
// "B uses Mongo" ≈0.96) dangerously close to true paraphrases (≈0.99). Dedup
|
|
67
|
+
// wrongly below 0.985 would silently supersede distinct memories → data loss.
|
|
68
|
+
e5: { keyMerge: 0.97, memoryDedup: 0.985, keyAutoLink: 0.93, keyRecall: 0.85, contentRecall: 0.8 },
|
|
69
|
+
minilm: { keyMerge: 0.85, memoryDedup: 0.9, keyAutoLink: 0.6, keyRecall: 0.5, contentRecall: 0.45 },
|
|
70
|
+
};
|
|
71
|
+
let _warnedUncalibrated = false;
|
|
72
|
+
function localModelFamily() {
|
|
73
|
+
const alias = LOCAL_MODEL_ALIASES[normalizeModelName(LOCAL_EMBEDDING_MODEL)];
|
|
74
|
+
if (alias === "MLE5Large")
|
|
75
|
+
return "e5";
|
|
76
|
+
if (alias === "AllMiniLML6V2")
|
|
77
|
+
return "minilm";
|
|
78
|
+
if (alias === "BGEBaseENV15" || alias === "BGESmallENV15")
|
|
79
|
+
return "bge";
|
|
80
|
+
// Unknown model: thresholds are NOT calibrated for it. A wrong profile can
|
|
81
|
+
// silently collapse (over-merge) or fragment (under-recall) the graph, so make
|
|
82
|
+
// the miscalibration loud and point at the env override escape hatch.
|
|
83
|
+
if (!_warnedUncalibrated) {
|
|
84
|
+
_warnedUncalibrated = true;
|
|
85
|
+
console.error(`[super-memory] WARNING: no calibrated threshold profile for ` +
|
|
86
|
+
`LOCAL_EMBEDDING_MODEL="${LOCAL_EMBEDDING_MODEL}". Falling back to BGE ` +
|
|
87
|
+
`thresholds — the graph may mis-cluster. Override per-threshold with ` +
|
|
88
|
+
`SUPER_MEMORY_KEY_MERGE / _MEMORY_DEDUP / _KEY_AUTOLINK / _KEY_RECALL / _CONTENT_RECALL.`);
|
|
89
|
+
}
|
|
90
|
+
return "bge";
|
|
91
|
+
}
|
|
92
|
+
function envThreshold(name) {
|
|
93
|
+
const raw = process.env[name];
|
|
94
|
+
if (raw === undefined || raw.trim() === "")
|
|
95
|
+
return undefined;
|
|
96
|
+
const n = Number(raw);
|
|
97
|
+
if (!Number.isFinite(n) || n < 0 || n > 1) {
|
|
98
|
+
console.error(`[super-memory] WARNING: ignoring ${name}="${raw}" (must be a number in [0,1]).`);
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
return n;
|
|
102
|
+
}
|
|
103
|
+
// Per-threshold env overrides are an escape hatch for when the model or the
|
|
104
|
+
// character of stored data drifts away from what the built-in profiles assume.
|
|
105
|
+
export function getThresholdProfile() {
|
|
106
|
+
const base = EMBEDDING_BACKEND !== "local"
|
|
107
|
+
? THRESHOLD_PROFILES.openai
|
|
108
|
+
: THRESHOLD_PROFILES[localModelFamily()];
|
|
109
|
+
return {
|
|
110
|
+
keyMerge: envThreshold("SUPER_MEMORY_KEY_MERGE") ?? base.keyMerge,
|
|
111
|
+
memoryDedup: envThreshold("SUPER_MEMORY_MEMORY_DEDUP") ?? base.memoryDedup,
|
|
112
|
+
keyAutoLink: envThreshold("SUPER_MEMORY_KEY_AUTOLINK") ?? base.keyAutoLink,
|
|
113
|
+
keyRecall: envThreshold("SUPER_MEMORY_KEY_RECALL") ?? base.keyRecall,
|
|
114
|
+
contentRecall: envThreshold("SUPER_MEMORY_CONTENT_RECALL") ?? base.contentRecall,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
17
117
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
118
|
let _localModel = null;
|
|
19
119
|
async function getLocalModel() {
|
|
20
120
|
if (!_localModel) {
|
|
21
121
|
try {
|
|
22
|
-
const {
|
|
23
|
-
|
|
122
|
+
const { FlagEmbedding, EmbeddingModel } = await import("fastembed");
|
|
123
|
+
const model = resolveLocalModel(LOCAL_EMBEDDING_MODEL, EmbeddingModel);
|
|
124
|
+
_localModel = await FlagEmbedding.init({
|
|
125
|
+
model: model,
|
|
126
|
+
cacheDir: LOCAL_EMBEDDING_CACHE_DIR,
|
|
127
|
+
});
|
|
24
128
|
}
|
|
25
|
-
catch {
|
|
26
|
-
throw new Error("
|
|
27
|
-
"Install
|
|
28
|
-
"Or set OPENAI_API_KEY to use OpenAI embeddings
|
|
129
|
+
catch (err) {
|
|
130
|
+
throw new Error("Failed to initialize local fastembed model.\n" +
|
|
131
|
+
"Install with: npm install fastembed\n" +
|
|
132
|
+
"Or set OPENAI_API_KEY to use OpenAI embeddings.\n" +
|
|
133
|
+
`Cause: ${errorMessage(err)}`);
|
|
29
134
|
}
|
|
30
135
|
}
|
|
31
136
|
return _localModel;
|
|
32
137
|
}
|
|
33
|
-
async function embedLocal(text) {
|
|
138
|
+
async function embedLocal(text, inputType) {
|
|
34
139
|
const model = await getLocalModel();
|
|
35
|
-
|
|
36
|
-
|
|
140
|
+
if (inputType === "query" && typeof model.queryEmbed === "function") {
|
|
141
|
+
return Array.from(await model.queryEmbed(text));
|
|
142
|
+
}
|
|
143
|
+
const gen = typeof model.passageEmbed === "function"
|
|
144
|
+
? model.passageEmbed([text], 256)
|
|
145
|
+
: model.embed([text]);
|
|
146
|
+
for await (const batch of gen) {
|
|
147
|
+
return Array.from(batch[0]);
|
|
148
|
+
}
|
|
149
|
+
throw new Error("fastembed returned no embeddings");
|
|
37
150
|
}
|
|
38
|
-
export async function embedTextAsync(text) {
|
|
151
|
+
export async function embedTextAsync(text, inputType = "passage") {
|
|
39
152
|
if (EMBEDDING_BACKEND === "local") {
|
|
40
|
-
return embedLocal(text);
|
|
153
|
+
return embedLocal(text, inputType);
|
|
41
154
|
}
|
|
42
155
|
const client = getOpenAIClient();
|
|
43
156
|
for (let attempt = 0; attempt < EMBED_RETRIES; attempt++) {
|
package/dist/embedding.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embedding.js","sourceRoot":"","sources":["../src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AAC;IACD,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;AACjC,CAAC"}
|
package/dist/memoryGraph.d.ts
CHANGED
|
@@ -9,19 +9,29 @@ export declare class MemoryGraph {
|
|
|
9
9
|
private _storedDim;
|
|
10
10
|
private _lock;
|
|
11
11
|
private _dirty;
|
|
12
|
-
|
|
12
|
+
private _bm25;
|
|
13
|
+
constructor();
|
|
14
|
+
static readonly HOP_DECAY = 0.3;
|
|
13
15
|
static readonly TIME_HALF_LIFE: number;
|
|
14
16
|
get linkCount(): number;
|
|
15
17
|
private _link;
|
|
16
18
|
private _hasLink;
|
|
19
|
+
private _getLinkWeight;
|
|
20
|
+
private _setLinkWeight;
|
|
17
21
|
private _unlinkMemory;
|
|
22
|
+
private _validMemoryLinks;
|
|
23
|
+
private _removeMemoryReferences;
|
|
24
|
+
private _pruneDanglingExplicitLinks;
|
|
18
25
|
private _pruneOrphanKeys;
|
|
19
26
|
private _checkDim;
|
|
27
|
+
private _ensureEmbeddingDim;
|
|
28
|
+
private _migrateEmbeddings;
|
|
20
29
|
private _isExpired;
|
|
21
30
|
private _timeFactor;
|
|
22
31
|
private _keyIdf;
|
|
23
32
|
private _findDuplicate;
|
|
24
33
|
private _autoLinkKeys;
|
|
34
|
+
private _rebuildBm25Index;
|
|
25
35
|
getKeysForMemory(memId: string): string[];
|
|
26
36
|
load(): Promise<void>;
|
|
27
37
|
save(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memoryGraph.d.ts","sourceRoot":"","sources":["../src/memoryGraph.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"memoryGraph.d.ts","sourceRoot":"","sources":["../src/memoryGraph.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,EAAa,MAAM,YAAY,CAAC;AAwEzD,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,CAgBpD;AAID,qBAAa,WAAW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