nebula-memory-mcp 1.2.2 → 1.2.3
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 +1 -1
- package/mcp-server.mjs +1 -1
- package/memory/profile-recall.cjs +46 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -112,7 +112,7 @@ agent-memory(引擎真源,9 个模块) ──人工对齐──▶ 本
|
|
|
112
112
|
|
|
113
113
|
| 上游 `agent-memory` | **本仓库** | `nebula-workbuddy-mcp` | 备注 |
|
|
114
114
|
|---|---|---|---|
|
|
115
|
-
| 2.1.
|
|
115
|
+
| **2.1.1**(薄索引 + 画像反哺闸门) | **1.2.3** | 1.0.6(待同步) | 引擎与上游 2.1.1 对齐 |
|
|
116
116
|
|
|
117
117
|
## License
|
|
118
118
|
|
package/mcp-server.mjs
CHANGED
|
@@ -40,6 +40,45 @@ function isPersonalQuery(query) {
|
|
|
40
40
|
return PERSONAL_PATTERNS.some((re) => re.test(q));
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* 功能虚词 bigram:这些词在任何中文句子里都高频出现,
|
|
45
|
+
* 不能用来判断「query 与画像节点是否同一个话题」。
|
|
46
|
+
* (2026-11-29 加:没有这层过滤时,「我平时喝什么咖啡」会因为「我平/平时/什么」
|
|
47
|
+
* 跟画像节点「孩子上二年级」之外的高重要度 fact 撞上而被污染)
|
|
48
|
+
*/
|
|
49
|
+
const FUNCTION_STEMS = [
|
|
50
|
+
'什么', '怎么', '为什', '多少', '哪个', '哪家', '是不', '有什',
|
|
51
|
+
'我平', '平时', '我的', '我叫', '我是', '我喜', '喜欢', '习惯', '偏好', '爱好',
|
|
52
|
+
'一些', '这个', '那个', '现在', '今天', '时候',
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
/** 取文本的 2~3 字 n-gram 集合(纯字符切分,不做分词,零依赖) */
|
|
56
|
+
function gramsOf(text, maxLen = 3) {
|
|
57
|
+
const out = new Set();
|
|
58
|
+
for (const seg of String(text || '').split(/[^\u4e00-\u9fa5A-Za-z0-9]+/)) {
|
|
59
|
+
for (let len = 2; len <= maxLen; len++) {
|
|
60
|
+
for (let i = 0; i + len <= seg.length; i++) out.add(seg.slice(i, i + len));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 画像节点是否与 query 属于同一话题。
|
|
68
|
+
*
|
|
69
|
+
* 规则:两者至少有一个**非功能虚词**的 n-gram 交集。
|
|
70
|
+
* 只有同话题时才反哺——否则「用户的名字是李雷」这种高重要度身份节点
|
|
71
|
+
* 会在任何个人化提问里被注入,把无关的画像词塞进查询。
|
|
72
|
+
*/
|
|
73
|
+
function sharesTopic(queryGrams, nodeText) {
|
|
74
|
+
for (const g of gramsOf(nodeText)) {
|
|
75
|
+
// 含功能词干的 n-gram 一律不算实义(否则 3-gram「我平时」会被当成话题交集)
|
|
76
|
+
if (FUNCTION_STEMS.some((s) => g.includes(s))) continue;
|
|
77
|
+
if (queryGrams.has(g)) return true;
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
43
82
|
/**
|
|
44
83
|
* 收集库里的画像/摘要节点文本(最多 N 条,按 importance 降序)。
|
|
45
84
|
* @param {any} mem NebulaMemory 实例
|
|
@@ -78,11 +117,16 @@ function boostPersonalQuery(mem, query, opts = {}) {
|
|
|
78
117
|
const nodes = collectProfileNodes(mem, maxNodes);
|
|
79
118
|
if (!nodes.length) return { boosted: false, reason: 'no-profile', tokens: [] };
|
|
80
119
|
|
|
120
|
+
// 相关性闸门:只有与 query 同话题的画像节点才参与反哺
|
|
121
|
+
const queryGrams = gramsOf(query);
|
|
122
|
+
const relevant = nodes.filter((n) => sharesTopic(queryGrams, n.text));
|
|
123
|
+
if (!relevant.length) return { boosted: false, reason: 'off-topic', tokens: [] };
|
|
124
|
+
|
|
81
125
|
// 从画像节点文本里抽关键词(用简单的二元切分 + 过滤停用词)
|
|
82
126
|
const STOP = new Set(['的', '了', '是', '在', '有', '和', '与', '我', '你', '他', '她', '这', '那', '就', '也', '都', '很', '个', '上', '下', '中', '为', '对', '从', '到', '把', '被', '让', '给', '但', '而', '或', '如果', '因为', '所以', '一个', '我们', '你们', '他们']);
|
|
83
127
|
const tokens = [];
|
|
84
128
|
const seen = new Set();
|
|
85
|
-
for (const node of
|
|
129
|
+
for (const node of relevant) {
|
|
86
130
|
const text = String(node.text || '');
|
|
87
131
|
// 中文按 2-4 字滑窗取词组(比单字有区分度,比整句更可匹配)
|
|
88
132
|
for (const seg of text.split(/[,。;:、\s\n|()()\[\]【】"'"'']+/)) {
|
|
@@ -106,4 +150,4 @@ function boostPersonalQuery(mem, query, opts = {}) {
|
|
|
106
150
|
return { boosted: tokens.length > 0, reason: 'personal', tokens };
|
|
107
151
|
}
|
|
108
152
|
|
|
109
|
-
module.exports = { isPersonalQuery, collectProfileNodes, boostPersonalQuery, PERSONAL_PATTERNS };
|
|
153
|
+
module.exports = { isPersonalQuery, collectProfileNodes, boostPersonalQuery, PERSONAL_PATTERNS, gramsOf, sharesTopic, FUNCTION_STEMS };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nebula-memory-mcp",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"mcpName": "io.github.yb-zhai/nebula-memory",
|
|
5
5
|
"description": "Zero-dependency local Agent memory MCP Server (stdio JSON-RPC). Works offline, no API keys, no database. Exposes remember/recall/stats/forget to Claude Desktop, Cursor, ChatGPT and any MCP client.",
|
|
6
6
|
"type": "module",
|