@restregular/dsh-memory 0.7.3 → 0.8.0
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 +4 -0
- package/lib/client.js +26 -8
- package/lib/panel.js +9 -0
- package/lib/provider/apply.js +10 -0
- package/lib/provider/index.js +23 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -320,6 +320,10 @@ tools/build-single-package.mjs 构建(产物契约检查 + 可选加载验证)
|
|
|
320
320
|
|
|
321
321
|
## 版本
|
|
322
322
|
|
|
323
|
+
- **0.8.0** —— 「服务 → 维护」新增**重建全部向量**:
|
|
324
|
+
- 一键把所有记录的向量(内存 + 磁盘)作废、重新排队并按当前模型重嵌,用于换过模型或怀疑向量与内容对不上时修复;只显示在两个条件都满足时(配置了后端且启用),两步确认,后台执行、不阻塞请求。
|
|
325
|
+
- 进度看「待嵌入向量」:面板在有待嵌入时每 **1.5s** 自动刷新列表徽标与计数(上限 300 次);从其它标签切回「记录」也会立即刷新一次。
|
|
326
|
+
- 重建期间向量检索暂时只用词法,完成一条恢复一条。
|
|
323
327
|
- **0.7.3** —— 修复「编辑一条记忆后一直显示待嵌入」:
|
|
324
328
|
- 面板 `/update` 改内容时只删了内存里的向量、**没有把 `.vec` 标脏**,重启后旧向量仍在磁盘上,会被当成“已嵌入”继续用(而且内容已经变了)。现在旧向量在内存与磁盘上一并作废。
|
|
325
329
|
- 编辑后**立即重建这一条**的向量(不再等 60s 的定时回填);重建失败才留在队列里由重试兜底。
|
package/lib/client.js
CHANGED
|
@@ -898,8 +898,8 @@ window.__ModuleLoader__.load({
|
|
|
898
898
|
)
|
|
899
899
|
}
|
|
900
900
|
|
|
901
|
-
/** 待嵌入自动刷新:最多
|
|
902
|
-
const PENDING_POLL_LIMIT =
|
|
901
|
+
/** 待嵌入自动刷新:最多 300 次 × 1.5s(后端挂着时不无限轮询)。 */
|
|
902
|
+
const PENDING_POLL_LIMIT = 300
|
|
903
903
|
|
|
904
904
|
function MemoryPanel() {
|
|
905
905
|
const [records, setRecords] = React.useState([])
|
|
@@ -974,8 +974,8 @@ window.__ModuleLoader__.load({
|
|
|
974
974
|
}
|
|
975
975
|
|
|
976
976
|
/**
|
|
977
|
-
* 维护动作:卸载向量服务 /
|
|
978
|
-
*
|
|
977
|
+
* 维护动作:卸载向量服务 / 清空记忆数据 / 重建全部向量。前两者不可撤销,重建代价高,
|
|
978
|
+
* 都走两步确认(dangerAsk 记住当前等确认的那一项,第二次点击才真的发请求)。
|
|
979
979
|
*/
|
|
980
980
|
const maintenanceAction = async (which) => {
|
|
981
981
|
if (dangerAsk !== which) { setDangerAsk(which); setEmbedNotice(''); return }
|
|
@@ -984,8 +984,10 @@ window.__ModuleLoader__.load({
|
|
|
984
984
|
try {
|
|
985
985
|
const value = which === 'uninstall'
|
|
986
986
|
? await api('embed/uninstall', {})
|
|
987
|
-
|
|
988
|
-
|
|
987
|
+
: which === 'reindex'
|
|
988
|
+
? await api('embed/reindex', {})
|
|
989
|
+
// 服务端要求显式 confirm:"delete",避免任何一次误触就清库
|
|
990
|
+
: await api('data/wipe', { confirm: 'delete' })
|
|
989
991
|
setEmbedServer(value.embedServer ? { ...value.embedServer } : value)
|
|
990
992
|
if (which === 'uninstall') {
|
|
991
993
|
setEmbedNotice(value.removed
|
|
@@ -993,6 +995,9 @@ window.__ModuleLoader__.load({
|
|
|
993
995
|
: value.reason === 'EXTERNAL_BACKEND'
|
|
994
996
|
? '当前后端不在本插件管理的目录里(是你自己装的),没有删除任何东西。'
|
|
995
997
|
: '没有找到本插件安装的向量服务文件。')
|
|
998
|
+
} else if (which === 'reindex') {
|
|
999
|
+
setPendingTick(0)
|
|
1000
|
+
setEmbedNotice(`已开始重建 ${value.records ?? 0} 条的向量;「待嵌入向量」会逐步下降,期间检索暂时只用词法。`)
|
|
996
1001
|
} else {
|
|
997
1002
|
setEmbedNotice(`已清空 ${value.removed ?? 0} 条记忆(${(value.scopes ?? []).length} 个作用域)。`)
|
|
998
1003
|
}
|
|
@@ -1033,7 +1038,7 @@ window.__ModuleLoader__.load({
|
|
|
1033
1038
|
const timer = setTimeout(() => {
|
|
1034
1039
|
setPendingTick((n) => n + 1)
|
|
1035
1040
|
load()
|
|
1036
|
-
},
|
|
1041
|
+
}, 1500)
|
|
1037
1042
|
return () => clearTimeout(timer)
|
|
1038
1043
|
}, [pendingTick, pending])
|
|
1039
1044
|
// 服务端 /status 给的 scope → label 映射(会话标题、project 的 cwd 只有服务端知道)
|
|
@@ -1151,6 +1156,8 @@ window.__ModuleLoader__.load({
|
|
|
1151
1156
|
onInstall: (override) => embedAction('install', override),
|
|
1152
1157
|
}),
|
|
1153
1158
|
)
|
|
1159
|
+
// 重建向量只在"配置了后端且启用"时有意义(maintenanceCard 在 configured 声明之前构建)。
|
|
1160
|
+
const canReindex = Boolean(embedServer && embedServer.enabled && (embedServer.configured === undefined ? Boolean(embedServer.baseUrl) : embedServer.configured))
|
|
1154
1161
|
// 维护区:DSH 卸载插件时不会给插件任何提问机会(就是 pnpm remove + 去掉
|
|
1155
1162
|
// bundles),所以"要不要留向量服务 / 要不要留记忆数据"只能在这里、卸载之前问。
|
|
1156
1163
|
const maintenanceCard = maintenance
|
|
@@ -1168,6 +1175,17 @@ window.__ModuleLoader__.load({
|
|
|
1168
1175
|
: h('button', { key: 'ask', disabled: embedBusy, onClick: () => maintenanceAction('uninstall') }, '卸载向量服务'))
|
|
1169
1176
|
: h('span', { className: 'muted' }, '未安装'),
|
|
1170
1177
|
),
|
|
1178
|
+
h('div', { className: 'maint-row' },
|
|
1179
|
+
h('span', { className: 'grow' }, `向量索引:${maintenance.records} 条`),
|
|
1180
|
+
canReindex
|
|
1181
|
+
? (maintenance.records > 0
|
|
1182
|
+
? (dangerAsk === 'reindex'
|
|
1183
|
+
? [h('button', { key: 'ok', className: 'danger', disabled: embedBusy, onClick: () => maintenanceAction('reindex') }, `确认重建 ${maintenance.records} 条的向量`),
|
|
1184
|
+
h('button', { key: 'no', disabled: embedBusy, onClick: () => setDangerAsk('') }, '取消')]
|
|
1185
|
+
: h('button', { key: 'ask', disabled: embedBusy, onClick: () => maintenanceAction('reindex') }, '重建全部向量'))
|
|
1186
|
+
: h('span', { className: 'muted' }, '无'))
|
|
1187
|
+
: h('span', { className: 'muted' }, '向量未启用'),
|
|
1188
|
+
),
|
|
1171
1189
|
h('div', { className: 'maint-row' },
|
|
1172
1190
|
h('span', { className: 'grow' }, `记忆数据:${maintenance.records} 条`),
|
|
1173
1191
|
maintenance.storeDir ? h('span', { className: 'muted path', title: maintenance.storeDir }, maintenance.storeDir) : null,
|
|
@@ -1233,7 +1251,7 @@ window.__ModuleLoader__.load({
|
|
|
1233
1251
|
return h('div', { className: 'memp' },
|
|
1234
1252
|
h('div', { className: 'tabs' },
|
|
1235
1253
|
h('button', { className: 'tab' + (tab === 'records' ? ' on' : ''), onClick: () => setTab('records') }, '服务'),
|
|
1236
|
-
h('button', { className: 'tab' + (tab === 'data' ? ' on' : ''), onClick: () => setTab('data') }, '记录'),
|
|
1254
|
+
h('button', { className: 'tab' + (tab === 'data' ? ' on' : ''), onClick: () => { if (tab !== 'data') load(); setTab('data') } }, '记录'),
|
|
1237
1255
|
h('button', { className: 'tab' + (tab === 'settings' ? ' on' : ''), onClick: () => setTab('settings') }, '设置'),
|
|
1238
1256
|
),
|
|
1239
1257
|
tab === 'settings' ? h(SettingsTab, {}) : tab === 'data' ? dataBody : overviewBody,
|
package/lib/panel.js
CHANGED
|
@@ -363,6 +363,15 @@ async function handle(ctx, routePath, req, res) {
|
|
|
363
363
|
writeJson(res, { ok: true, value: { ...out, ...(await memory.embedServerStatus()) } })
|
|
364
364
|
return
|
|
365
365
|
}
|
|
366
|
+
if (method === 'POST' && path === '/embed/reindex') {
|
|
367
|
+
if (typeof memory.reindexAll !== 'function') throw new ApiError(501, 'NOT_SUPPORTED', 'provider 未提供向量重建接口(请升级 @restregular/dsh-memory)')
|
|
368
|
+
// 同步部分只作废旧向量 + 排队,真正的重嵌在后台跑,不阻塞请求;进度看 /status 的待嵌入计数。
|
|
369
|
+
const result = memory.reindexAll() ?? {}
|
|
370
|
+
const total = typeof result.total === 'number' ? result.total : 0
|
|
371
|
+
console.log(`[dsh-memory-panel] 开始重建全部向量:${total} 条`)
|
|
372
|
+
writeJson(res, { ok: true, value: { scheduled: true, records: total } })
|
|
373
|
+
return
|
|
374
|
+
}
|
|
366
375
|
if (method === 'POST' && path === '/data/wipe') {
|
|
367
376
|
if (typeof memory.wipeAllRecords !== 'function') throw new ApiError(501, 'NOT_SUPPORTED', 'provider 未提供数据清理接口(请升级 @restregular/dsh-memory)')
|
|
368
377
|
const body = await readJsonBody(req)
|
package/lib/provider/apply.js
CHANGED
|
@@ -155,6 +155,16 @@ export class CordisMemoryService extends Service {
|
|
|
155
155
|
return this.impl.reindexRecord(scope, id)
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
+
/** 维护:重建全部向量(作废旧向量并重新嵌入)。 */
|
|
159
|
+
reindexAll() {
|
|
160
|
+
return this.impl.reindexAll()
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** 维护:作废全部向量并按当前模型后台重嵌。 */
|
|
164
|
+
reindexAll() {
|
|
165
|
+
return this.impl.reindexAll()
|
|
166
|
+
}
|
|
167
|
+
|
|
158
168
|
/** 作用域别名(没有则 undefined)。 */
|
|
159
169
|
scopeName(scope ) {
|
|
160
170
|
return this.impl.scopeName(scope)
|
package/lib/provider/index.js
CHANGED
|
@@ -1296,6 +1296,29 @@ export class LocalMemoryService {
|
|
|
1296
1296
|
return true
|
|
1297
1297
|
}
|
|
1298
1298
|
|
|
1299
|
+
/**
|
|
1300
|
+
* 作废全部向量并按当前模型重新嵌入。给"换模型残留了旧向量 / 怀疑向量有问题"用:
|
|
1301
|
+
* 同步部分只清空 + 排队,真正的重嵌在后台跑(别让 HTTP 等几分钟)。
|
|
1302
|
+
* 返回排队条数;进度由面板的「待嵌入」计数与自动刷新体现。
|
|
1303
|
+
*/
|
|
1304
|
+
reindexAll() {
|
|
1305
|
+
if (!this.cfg.vector.enabled || !this.cfg.vector.configured) return { total: 0, queued: this.pendingEmbedCount }
|
|
1306
|
+
this.discoverScopes()
|
|
1307
|
+
let total = 0
|
|
1308
|
+
for (const s of this.store.allScopes()) {
|
|
1309
|
+
for (const id of s.records.keys()) {
|
|
1310
|
+
s.vectors.delete(id)
|
|
1311
|
+
s.embedPending.add(id)
|
|
1312
|
+
total += 1
|
|
1313
|
+
}
|
|
1314
|
+
s.vectorsDirty = true
|
|
1315
|
+
s.dirty = true
|
|
1316
|
+
}
|
|
1317
|
+
this.store.scheduleFlush()
|
|
1318
|
+
void this.backfillAll({ throttleMs: 50 }).catch(() => { /* 失败留给 60s 重试 */ })
|
|
1319
|
+
return { total, queued: this.pendingEmbedCount }
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1299
1322
|
/**
|
|
1300
1323
|
* First-fill: embed the ENTIRE backlog (unlike backfillEmbeddings' single
|
|
1301
1324
|
* batch per scope), in throttled batches so a big import does not hammer
|