dsh-feiyu-memgate 0.3.1 → 0.3.2
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/CHANGELOG.md +22 -0
- package/README.md +7 -3
- package/README.zh.md +7 -3
- package/client/client.js +13 -0
- package/docs/DETAIL.en.md +6 -2
- package/docs/DETAIL.md +6 -2
- package/package.json +1 -1
- package/python/GATEWAY_VERSION.json +7 -7
- package/python/feiyu_memgate/backends/base.py +9 -0
- package/python/feiyu_memgate/backends/embedding.py +38 -0
- package/python/feiyu_memgate/backends/hybrid.py +32 -0
- package/python/feiyu_memgate/cli.py +16 -0
- package/python/feiyu_memgate/core/recall.py +6 -3
- package/python/feiyu_memgate/core/stages.py +117 -4
- package/src/config.js +4 -0
- package/src/gateway.js +2 -0
- package/src/plugin.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,28 @@
|
|
|
4
4
|
|
|
5
5
|
每个版本下,“默认行为的变化”列出升级后不用改设置就会不一样的地方,每一项都写了怎么改回去。
|
|
6
6
|
|
|
7
|
+
## 0.3.2
|
|
8
|
+
|
|
9
|
+
日期:2026-11-18。自带网关为提交 `7de07c6`。
|
|
10
|
+
|
|
11
|
+
闲聊时顺带想起相连的记忆,设计说明和测量见 [docs/design/2026-11-18-linked-recall.md](https://github.com/N0rmal-114/feiyu-memgate/blob/main/docs/design/2026-11-18-linked-recall.md)。
|
|
12
|
+
|
|
13
|
+
### 默认行为的变化
|
|
14
|
+
|
|
15
|
+
- **用向量检索时,顺带想起相连的记忆。** 召回之后,网关顺着交出去的前两条记忆,找和它们最相似的记忆,把相似度够高(0.60)的最多再加两条,总数不超过 `advanced.recallLimit`。用 `endpoint` 或 `local` 检索(开不开 `retrieval.hybrid` 都一样)时生效;`keyword` 下没有变化。每顺着一条记忆,要把已存的向量多扫一遍。用 bge-m3 在 48 句留出的闲聊上通过真实的网关量得:和一句话所触及的记忆相连的记忆,混合检索下交出去的比例从 26.4% 到 41.7%,单用向量检索从 29.2% 到 42.7%;每句话交出的条数,混合检索从 2.9 到 3.7,向量检索从 3.7 到 4.3;没有相关记忆的轮次和以前一样安静(混合检索 43.8%,向量检索 31.2%),追问没有变差。一道题约两个点。改回去:`advanced.linkedRecall` 设为关。
|
|
16
|
+
|
|
17
|
+
### 新增
|
|
18
|
+
|
|
19
|
+
- 新设置 `advanced.linkedRecall`(默认开),在设置页面、`/memgate` 和 profile 文件里都能改。改动它会重启自带的网关。
|
|
20
|
+
|
|
21
|
+
### 修好的
|
|
22
|
+
|
|
23
|
+
- 自带的网关里,命令行在写不出中文的控制台上不再以错误结束(这项修复在 0.3.1 发布之后才打包进来)。插件启动网关时已经指定了编码,所以它不改变插件的行为。
|
|
24
|
+
|
|
25
|
+
### 没有验证的
|
|
26
|
+
|
|
27
|
+
上面的数字只来自一个模型(bge-m3)和一小组编出来的例子;别的模型沿用同一个相似度门槛,没有量过。没有在和真实模型的聊天里验证过。
|
|
28
|
+
|
|
7
29
|
## 0.3.1
|
|
8
30
|
|
|
9
31
|
日期:2026-11-17。自带网关为提交 `9b00619`。
|
package/README.md
CHANGED
|
@@ -23,6 +23,8 @@ With the default settings, this is what you see:
|
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
The age counts calendar days: today, yesterday, 2 days ago, 3 to 6 days ago, 7 to 29 days in weeks, 30 to 364 days in months, then years. A date after today gets no age. If more memories matched than fit, a last line says how many. The gateway applies score thresholds, so most turns get fewer memories than the limit, and many get none. The lookup waits at most `advanced.recallTimeoutMs` (4000 ms by default); a slower lookup is skipped for that turn.
|
|
26
|
+
|
|
27
|
+
A block may also hold memories that are not close to your message but are close to the first ones found. With vector retrieval (the `endpoint` and `local` tiers, with or without `retrieval.hybrid`) and `advanced.linkedRecall` on (the default since 0.3.2), the gateway, after the usual lookup, follows the first two memories it found to the memories most similar to them and adds at most two that are similar enough, never more than `advanced.recallLimit` in all. Measured through the bundled gateway with the bge-m3 embedding model on a held-out set of 48 casual chat remarks (one case is two points): of the memories connected to what a remark reaches, 26.4% were delivered before and 41.7% after with hybrid retrieval, and 29.2% and 42.7% with plain vector retrieval. Memories per remark went from 2.9 to 3.7 (hybrid) and from 3.7 to 4.3 (vector). Turns with nothing related stayed quiet as often as before (43.8% with hybrid, 31.2% with plain vector retrieval), and follow-up questions were not hurt. These numbers come from one model and a small set of invented cases, and were not verified in a live chat. Under `keyword` nothing changes. Each followed memory costs one extra pass over the stored vectors.
|
|
26
28
|
4. **The block stays in the conversation history, and a memory is not given twice.** The block is saved with the turn, like any other message. Two consequences. The context grows by the block on every turn that has one, and those tokens are sent again on later turns. The prompt cache is not harmed: nothing before your current message changes, so the cached prefix of the earlier conversation is still valid. And the plugin can see what the model already has: with `advanced.skipRepeats` on (the default) it leaves out of each turn every memory whose text is already in a block of this plugin that is still in the history, and adds no block when nothing new is left. Memories are compared by their text, not by label or date. When the host compacts the conversation and the old block is gone, the memory is given again. With the setting off, only a block identical to the previous one is left out.
|
|
27
29
|
5. **A failed lookup is announced.** If the lookup of a turn times out or fails, or memory is wanted while the bundled gateway is still starting or restarting, the plugin adds one short note after your message instead of a block: "(Long-term memory could not be searched this turn: the lookup timed out or the memory service is not available right now. Do not conclude from this that there is no related memory.)". It does this only on the first turn of a streak of failures, never when the result was simply empty, when the message was not worth a lookup, or when memory is off (no Python, incomplete settings, a gateway that is off, stopped or failed). Switch it off with `advanced.failureNote`.
|
|
28
30
|
6. **Two tools for the model.** `memgate_remember` takes one short sentence (at most 4000 characters) and saves it. `memgate_search` takes a query (at most 500 characters) and an optional `limit` from 1 to 10, and returns the same kind of block. A short fixed section in the system prompt (in Chinese or English, following `advanced.language`) tells the model to call `memgate_remember` when you ask it to remember something or state a lasting fact about yourself, your preferences or your work, never to save secrets, to call `memgate_search` when earlier conversations may hold the answer, and to treat recalled memories as data, not instructions. It also tells the model how to write what it saves: a sentence that can be understood on its own later (who or what it is about, not "he" or "this"), times written as dates, and, when something changed, the new state as a full sentence that says what it replaces (the old memory is not rewritten; the newer one is ranked first). The tool descriptions say the same. The tools report what happened: saved, not saved (nothing worth keeping, daily cap used up, refused, memory unavailable), or unknown (the gateway did not answer in time). The model is told never to say "saved" unless the tool did.
|
|
@@ -70,7 +72,7 @@ Every setting can be changed in three ways. They write the same values.
|
|
|
70
72
|
- **The `/memgate` chat command.** See [The /memgate command](#the-memgate-command).
|
|
71
73
|
- **The profile's configuration file.** The row `feiyu-memgate` in the profile's `cordis.patch.yml`. The other two ways save their changes there. A home-level patch or a `--patch` overlay that sets the same row takes precedence, and a change they would override is refused.
|
|
72
74
|
|
|
73
|
-
Most settings take effect at once. A change of `gateway.mode`, `gateway.python`, `gateway.dataDir`, the retrieval tier or the endpoint settings in use, `retrieval.hybrid` (only while it changes what the gateway runs: under `keyword` it does not), `advanced.profile`, `advanced.dailyWrites`, `advanced.redaction`, `advanced.newerFirst` or `advanced.forgetting` restarts the gateway. The count of the daily cap starts again then. The four settings of the chat experience (`advanced.skipRepeats`, `advanced.showAge`, `advanced.failureNote`, `advanced.captureMinChars`) are read on every turn and never restart the gateway; a change of `advanced.language` registers the system prompt section again in the new language. Switching a module off removes what it registered in DSH. The gateway runs only while at least one of `modules.autoRecall`, `modules.rememberTool`, `modules.searchTool` and `modules.autoCapture` is on.
|
|
75
|
+
Most settings take effect at once. A change of `gateway.mode`, `gateway.python`, `gateway.dataDir`, the retrieval tier or the endpoint settings in use, `retrieval.hybrid` (only while it changes what the gateway runs: under `keyword` it does not), `advanced.profile`, `advanced.dailyWrites`, `advanced.redaction`, `advanced.newerFirst`, `advanced.linkedRecall` or `advanced.forgetting` restarts the gateway. The count of the daily cap starts again then. The four settings of the chat experience (`advanced.skipRepeats`, `advanced.showAge`, `advanced.failureNote`, `advanced.captureMinChars`) are read on every turn and never restart the gateway; a change of `advanced.language` registers the system prompt section again in the new language. Switching a module off removes what it registered in DSH. The gateway runs only while at least one of `modules.autoRecall`, `modules.rememberTool`, `modules.searchTool` and `modules.autoCapture` is on.
|
|
74
76
|
|
|
75
77
|
| Setting | What it does | Default | Notes |
|
|
76
78
|
|---|---|---|---|
|
|
@@ -95,6 +97,7 @@ Most settings take effect at once. A change of `gateway.mode`, `gateway.python`,
|
|
|
95
97
|
| `advanced.recallTimeoutMs` | How long a turn waits for automatic recall (500 to 20000 ms). A slower lookup is skipped. | 4000 | |
|
|
96
98
|
| `advanced.language` | Language of the memory block, the tool replies, the system prompt section, the failure note and `/memgate`: `auto` (follow the system language), `zh` or `en`. | `auto` | Memories themselves are never translated. |
|
|
97
99
|
| `advanced.skipRepeats` | Leave out a memory that a block of this conversation still in the history already shows (compared by text); add no block when nothing new is left. | on | Off: only a block identical to the previous one is left out (the behaviour up to 0.3.0). The comparison does not read the label, so a memory whose text is the tail of another one that follows a closing bracket (for example "(备注)喝茶" and "喝茶") counts as shown. |
|
|
100
|
+
| `advanced.linkedRecall` | With vector retrieval (the `endpoint` and `local` tiers, with or without `retrieval.hybrid`): after the usual lookup, follow the first two memories found to the memories closest to them and add at most two. | on | Never beyond `advanced.recallLimit`. Under `keyword` it does nothing. Off: only what the usual lookup found, as in 0.3.1. Changing it restarts the managed gateway. Managed mode only. |
|
|
98
101
|
| `advanced.showAge` | The memory block says today's date (the date on this computer) and how long ago each dated memory is. | on | Off: the block shows only the absolute dates, as in 0.3.0. Applies to the `memgate_search` results as well. |
|
|
99
102
|
| `advanced.failureNote` | When the lookup of a turn times out or fails, or the bundled gateway is still starting, add one note after your message. | on | Only on the first turn of a failure streak. Never when memory is off or the result was empty. |
|
|
100
103
|
| `advanced.captureMinChars` | With `modules.autoCapture` on: a message with fewer meaningful characters than this is not saved (0 to 50). | 4 | 0 turns the length test off; commands, `ok` and filler are skipped whatever the value. Punctuation, spaces, emoji and placeholders such as `[图片]` do not count. |
|
|
@@ -238,6 +241,7 @@ The setup survives closing or reloading the page. After a DSH restart in the mid
|
|
|
238
241
|
|
|
239
242
|
- **Keyword search does not find reworded questions.** In the gateway's own benchmark (240 memories, 160 questions, synthetic Chinese text) the keyword store delivered a right memory for 0 of 55 reworded questions at the default settings, and for 95.6% of 45 questions that use the memory's own words. Semantic search is much better on reworded questions. See the [benchmark](https://github.com/N0rmal-114/feiyu-memgate#基准测试) (in Chinese). Languages other than Chinese were not measured.
|
|
240
243
|
- **The memory block stays in the history.** The context grows with every turn that gets a block (see step 4 above). `advanced.skipRepeats` keeps the same memory from being added again while its block is still there.
|
|
244
|
+
- **Linked memories were measured once.** The numbers under step 3 come from one embedding model (bge-m3), a held-out set of 48 invented casual remarks, in which one case is two points, and the gateway's own test tool; they were not verified in a live chat. Other models keep the same similarity threshold (0.60) without having been measured. Under `keyword` the setting changes nothing. With vector retrieval each followed memory costs one extra pass over the stored vectors, so a recall can cost up to two more passes.
|
|
241
245
|
- **Not verified in a live chat.** The 0.3.1 changes (no repeated memories, today's date and ages, the way memories are written, the filter of automatic capture, the note about a failed lookup) were exercised in unit tests and in a simulated host, not in a live conversation with a model. Whether a model follows the new instructions for writing memories, and whether the date and ages in the block improve its answers, was not measured. The host's own handling of a plugin message of the form `notice` was not checked in a real host.
|
|
242
246
|
- **"Today" is the date of this computer.** The block states it from the local clock; a wrong clock or time zone gives wrong ages. A memory's age is counted from the date the gateway stored, which is the date of the message's own time for memories saved by 0.3.1 and the UTC day for older ones.
|
|
243
247
|
- **Only memories that the model chose to save exist**, unless you switch on `modules.autoCapture`. The gateway stores the text as it is passed, with secrets removed when redaction is on. It does not extract facts, merge memories or mark old ones as outdated. A newer memory is only ranked before an older one.
|
|
@@ -247,7 +251,7 @@ The setup survives closing or reloading the page. After a DSH restart in the mid
|
|
|
247
251
|
- **Forgetting is experimental** and has been tested only in simulations.
|
|
248
252
|
- **Real-host testing.** Tested in the installed DeepSeek Harness 0.2.2-rc.1 on Windows 11 with an isolated profile: the plugin loads, the bundled gateway starts with a Python from PATH, the settings page renders and saves, the status and model routes answer only to the owner session, the chat command works, and with the add-on and bge-small-zh-v1.5 the local tier is used and reworded questions find their memories. Installing the add-on from npm through the settings page was run too, with the dependency's install script refused: the add-on is installed and enabled, the model is downloaded and the local tier takes over (the path that allows the script was not run). The hybrid switch of 0.3.0 was also run in an isolated profile, with a stand-in embeddings service on the local machine, not a real model: with the `endpoint` tier and `retrieval.hybrid` on, the gateway starts with a hybrid store and the memories of the keyword store are copied into both the vector file and the keyword index; after one memory was removed from the vector file while the host was stopped, the next start removed it from the index too. In that profile, where the plugin is linked from its source folder, the settings form says the settings are not available (0.2.0 behaves the same there), so the new switch was not seen in the form and was set through the profile file. Not tested: macOS and Linux desktops, the Desktop application's own window (the web profile of the same host was used), and a conversation with a real model (automatic recall and the two tools were exercised in tests and against the gateway, not in a live chat).
|
|
249
253
|
- **Other versions and systems.** Other DSH versions in the accepted ranges, other operating systems and other Python builds are not covered by a real-host test.
|
|
250
|
-
- This is version 0.3.
|
|
254
|
+
- This is version 0.3.2; what each version changed is in the [changelog](https://github.com/N0rmal-114/feiyu-memgate/blob/main/plugins/dsh-feiyu-memgate/CHANGELOG.md) (Chinese). Version 0.3.2 changes one default: with vector retrieval the block may now hold up to two memories linked to the first two found; switch it off with `advanced.linkedRecall`. Version 0.3.1 changed defaults, and each change has a switch: repeated memories are skipped (`advanced.skipRepeats`), the memory block shows today's date and the age of each memory (`advanced.showAge`), a failed lookup is announced to the model (`advanced.failureNote`), and automatic capture skips trivial messages (`advanced.captureMinChars`). The system prompt section and the `memgate_remember` description say more about how to write a memory, and saved memories carry the local time. The bundled gateway is updated to the same version.
|
|
251
255
|
|
|
252
256
|
## Troubleshooting
|
|
253
257
|
|
|
@@ -265,4 +269,4 @@ Start with `/memgate status`. It shows the state of the gateway, the Python that
|
|
|
265
269
|
|
|
266
270
|
## Licence
|
|
267
271
|
|
|
268
|
-
MIT, see [LICENSE](LICENSE). The bundled gateway in `python/` is the same author's project, [feiyu-memgate](https://github.com/N0rmal-114/feiyu-memgate), under the same licence ([python/LICENSE](python/LICENSE)). It is version 0.1.0 at commit `
|
|
272
|
+
MIT, see [LICENSE](LICENSE). The bundled gateway in `python/` is the same author's project, [feiyu-memgate](https://github.com/N0rmal-114/feiyu-memgate), under the same licence ([python/LICENSE](python/LICENSE)). It is version 0.1.0 at commit `7de07c60f2b370e6a79371dbc42068240f20942f` as recorded in [python/GATEWAY_VERSION.json](python/GATEWAY_VERSION.json).
|
package/README.zh.md
CHANGED
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
“多久以前”按日历天数算:当天是“今天”,1 天“昨天”,2 天“前天”,3 到 6 天“N 天前”,7 到 29 天按周,30 到 364 天按月,再久按年。日期在今天之后的不写。相关的记忆放不下时,最后一行说明还有几条。网关有分数线,所以多数轮次得到的记忆比上限少,不少轮次一条都没有。查找最多等 `advanced.recallTimeoutMs`(默认 4000 毫秒);更慢的查找这一轮跳过。
|
|
26
|
+
|
|
27
|
+
记忆块里还可能有和你的消息不太近、却和最先查到的记忆相近的记忆。用向量检索(`endpoint` 和 `local` 两档,开不开 `retrieval.hybrid` 都一样)并且 `advanced.linkedRecall` 开着(0.3.2 起默认开)时,网关在平常的查找之后,顺着查到的前两条记忆,找和它们最相似的记忆,把相似度够高的最多再加两条,总数不超过 `advanced.recallLimit`。通过自带的网关、用 bge-m3 嵌入模型,在 48 句留出的闲聊上量得:和一句话所触及的记忆相连的记忆,混合检索下交出去的比例从 26.4% 到 41.7%,单用向量检索从 29.2% 到 42.7%(一道题约两个点)。每句话交出的记忆条数,混合检索从 2.9 条到 3.7 条,向量检索从 3.7 条到 4.3 条。没有相关记忆的轮次和以前一样安静(混合检索 43.8%,单用向量检索 31.2%),追问没有变差。这些数字只来自一个模型和一小组编出来的例子,没有在真实的聊天里验证过。用 `keyword` 时没有任何变化。每顺着一条记忆,要把已存的向量多扫一遍。
|
|
26
28
|
4. **记忆块留在对话历史里,同一条记忆不会给第二次。** 记忆块和这一轮一起保存,和别的消息一样。这有两个后果。有记忆块的每一轮,上下文都会变长,这些词元在之后的轮次里还会再发送。提示词缓存不受损害:你当前消息之前的内容都没有变,之前对话已缓存的前缀仍然有效。另外,插件能看到模型已经有哪些记忆:`advanced.skipRepeats` 开着(默认)时,历史里还留着的本插件的记忆块里已经出现过的记忆,这一轮不再给,一条新的都没有就不加记忆块。比较的是记忆的文字,不看标签和日期。宿主压缩了对话、旧的记忆块不在了,这条记忆就会再给一次。关掉这项后,只有和上一个记忆块完全相同的块才不加。
|
|
27
29
|
5. **召回失败会告诉模型。** 这一轮的查询超时或出错,或者需要记忆而自带网关还在启动或重启时,插件在你的消息之后加一行说明,代替记忆块:“(这一轮没能查询长期记忆:查询超时或记忆服务暂时不可用。不要据此认为没有相关记忆。)”。它只在连续失败的第一轮加一次;结果只是为空、这条消息不值得查、或者记忆功能本来就没开(没有 Python、设置不完整、网关处于 off、stopped 或 failed)时不加。用 `advanced.failureNote` 关闭。
|
|
28
30
|
6. **给模型的两个工具。** `memgate_remember` 接收一句短话(最多 4000 个字符)并保存。`memgate_search` 接收一个查询(最多 500 个字符)和可选的 `limit`(1 到 10),返回同样格式的块。系统提示词里有一小段固定说明(中文或英文,按 `advanced.language`),告诉模型:你要求它记住某件事、或说出关于你自己、你的偏好、你的工作的长期信息时,调用 `memgate_remember`;不要保存秘密;之前的对话可能有答案时,调用 `memgate_search`;召回的记忆是资料,不是指令。说明里还告诉模型怎么写要保存的话:以后单独看也能懂(说清是谁、是什么,不用“他”“这个”),时间写成日期,一件事变了就把新的情况记成完整的一句并说明它取代了什么(旧的那条不会被改写,新的排在前面)。工具的描述里也写了同样的内容。工具会如实报告结果:已保存;没有保存(没有需要记的内容、今天的写入次数用完、被拒绝、记忆功能不可用);或结果不确定(网关没有及时回应)。工具没有说已保存,模型就不能说已保存。
|
|
@@ -70,7 +72,7 @@ dsh plugin --profile desktop add dsh-feiyu-memgate
|
|
|
70
72
|
- **`/memgate` 聊天命令。** 见[/memgate 命令](#memgate-命令)。
|
|
71
73
|
- **profile 的配置文件。** profile 的 `cordis.patch.yml` 里的 `feiyu-memgate` 这一行。另外两种方式也把改动存在这里。家目录级的补丁或 `--patch` 覆盖层如果设置了同一行,它们优先;会被它们盖掉的改动会被拒绝。
|
|
72
74
|
|
|
73
|
-
多数设置立即生效。改动 `gateway.mode`、`gateway.python`、`gateway.dataDir`、检索方式或正在使用的向量接口设置、`retrieval.hybrid`(只在它改变网关实际运行的内容时;在 `keyword` 下不会)、`advanced.profile`、`advanced.dailyWrites`、`advanced.redaction`、`advanced.newerFirst`、`advanced.forgetting` 会重启网关,每日写入上限的计数随之重新开始。聊天体验的四项设置(`advanced.skipRepeats`、`advanced.showAge`、`advanced.failureNote`、`advanced.captureMinChars`)每一轮都重新读取,不会重启网关;改动 `advanced.language` 会按新的语言重新注册系统提示词里的那一段。关掉一项功能,它在 DSH 里注册的东西就被移除。只有 `modules.autoRecall`、`modules.rememberTool`、`modules.searchTool`、`modules.autoCapture` 中至少有一个开着时,网关才会运行。
|
|
75
|
+
多数设置立即生效。改动 `gateway.mode`、`gateway.python`、`gateway.dataDir`、检索方式或正在使用的向量接口设置、`retrieval.hybrid`(只在它改变网关实际运行的内容时;在 `keyword` 下不会)、`advanced.profile`、`advanced.dailyWrites`、`advanced.redaction`、`advanced.newerFirst`、`advanced.linkedRecall`、`advanced.forgetting` 会重启网关,每日写入上限的计数随之重新开始。聊天体验的四项设置(`advanced.skipRepeats`、`advanced.showAge`、`advanced.failureNote`、`advanced.captureMinChars`)每一轮都重新读取,不会重启网关;改动 `advanced.language` 会按新的语言重新注册系统提示词里的那一段。关掉一项功能,它在 DSH 里注册的东西就被移除。只有 `modules.autoRecall`、`modules.rememberTool`、`modules.searchTool`、`modules.autoCapture` 中至少有一个开着时,网关才会运行。
|
|
74
76
|
|
|
75
77
|
| 设置 | 作用 | 默认值 | 备注 |
|
|
76
78
|
|---|---|---|---|
|
|
@@ -95,6 +97,7 @@ dsh plugin --profile desktop add dsh-feiyu-memgate
|
|
|
95
97
|
| `advanced.recallTimeoutMs` | 每轮最多等自动召回多少毫秒(500 到 20000)。更慢的查找跳过。 | 4000 | |
|
|
96
98
|
| `advanced.language` | 记忆块、工具回复、系统提示词那一段、失败说明和 `/memgate` 用的语言:`auto`(跟随系统语言)、`zh` 或 `en`。 | `auto` | 记忆本身不会被翻译。 |
|
|
97
99
|
| `advanced.skipRepeats` | 这个对话的历史里还留着的记忆块已经给过的记忆,不再给第二次(按文字比较);没有新的就不加记忆块。 | 开 | 关:只有和上一个记忆块完全相同的块才不加(0.3.0 及以前的做法)。比较时不解析标签,所以一条记忆的文字如果是另一条记忆在右括号之后的那一段(例如“(备注)喝茶”和“喝茶”),也算给过。 |
|
|
100
|
+
| `advanced.linkedRecall` | 用向量检索时(`endpoint` 和 `local` 两档,开不开 `retrieval.hybrid` 都一样):平常的查找之后,顺着查到的前两条记忆去找和它们最接近的记忆,最多再加两条。 | 开 | 总数不超过 `advanced.recallLimit`。用 `keyword` 时什么都不做。关:只给平常的查找查到的记忆,和 0.3.1 一样。改动它会重启自带的网关。只用于 managed 模式。 |
|
|
98
101
|
| `advanced.showAge` | 记忆块写明今天的日期(这台电脑上的日期),以及每条有日期的记忆是多久以前的事。 | 开 | 关:和 0.3.0 一样,只写具体日期。`memgate_search` 的结果也一样。 |
|
|
99
102
|
| `advanced.failureNote` | 这一轮的查询超时或出错,或者自带网关还在启动时,在你的消息之后加一行说明。 | 开 | 只在连续失败的第一轮加。记忆功能没开、或者结果为空时不加。 |
|
|
100
103
|
| `advanced.captureMinChars` | `modules.autoCapture` 打开时:有效字符少于这个数的消息不保存(0 到 50)。 | 4 | 0 表示不按字数过滤;命令、`ok` 和语气词不论取值都跳过。标点、空格、表情和 `[图片]` 这类占位不算字数。 |
|
|
@@ -238,6 +241,7 @@ profile 的 `cordis.patch.yml` 里,一行会整个替换同一个 `id` 那一
|
|
|
238
241
|
|
|
239
242
|
- **关键词检索找不到换了说法的问题。** 在网关自己的基准测试里(240 条记忆、160 个问题、合成的中文文本),关键词存储在默认设置下,55 个换了说法的问题一个都没有交出正确的记忆;45 个用了记忆原话的问题里交出了 95.6%。语义检索在换了说法的问题上好得多。见[基准测试](https://github.com/N0rmal-114/feiyu-memgate#基准测试)。中文以外的语言没有测过。
|
|
240
243
|
- **记忆块留在历史里。** 每个得到记忆块的轮次都会让上下文变长(见上面第 4 点)。记忆块还在的时候,`advanced.skipRepeats` 避免同一条记忆再被加一次。
|
|
244
|
+
- **相连的记忆只量过一次。** 第 3 点下面的数字只来自一个嵌入模型(bge-m3)、48 句编出来的留出闲聊(一道题约两个点)和网关自己的测试工具,没有在真实的聊天里验证过。别的模型沿用同一个相似度门槛(0.60),没有量过。用 `keyword` 时这项设置什么都不改。用向量检索时,每顺着一条记忆要把已存的向量多扫一遍,一次召回最多多扫两遍。
|
|
241
245
|
- **没有在真实的聊天里验证过。** 0.3.1 的这些改动(不重复给记忆、今天的日期和“多久以前”、记忆的写法说明、自动记录的过滤、召回失败的说明)由单元测试和模拟宿主的测试覆盖,没有在和真实模型的对话里验证过。模型是否照新的说明去写记忆、块里的日期和“多久以前”是否让回答变好,没有测量。宿主怎样对待 `notice` 形式的插件消息,没有在真实宿主里检查过。
|
|
242
246
|
- **“今天”是这台电脑上的日期。** 记忆块按本机的时钟写明今天;时钟或时区不对,“多久以前”就不对。一条记忆的“多久以前”从网关存下的日期算起:0.3.1 保存的记忆是消息自己时间的日期,更早保存的是 UTC 日期。
|
|
243
247
|
- **只有模型选择保存的记忆才存在**,除非你打开 `modules.autoCapture`。网关按传入的原文存储,打开脱敏时去掉秘密。它不抽取事实,不归并记忆,也不把旧记忆标成过时。较新的记忆只是排在较旧的前面。
|
|
@@ -247,7 +251,7 @@ profile 的 `cordis.patch.yml` 里,一行会整个替换同一个 `id` 那一
|
|
|
247
251
|
- **遗忘是实验性的**,只在模拟里测过。
|
|
248
252
|
- **真实环境测试。** 在 Windows 11 上已安装的 DeepSeek Harness 0.2.2-rc.1 里,用一个隔离的配置测过:插件能加载,自带网关用 PATH 上的 Python 启动,设置页面能显示和保存,状态接口和模型接口只回应所有者的会话,聊天命令可用;装上向量插件和 bge-small-zh-v1.5 后用的是 local 检索方式,换了说法的问题能找到对应的记忆。通过设置页面从 npm 安装向量插件也测过,测的是拒绝依赖的安装脚本这条路:向量插件装好并启用,模型下载完成,检索方式换成 local(允许脚本的那条路没有跑过)。0.3.0 的混合检索也在一个隔离的配置里跑过,向量接口用的是本机的一个替身服务,不是真实模型:`endpoint` 方式打开 `retrieval.hybrid` 后,网关以混合存储启动,关键词存储里的记忆被复制到向量文件和关键词索引两边;宿主停止时从向量文件里删掉一条,下次启动索引同步去掉了这一条。在这个从源码目录链接插件的配置里,设置页面的表单显示“设置现在不可用”(0.2.0 在这里也是这样),所以新开关在表单里的显示没有实际看到,开关是通过 profile 文件设置的。没有测过:macOS 和 Linux 桌面、桌面应用自己的窗口(用的是同一宿主的 web 配置)、和真实模型的对话(自动召回和两个工具只在测试里和对着网关测过,没有在实际聊天里用过)。
|
|
249
253
|
- **其他版本和系统。** 可接受范围内的其他 DSH 版本、其他操作系统和其他 Python 构建,都没有在真实宿主里测过。
|
|
250
|
-
- 当前版本是 0.3.
|
|
254
|
+
- 当前版本是 0.3.2,每个版本改了什么见[更新记录](https://github.com/N0rmal-114/feiyu-memgate/blob/main/plugins/dsh-feiyu-memgate/CHANGELOG.md)。0.3.2 改了一项默认行为:用向量检索时,记忆块里可能多出最多两条和最先查到的两条相连的记忆,用 `advanced.linkedRecall` 可以关掉。0.3.1 改了几项默认行为,每一项都有开关:不重复给同一条记忆(`advanced.skipRepeats`),记忆块写明今天的日期和每条记忆是多久以前的事(`advanced.showAge`),召回失败时告诉模型(`advanced.failureNote`),自动记录跳过无关紧要的消息(`advanced.captureMinChars`)。系统提示词里的说明和 `memgate_remember` 的描述多讲了怎么写记忆,保存的记忆带上本地时间。自带的网关也更新到同一版本。
|
|
251
255
|
|
|
252
256
|
## 故障排查
|
|
253
257
|
|
|
@@ -265,4 +269,4 @@ profile 的 `cordis.patch.yml` 里,一行会整个替换同一个 `id` 那一
|
|
|
265
269
|
|
|
266
270
|
## 许可
|
|
267
271
|
|
|
268
|
-
MIT,见 [LICENSE](LICENSE)。`python/` 里自带的网关是同一作者的项目 [feiyu-memgate](https://github.com/N0rmal-114/feiyu-memgate),许可相同([python/LICENSE](python/LICENSE))。版本是 0.1.0,提交是 `
|
|
272
|
+
MIT,见 [LICENSE](LICENSE)。`python/` 里自带的网关是同一作者的项目 [feiyu-memgate](https://github.com/N0rmal-114/feiyu-memgate),许可相同([python/LICENSE](python/LICENSE))。版本是 0.1.0,提交是 `7de07c60f2b370e6a79371dbc42068240f20942f`,记录在 [python/GATEWAY_VERSION.json](python/GATEWAY_VERSION.json) 里。
|
package/client/client.js
CHANGED
|
@@ -457,6 +457,19 @@ window.__ModuleLoader__.load({ id: 'dsh-feiyu-memgate', factory: (require) => {
|
|
|
457
457
|
"zh": "这个对话里前面的记忆块还留着的记忆,不再给第二次(按记忆的文字比较)。没有新的就不加记忆块。关掉:只有和上一个记忆块完全相同时才不加。"
|
|
458
458
|
}
|
|
459
459
|
},
|
|
460
|
+
{
|
|
461
|
+
"key": "linkedRecall",
|
|
462
|
+
"kind": "boolean",
|
|
463
|
+
"default": true,
|
|
464
|
+
"label": {
|
|
465
|
+
"en": "Recall linked memories",
|
|
466
|
+
"zh": "顺带想起相连的记忆"
|
|
467
|
+
},
|
|
468
|
+
"help": {
|
|
469
|
+
"en": "With vector retrieval (the endpoint and local tiers, with or without retrieval.hybrid), after the usual lookup the gateway follows the first two memories it found to the memories closest to them and adds at most two, never beyond advanced.recallLimit. Under keyword retrieval it does nothing.",
|
|
470
|
+
"zh": "用向量检索时(endpoint 和 local 两档,开不开 retrieval.hybrid 都一样),网关在平常的查找之后,顺着找到的前两条记忆去找和它们最接近的记忆,最多再加两条,总数不超过 advanced.recallLimit。用 keyword 检索时什么都不做。"
|
|
471
|
+
}
|
|
472
|
+
},
|
|
460
473
|
{
|
|
461
474
|
"key": "showAge",
|
|
462
475
|
"kind": "boolean",
|
package/docs/DETAIL.en.md
CHANGED
|
@@ -6,6 +6,8 @@ The DeepSeek Harness (DSH) plugin for the [feiyu-memgate](https://github.com/N0r
|
|
|
6
6
|
|
|
7
7
|
1. The first time a memory feature is needed, the plugin starts the bundled gateway in the background. DSH does not wait for it.
|
|
8
8
|
2. When you send a message, the plugin looks up related memories and adds them after your message, in a block marked as data, not instructions. The block says today's date (the date on this computer) and each dated memory shows how long ago it was, for example `(记忆,2026-10-27,3 周前)` in Chinese or `(memory, 2026-10-27, 3 weeks ago)` in English. At most 5 by default; most turns get fewer, and many get none. The lookup waits at most 4 seconds and is skipped when slower.
|
|
9
|
+
|
|
10
|
+
The block may also hold memories that are not close to your message but are close to the first ones found. With vector retrieval (the `endpoint` and `local` tiers, with or without `retrieval.hybrid`) and `advanced.linkedRecall` on (the default since 0.3.2), the gateway follows the first two memories it found to the memories most similar to them and adds at most two that are similar enough, never more than `advanced.recallLimit` in all. Measured through the bundled gateway with the bge-m3 embedding model on a held-out set of 48 casual chat remarks (one case is two points): of the memories connected to what a remark reaches, 26.4% were delivered before and 41.7% after with hybrid retrieval, and 29.2% and 42.7% with plain vector retrieval. Memories per remark went from 2.9 to 3.7 (hybrid) and from 3.7 to 4.3 (vector). Turns with nothing related stayed quiet as often as before (43.8% with hybrid, 31.2% with plain vector retrieval), and follow-up questions were not hurt. One model, a small set of invented cases, not verified in a live chat. Under `keyword` nothing changes. Each followed memory costs one extra pass over the stored vectors.
|
|
9
11
|
3. The block stays in the conversation history, so the context grows on every turn that has one. Nothing before your current message changes, so the prompt cache is not affected. A memory that a block still in the history already shows is not added again (`advanced.skipRepeats`); if the host compacts the conversation and the block is gone, the memory is given again.
|
|
10
12
|
4. If the lookup of a turn times out or fails, or the bundled gateway is still starting, one short note after your message tells the model that memory could not be searched, so it does not take that for "no related memory". It is added on the first turn of a failure streak only (`advanced.failureNote`).
|
|
11
13
|
5. The model has two tools: `memgate_remember` saves one sentence, `memgate_search` looks memories up. A short section in the system prompt (in Chinese or English, following `advanced.language`) tells it to save only when you ask it to remember something or state a lasting fact, never to save secrets, and how to write a memory: a sentence that can be understood on its own (who or what, not "he" or "this"), times as dates, and for a change the new state as a full sentence that says what it replaces.
|
|
@@ -42,6 +44,7 @@ Every setting can be changed in three places: this plugin's settings page on the
|
|
|
42
44
|
| `retrieval.hybrid` | Also search by keyword in the vector tiers and fuse the results (no effect under `keyword`) | off |
|
|
43
45
|
| `advanced.recallLimit` | Most memories added per turn | 5 |
|
|
44
46
|
| `advanced.skipRepeats` | Do not add a memory that a block still in the history already shows | on |
|
|
47
|
+
| `advanced.linkedRecall` | With vector retrieval, follow the first two memories found to the memories closest to them and add at most two, never beyond `advanced.recallLimit`; nothing under `keyword`. Changing it restarts the managed gateway | on |
|
|
45
48
|
| `advanced.showAge` | The block says today's date and how long ago each memory is | on |
|
|
46
49
|
| `advanced.failureNote` | Tell the model when the lookup of a turn failed | on |
|
|
47
50
|
| `advanced.captureMinChars` | Automatic capture skips a message with fewer meaningful characters (0 to 50; 0 turns the length test off) | 4 |
|
|
@@ -81,12 +84,13 @@ Measured basis, in the gateway's own benchmark with bge-m3 (nothing was measured
|
|
|
81
84
|
|
|
82
85
|
- Keyword search does not find reworded questions: in the gateway's own benchmark it delivered a right memory for none of 55 reworded questions. See the [benchmark](https://github.com/N0rmal-114/feiyu-memgate#基准测试) (in Chinese).
|
|
83
86
|
- The memory block stays in the history, so the context grows. `advanced.skipRepeats` keeps the same memory from being added again while its block is there.
|
|
87
|
+
- Linked memories were measured once: one embedding model (bge-m3), 48 invented casual remarks held out (one case is two points), the gateway's own test tool, not a live chat. Other models keep the same threshold (0.60) unmeasured. Under `keyword` nothing changes. Each followed memory costs one extra pass over the stored vectors.
|
|
84
88
|
- Not verified in a live chat. The 0.3.1 changes (no repeated memories, today's date and ages, the way memories are written, the filter of automatic capture, the note about a failed lookup) were exercised in unit tests and in a simulated host, not in a live conversation with a model. Whether a model follows the new instructions, and whether the date and ages improve its answers, was not measured. "Today" is the date on this computer.
|
|
85
89
|
- Only memories the model chose to save exist, unless automatic capture is on.
|
|
86
90
|
- The daily write cap is counted in memory, per DSH process, and starts again when the gateway restarts.
|
|
87
91
|
- The settings page depends on host UI interfaces that are still changing; without it, every setting can be changed with `/memgate` or in the profile file.
|
|
88
92
|
- Real-host testing. Tested in the installed DeepSeek Harness 0.2.2-rc.1 on Windows 11 with an isolated profile: the plugin loads, the bundled gateway starts with a Python from PATH, the settings page renders and saves, the status and model routes answer only to the owner session, the chat command works, and with the add-on and bge-small-zh-v1.5 the local tier is used and reworded questions find their memories. Installing the add-on from npm through the settings page was run too, with the dependency's install script refused: the add-on is installed and enabled, the model is downloaded and the local tier takes over (the path that allows the script was not run). The hybrid switch of 0.3.0 was also run in an isolated profile, with a stand-in embeddings service on the local machine, not a real model: with the `endpoint` tier and `retrieval.hybrid` on, the gateway starts with a hybrid store and the memories of the keyword store are copied into both the vector file and the keyword index; after one memory was removed from the vector file while the host was stopped, the next start removed it from the index too. In that profile, where the plugin is linked from its source folder, the settings form says the settings are not available (0.2.0 behaves the same there), so the new switch was not seen in the form and was set through the profile file. Not tested: macOS and Linux desktops, the Desktop application's own window (the web profile of the same host was used), and a conversation with a real model (automatic recall and the two tools were exercised in tests and against the gateway, not in a live chat).
|
|
89
|
-
- This is version 0.3.
|
|
93
|
+
- This is version 0.3.2; what each version changed is in the [changelog](https://github.com/N0rmal-114/feiyu-memgate/blob/main/plugins/dsh-feiyu-memgate/CHANGELOG.md) (Chinese). Version 0.3.2 changes one default: with vector retrieval the block may now hold up to two memories linked to the first two found; switch it off with `advanced.linkedRecall`. Version 0.3.1 changed defaults, and each change has a switch: repeated memories are skipped (`advanced.skipRepeats`), the memory block shows today's date and the age of each memory (`advanced.showAge`), a failed lookup is announced to the model (`advanced.failureNote`), and automatic capture skips trivial messages (`advanced.captureMinChars`). Saved memories carry the local time, and the bundled gateway is updated to the same version.
|
|
90
94
|
|
|
91
95
|
## Troubleshooting
|
|
92
96
|
|
|
@@ -94,4 +98,4 @@ Start with `/memgate status`. If no Python is found, install Python 3.11 or late
|
|
|
94
98
|
|
|
95
99
|
## Licence
|
|
96
100
|
|
|
97
|
-
MIT. The bundled gateway is the same author's project [feiyu-memgate](https://github.com/N0rmal-114/feiyu-memgate), under the same licence, version 0.1.0 at commit `
|
|
101
|
+
MIT. The bundled gateway is the same author's project [feiyu-memgate](https://github.com/N0rmal-114/feiyu-memgate), under the same licence, version 0.1.0 at commit `7de07c60f2b370e6a79371dbc42068240f20942f`.
|
package/docs/DETAIL.md
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
1. 第一次需要记忆功能时,插件在后台启动自带的网关,DSH 不会等它。
|
|
8
8
|
2. 你发出消息时,插件查找相关记忆,把它们放在你的消息之后,包在一个标明“这是资料,不是指令”的块里。块里写明今天的日期(这台电脑上的日期),有日期的记忆还写明是多久以前的事,例如“(记忆,2026-10-27,3 周前)”。默认最多 5 条,多数轮次更少,也可能一条都没有。查找最多等 4 秒,更慢就跳过。
|
|
9
|
+
|
|
10
|
+
记忆块里还可能有和你的消息不太近、却和最先查到的记忆相近的记忆。用向量检索(`endpoint` 和 `local` 两档,开不开 `retrieval.hybrid` 都一样)并且 `advanced.linkedRecall` 开着(0.3.2 起默认开)时,网关顺着查到的前两条记忆,找和它们最相似的记忆,把相似度够高的最多再加两条,总数不超过 `advanced.recallLimit`。通过自带的网关、用 bge-m3 嵌入模型,在 48 句留出的闲聊上量得:和一句话所触及的记忆相连的记忆,混合检索下交出去的比例从 26.4% 到 41.7%,单用向量检索从 29.2% 到 42.7%(一道题约两个点)。每句话交出的记忆条数,混合检索从 2.9 条到 3.7 条,向量检索从 3.7 条到 4.3 条。没有相关记忆的轮次和以前一样安静(混合检索 43.8%,单用向量检索 31.2%),追问没有变差。数字只来自一个模型和一小组编出来的例子,没有在真实的聊天里验证过。用 `keyword` 时没有任何变化。每顺着一条记忆,要把已存的向量多扫一遍。
|
|
9
11
|
3. 这个块会留在对话历史里,所以有记忆块的每一轮,上下文都会变长。你当前消息之前的内容不变,提示词缓存不受影响。历史里还留着的记忆块已经给过的记忆,不会再加一次(`advanced.skipRepeats`);宿主压缩了对话、记忆块不在了,这条记忆就会再给一次。
|
|
10
12
|
4. 这一轮的查询超时或出错,或者自带网关还在启动时,你的消息之后会加一行说明,告诉模型这一轮没能查询记忆,不要当作“没有相关记忆”。只在连续失败的第一轮加(`advanced.failureNote`)。
|
|
11
13
|
5. 模型有两个工具:`memgate_remember` 保存一句话,`memgate_search` 主动查找。系统提示词里的一小段说明(中文或英文,按 `advanced.language`)告诉它:你要求记住、或说出长期有用的信息时才保存,不保存秘密,并告诉它怎么写记忆:以后单独看也能懂的一句话(说清是谁、是什么,不用“他”“这个”),时间写成日期,一件事变了就把新的情况记成完整的一句并说明它取代了什么。
|
|
@@ -42,6 +44,7 @@ dsh plugin --profile <name> add dsh-feiyu-memgate
|
|
|
42
44
|
| `retrieval.hybrid` | 向量检索下同时用关键词检索并合并结果(`keyword` 下不起作用) | 关 |
|
|
43
45
|
| `advanced.recallLimit` | 每轮最多加入几条记忆 | 5 |
|
|
44
46
|
| `advanced.skipRepeats` | 历史里的记忆块已经给过的记忆,不再给第二次 | 开 |
|
|
47
|
+
| `advanced.linkedRecall` | 用向量检索时,顺着查到的前两条记忆去找和它们最接近的记忆,最多再加两条,总数不超过 `advanced.recallLimit`;用 `keyword` 时什么都不做。改动它会重启自带的网关 | 开 |
|
|
45
48
|
| `advanced.showAge` | 记忆块写明今天的日期和每条记忆是多久以前的事 | 开 |
|
|
46
49
|
| `advanced.failureNote` | 这一轮的查询失败时告诉模型 | 开 |
|
|
47
50
|
| `advanced.captureMinChars` | 自动记录跳过有效字符少于这个数的消息(0 到 50;0 表示不按字数过滤) | 4 |
|
|
@@ -81,12 +84,13 @@ dsh plugin --profile <name> add dsh-feiyu-memgate
|
|
|
81
84
|
|
|
82
85
|
- 关键词检索找不到换了说法的问题:在网关自己的基准测试里,55 个换了说法的问题一个都没有交出正确的记忆。见[基准测试](https://github.com/N0rmal-114/feiyu-memgate#基准测试)。
|
|
83
86
|
- 记忆块留在历史里,上下文会变长。记忆块还在的时候,`advanced.skipRepeats` 避免同一条记忆再被加一次。
|
|
87
|
+
- 相连的记忆只量过一次:一个嵌入模型(bge-m3)、48 句编出来的留出闲聊(一道题约两个点)、网关自己的测试工具,没有在真实的聊天里验证过。别的模型沿用同一个门槛(0.60),没有量过。用 `keyword` 时没有变化。每顺着一条记忆,要把已存的向量多扫一遍。
|
|
84
88
|
- 没有在真实的聊天里验证过。0.3.1 的这些改动(不重复给记忆、今天的日期和“多久以前”、记忆的写法说明、自动记录的过滤、召回失败的说明)由单元测试和模拟宿主的测试覆盖,没有在和真实模型的对话里验证过。模型是否照新的说明去做、日期和“多久以前”是否让回答变好,没有测量。“今天”是这台电脑上的日期。
|
|
85
89
|
- 只有模型选择保存的记忆才存在,除非打开自动记录。
|
|
86
90
|
- 每日写入上限在内存里计数,按 DSH 进程计,网关重启后重新开始。
|
|
87
91
|
- 设置页面依赖宿主里仍在变化的界面接口;没有它,用 `/memgate` 或 profile 文件也能改全部设置。
|
|
88
92
|
- 真实环境测试:在 Windows 11 上已安装的 DeepSeek Harness 0.2.2-rc.1 里,用一个隔离的配置测过:插件能加载,自带网关用 PATH 上的 Python 启动,设置页面能显示和保存,状态接口和模型接口只回应所有者的会话,聊天命令可用;装上向量插件和 bge-small-zh-v1.5 后用的是 local 检索方式,换了说法的问题能找到对应的记忆。通过设置页面从 npm 安装向量插件也测过,测的是拒绝依赖的安装脚本这条路:向量插件装好并启用,模型下载完成,检索方式换成 local(允许脚本的那条路没有跑过)。0.3.0 的混合检索也在一个隔离的配置里跑过,向量接口用的是本机的一个替身服务,不是真实模型:`endpoint` 方式打开 `retrieval.hybrid` 后,网关以混合存储启动,关键词存储里的记忆被复制到向量文件和关键词索引两边;宿主停止时从向量文件里删掉一条,下次启动索引同步去掉了这一条。在这个从源码目录链接插件的配置里,设置页面的表单显示“设置现在不可用”(0.2.0 在这里也是这样),所以新开关在表单里的显示没有实际看到,开关是通过 profile 文件设置的。没有测过:macOS 和 Linux 桌面、桌面应用自己的窗口(用的是同一宿主的 web 配置)、和真实模型的对话(自动召回和两个工具只在测试里和对着网关测过,没有在实际聊天里用过)。
|
|
89
|
-
- 当前版本是 0.3.
|
|
93
|
+
- 当前版本是 0.3.2,每个版本改了什么见[更新记录](https://github.com/N0rmal-114/feiyu-memgate/blob/main/plugins/dsh-feiyu-memgate/CHANGELOG.md)。0.3.2 改了一项默认行为:用向量检索时,记忆块里可能多出最多两条和最先查到的两条相连的记忆,用 `advanced.linkedRecall` 可以关掉。0.3.1 改了几项默认行为,每一项都有开关:不重复给同一条记忆(`advanced.skipRepeats`),记忆块写明今天的日期和每条记忆是多久以前的事(`advanced.showAge`),召回失败时告诉模型(`advanced.failureNote`),自动记录跳过无关紧要的消息(`advanced.captureMinChars`)。保存的记忆带上本地时间,自带的网关也更新到同一版本。
|
|
90
94
|
|
|
91
95
|
## 遇到问题
|
|
92
96
|
|
|
@@ -94,4 +98,4 @@ dsh plugin --profile <name> add dsh-feiyu-memgate
|
|
|
94
98
|
|
|
95
99
|
## 许可
|
|
96
100
|
|
|
97
|
-
MIT。自带的网关是同一作者的项目 [feiyu-memgate](https://github.com/N0rmal-114/feiyu-memgate),许可相同,版本 0.1.0,提交 `
|
|
101
|
+
MIT。自带的网关是同一作者的项目 [feiyu-memgate](https://github.com/N0rmal-114/feiyu-memgate),许可相同,版本 0.1.0,提交 `7de07c60f2b370e6a79371dbc42068240f20942f`。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-feiyu-memgate",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "DeepSeek Harness (DSH) plugin for the feiyu-memgate memory gateway: automatic recall, remember and search tools, with a bundled gateway.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
"package": "feiyu-memgate",
|
|
3
3
|
"repository": "https://github.com/N0rmal-114/feiyu-memgate",
|
|
4
4
|
"version": "0.1.0",
|
|
5
|
-
"commit": "
|
|
5
|
+
"commit": "7de07c60f2b370e6a79371dbc42068240f20942f",
|
|
6
6
|
"dirty": false,
|
|
7
7
|
"files": {
|
|
8
8
|
"LICENSE": "5ced0abe92eb65e7bdceda54797958785c6523fb7e927bb5fb4851d4e9c9865a",
|
|
9
9
|
"feiyu_memgate/__init__.py": "de5e4762ab5eca26b89b0ce338f0e033af9c6a19c1f2b12c5ac8b586b2d87bcb",
|
|
10
10
|
"feiyu_memgate/__main__.py": "13a1a5b340cdcfc1902b62be90e508c7c71886000d5bf087e7854aadf09fb35e",
|
|
11
11
|
"feiyu_memgate/backends/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
|
12
|
-
"feiyu_memgate/backends/base.py": "
|
|
13
|
-
"feiyu_memgate/backends/embedding.py": "
|
|
14
|
-
"feiyu_memgate/backends/hybrid.py": "
|
|
12
|
+
"feiyu_memgate/backends/base.py": "1547bf21c23c613254fe326b73e64d880a1e3ddbcaab6d1e6c7173b1b81fc876",
|
|
13
|
+
"feiyu_memgate/backends/embedding.py": "a22303e3cecde570342dbc61f8a657e4c73a7c75a94bf55dc1966ee769e58467",
|
|
14
|
+
"feiyu_memgate/backends/hybrid.py": "5f4d79998327f5b9173a67d0c1d48c934efa81e6ac03c31c5b2e7ead8e011588",
|
|
15
15
|
"feiyu_memgate/backends/inmemory.py": "839bd82ef3ff1b5907520a1b957586e1edf2dfa336a2727c07b41d230fcf61d5",
|
|
16
16
|
"feiyu_memgate/backends/openviking.py": "53f05faf86242ca1d01d9c2c4135e872ad005724dfb230f176bddc2fb4d26592",
|
|
17
17
|
"feiyu_memgate/backends/sqlite.py": "6a56e0b5968bf2b898106e551db484125db1ec84ff94da77534fb87c4de8fe97",
|
|
18
18
|
"feiyu_memgate/builtins.py": "dbc33174ab45e6e46ccd7ecaf81ec1909503d602d386671d93d9f887ce2f20c3",
|
|
19
|
-
"feiyu_memgate/cli.py": "
|
|
19
|
+
"feiyu_memgate/cli.py": "4448f03c88352109080fa66b054965e6fb352a7794288ddc4c36f6fb923f7e70",
|
|
20
20
|
"feiyu_memgate/client/__init__.py": "910350a7c0f44f078aa1eedb9b3e7c79da3ab198ef4db8073921900af9d2e84f",
|
|
21
21
|
"feiyu_memgate/client/block.py": "f0846004cfd7b060dae85a3e95470c7de9c79f37450a80d5321c0f70fcf105bd",
|
|
22
22
|
"feiyu_memgate/client/http.py": "57e6f68ea4b12bd0c7c22092f279777d374344323827723d69e0c26bbede6ef8",
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"feiyu_memgate/core/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
|
27
27
|
"feiyu_memgate/core/limits.py": "513c3bc278cd2101329efd497e96b1845ce95f06a96bbd8a87e27c20c0a97f7c",
|
|
28
28
|
"feiyu_memgate/core/pool.py": "4f3454556f68db4044a762573b7b7164f865357f45cdaffd53f18f349c0fb8db",
|
|
29
|
-
"feiyu_memgate/core/recall.py": "
|
|
29
|
+
"feiyu_memgate/core/recall.py": "3e00fec49336cb5b75aa8822b893a67bf6c40950d1ca7db8b0fb30f2777d3475",
|
|
30
30
|
"feiyu_memgate/core/redact.py": "ef0d654cf06197d6e01bd08b9e21f760aa8870a28d78c72d24fae27f4c5cfe95",
|
|
31
|
-
"feiyu_memgate/core/stages.py": "
|
|
31
|
+
"feiyu_memgate/core/stages.py": "3a0b92616417ef2ea81d5a583dff8a04d2b5f079ba8630d279d403981ea6735b",
|
|
32
32
|
"feiyu_memgate/core/tidy.py": "b050113a1416b924c32fc606b9e7b1fcff9c1130f982fe7cd117d2e996e66507",
|
|
33
33
|
"feiyu_memgate/core/watch.py": "b43b41e3aff5a7e4b183efe27bf6d417c8625823831a8887054ca80470bf7a02",
|
|
34
34
|
"feiyu_memgate/core/write.py": "ded042ca80d373af4c4a48e15f736f205c4f2c07c4eadfad9cb884f34199f00f",
|
|
@@ -69,6 +69,15 @@ class MemoryBackend(abc.ABC):
|
|
|
69
69
|
replaces). Needs writable=True.
|
|
70
70
|
receipt_refs(receipt) -> list of the refs the write `receipt` produced,
|
|
71
71
|
or None when not known (yet) or not supported.
|
|
72
|
+
neighbours(ref, limit, timeout=None, ctl=None)
|
|
73
|
+
-> the `limit` memories most similar to the stored memory
|
|
74
|
+
`ref`, best first, as Hit objects whose `score` is on the
|
|
75
|
+
backend's own 0..1 relevance scale (the scale find() uses),
|
|
76
|
+
never including `ref` itself; [] when `ref` is unknown.
|
|
77
|
+
It takes the same `timeout` and `ctl` as find() and raises
|
|
78
|
+
(BackendError) rather than answer partly. The `linked` recall
|
|
79
|
+
stage uses it to bring back the memories connected with the
|
|
80
|
+
best ones; a backend without it is simply left out of that.
|
|
72
81
|
"""
|
|
73
82
|
|
|
74
83
|
# False makes remember() refuse; the gateway also checks it before writing.
|
|
@@ -592,6 +592,44 @@ class EmbeddingBackend(MemoryBackend):
|
|
|
592
592
|
hits.append(_make_hit(ref, self._score(cosine), text, date, cosine))
|
|
593
593
|
return hits
|
|
594
594
|
|
|
595
|
+
def neighbours(self, ref, limit, timeout=None, ctl=None):
|
|
596
|
+
"""Up to `limit` memories most similar to the stored memory `ref`, best first, never `ref` itself.
|
|
597
|
+
|
|
598
|
+
Works on the stored vectors only (no embeddings request): the same cosine and the same score mapping
|
|
599
|
+
as find(), so a score here means what it means there; memories at or below `floor` cosine are left
|
|
600
|
+
out. [] for a ref that is not stored. BackendError when the budget runs out or `ctl` was cancelled
|
|
601
|
+
(never a partial ranking). Costs one pass over the stored vectors."""
|
|
602
|
+
total = self._timeout if timeout is None else max(0.0, float(timeout))
|
|
603
|
+
deadline = time.monotonic() + total
|
|
604
|
+
if not isinstance(ref, str) or limit < 1:
|
|
605
|
+
return []
|
|
606
|
+
|
|
607
|
+
def check():
|
|
608
|
+
if time.monotonic() >= deadline:
|
|
609
|
+
raise BackendError("deadline exceeded")
|
|
610
|
+
if getattr(ctl, "cancelled", False):
|
|
611
|
+
raise BackendError("cancelled")
|
|
612
|
+
|
|
613
|
+
check()
|
|
614
|
+
snapshot = self._snapshot()
|
|
615
|
+
own = next((vec for key, vec in snapshot if key == ref), None)
|
|
616
|
+
if own is None:
|
|
617
|
+
return []
|
|
618
|
+
scored = []
|
|
619
|
+
for start in range(0, len(snapshot), SCORE_CHECK_EVERY):
|
|
620
|
+
check()
|
|
621
|
+
for key, vec in snapshot[start:start + SCORE_CHECK_EVERY]:
|
|
622
|
+
if key != ref and len(vec) == len(own):
|
|
623
|
+
scored.append((_sumprod(own, vec), key))
|
|
624
|
+
best = [(c, r) for c, r in heapq.nlargest(limit, scored) if self._score(c) > 0.0]
|
|
625
|
+
texts = self._texts([r for _, r in best])
|
|
626
|
+
hits = []
|
|
627
|
+
for cosine, key in best:
|
|
628
|
+
if key in texts: # deleted by another connection between scan and fetch: skip
|
|
629
|
+
text, date = texts[key]
|
|
630
|
+
hits.append(_make_hit(key, self._score(cosine), text, date, cosine))
|
|
631
|
+
return hits
|
|
632
|
+
|
|
595
633
|
def _texts(self, refs):
|
|
596
634
|
out = {}
|
|
597
635
|
with self._lock:
|
|
@@ -281,6 +281,38 @@ class HybridBackend(MemoryBackend):
|
|
|
281
281
|
raise BackendError("cannot read the memory")
|
|
282
282
|
raise KeyError(ref)
|
|
283
283
|
|
|
284
|
+
def neighbours(self, ref, limit, timeout=None, ctl=None):
|
|
285
|
+
"""The memories most similar to the stored memory `ref`: every child that has `neighbours` is asked,
|
|
286
|
+
the answers are merged by ref (the higher score wins) and cut to `limit`, best first. A child that
|
|
287
|
+
fails is skipped; with no child that has the method (or none that answers) the answer is []."""
|
|
288
|
+
total = self._timeout if timeout is None else max(0.0, float(timeout))
|
|
289
|
+
end = time.monotonic() + total
|
|
290
|
+
capable = [child for child in self.children if callable(getattr(child, "neighbours", None))]
|
|
291
|
+
# ref -> [highest score, its hit, first text found, first date found]
|
|
292
|
+
best = {}
|
|
293
|
+
for index, child in enumerate(capable):
|
|
294
|
+
left = max(0.0, end - time.monotonic()) / (len(capable) - index)
|
|
295
|
+
try:
|
|
296
|
+
hits = child.neighbours(ref, limit, **_extras(child.neighbours, left, ctl))
|
|
297
|
+
rows = [(h.ref, min(1.0, max(0.0, float(h.score))), h) for h in hits]
|
|
298
|
+
except Exception: # noqa: BLE001 - one failing child must not silence the others
|
|
299
|
+
continue
|
|
300
|
+
for hit_ref, score, hit in rows:
|
|
301
|
+
if hit_ref == ref:
|
|
302
|
+
continue
|
|
303
|
+
entry = best.setdefault(hit_ref, [score, hit, "", None])
|
|
304
|
+
if score > entry[0]:
|
|
305
|
+
entry[0], entry[1] = score, hit
|
|
306
|
+
entry[2] = entry[2] or hit.text
|
|
307
|
+
entry[3] = entry[3] or hit.date
|
|
308
|
+
out = []
|
|
309
|
+
for hit_ref, (score, hit, text, date) in best.items():
|
|
310
|
+
meta = dict(getattr(hit, "meta", None) or {})
|
|
311
|
+
out.append(Hit(ref=hit_ref, score=score, text=text, date=date, meta=meta) if _HAS_META
|
|
312
|
+
else Hit(ref=hit_ref, score=score, text=text, date=date))
|
|
313
|
+
out.sort(key=lambda h: (-h.score, h.ref))
|
|
314
|
+
return out[:max(0, int(limit))]
|
|
315
|
+
|
|
284
316
|
def _first(self, name):
|
|
285
317
|
for child in self.children:
|
|
286
318
|
if hasattr(child, name):
|
|
@@ -733,7 +733,23 @@ def build_parser():
|
|
|
733
733
|
return parser
|
|
734
734
|
|
|
735
735
|
|
|
736
|
+
def _lenient_output():
|
|
737
|
+
"""Let a message that the console cannot write come out with replacement marks.
|
|
738
|
+
|
|
739
|
+
The messages are Chinese. On a console or a pipe in another encoding (cp1252 on a Windows set to a
|
|
740
|
+
Western language) print() raised UnicodeEncodeError, and a command that had done its work ended in
|
|
741
|
+
a traceback with exit code 1. The encoding itself is left alone: setting PYTHONUTF8=1 is the way to
|
|
742
|
+
get readable text there. Streams that cannot be reconfigured (a test's StringIO) are left as they are.
|
|
743
|
+
"""
|
|
744
|
+
for stream in (sys.stdout, sys.stderr):
|
|
745
|
+
try:
|
|
746
|
+
stream.reconfigure(errors="replace")
|
|
747
|
+
except (AttributeError, ValueError, OSError):
|
|
748
|
+
pass
|
|
749
|
+
|
|
750
|
+
|
|
736
751
|
def main(argv=None):
|
|
752
|
+
_lenient_output()
|
|
737
753
|
args = build_parser().parse_args(argv)
|
|
738
754
|
try:
|
|
739
755
|
return args.func(args)
|
|
@@ -133,14 +133,17 @@ class RecallContext:
|
|
|
133
133
|
"""How long a call may wait for a free worker: briefly, never most of the time left."""
|
|
134
134
|
return min(MAX_WAIT, max(self.time_left(), 0.0) / 4)
|
|
135
135
|
|
|
136
|
-
def run(self, fn, store=None):
|
|
136
|
+
def run(self, fn, store=None, until=None):
|
|
137
137
|
"""Run fn(ctl) on the pool and wait until the deadline. Returns (ok, result).
|
|
138
138
|
|
|
139
139
|
When the time runs out the call is cancelled (its socket is shut down, its cancel
|
|
140
140
|
hooks run) and we return at once. Name the `store` the call is for, so the
|
|
141
|
-
per-store cap applies. No free worker counts as not ok.
|
|
141
|
+
per-store cap applies. No free worker counts as not ok. `until` (a time on the
|
|
142
|
+
context's clock) ends the wait earlier than the deadline, for a step that must
|
|
143
|
+
leave time to the stages after it; it never extends the deadline.
|
|
142
144
|
"""
|
|
143
|
-
|
|
145
|
+
end = self.deadline if until is None else min(until, self.deadline)
|
|
146
|
+
outcome, result = call(self.pool, fn, self.clock, end, wait=self.wait_budget(),
|
|
144
147
|
keep=self.keep, slots=self.slots, store=store)
|
|
145
148
|
return outcome == OK, result
|
|
146
149
|
|
|
@@ -7,9 +7,10 @@ import datetime
|
|
|
7
7
|
import math
|
|
8
8
|
|
|
9
9
|
from ..errors import ConfigError
|
|
10
|
+
from ..model import Candidate
|
|
10
11
|
from ..registry import register
|
|
11
12
|
from . import tidy
|
|
12
|
-
from .recall import DEFER, DROP, KEEP, RecallStage
|
|
13
|
+
from .recall import DEFER, DROP, KEEP, RecallStage, _hits
|
|
13
14
|
|
|
14
15
|
PROBE_MARKER = "FEIYU-PROBE-"
|
|
15
16
|
MAX_ITEM_CHARS = 64 * 1024
|
|
@@ -374,9 +375,119 @@ class NewerFirst(RecallStage):
|
|
|
374
375
|
return out
|
|
375
376
|
|
|
376
377
|
|
|
378
|
+
LINKED_TOP = 2
|
|
379
|
+
LINKED_MAX_ADDED = 2
|
|
380
|
+
LINKED_MINIMUM = 0.60
|
|
381
|
+
LINKED_WAIT = 1.0 # seconds all the lookups of one request may take together at most
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
def _whole(value, low, high):
|
|
385
|
+
return isinstance(value, int) and not isinstance(value, bool) and low <= value <= high
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
@register("recall_stage", "linked")
|
|
389
|
+
class Linked(RecallStage):
|
|
390
|
+
"""Add the memories linked to the best ones: one step from what the lines let through.
|
|
391
|
+
|
|
392
|
+
A casual remark ("最近天气有点热") is close to one memory ("主人喜欢吃冰淇淋"), and a second one
|
|
393
|
+
("上次冰淇淋掉在了地上") is close to that memory but not to the remark. After the score lines have
|
|
394
|
+
decided what is delivered, this stage takes the first `top` candidates (in the order the recall will
|
|
395
|
+
deliver them), asks their store for the memories most similar to each (the backend method
|
|
396
|
+
`neighbours`, docs/pieces.md) and appends at most `max_added` of those whose similarity is at least
|
|
397
|
+
`minimum`. It acts after the lines, so it never changes whether the gateway stays quiet: with no
|
|
398
|
+
candidate it does nothing.
|
|
399
|
+
|
|
400
|
+
Rules: only while the number of candidates is below the request's limit (the limit keeps meaning "at
|
|
401
|
+
most this many memories"); a memory that is a candidate already (same store and ref) is not added; a
|
|
402
|
+
memory found from two candidates counts once with its higher similarity; the best similarity first.
|
|
403
|
+
An appended candidate keeps the source and store of the memory it was found from, scores
|
|
404
|
+
`parent score x similarity` (never above the lowest first-hop score, so it stays behind every first-hop
|
|
405
|
+
candidate in the recall's score sort and keeps its own order), and has `meta["linked_from"]` = that
|
|
406
|
+
memory's ref. It then goes through the later stages like any other: texts are read by `fill_text`,
|
|
407
|
+
cleaned by `redact`, and counted by `dedupe` and `budget`. The HTTP answer does not change (no field is
|
|
408
|
+
added). A store without `neighbours`, a timeout or an error in it means nothing is added and one note
|
|
409
|
+
"linked-failed" for the access log (no note for a store that simply has no such method). The lookups go
|
|
410
|
+
through ctx.run like the reads of `fill_text`; together they wait at most 1 second and at most half of the
|
|
411
|
+
time left, so a store that hangs costs the request that much and not the answer it already has.
|
|
412
|
+
|
|
413
|
+
Put it after `min_score`, `relative_score` and `newer_first` (misplaced() reports the opposite order)
|
|
414
|
+
and before `fill_text`. Options: top (default 2, 1..5), max_added (default 2, 0..5; 0 switches the
|
|
415
|
+
stage off), minimum (default 0.60, 0..1; on the store's own 0..1 score scale: 0.60 was measured with
|
|
416
|
+
bge-m3 on the embedding backend, other models use it unmeasured).
|
|
417
|
+
"""
|
|
418
|
+
|
|
419
|
+
after = ("min_score", "relative_score", "newer_first")
|
|
420
|
+
|
|
421
|
+
def __init__(self, top=LINKED_TOP, max_added=LINKED_MAX_ADDED, minimum=LINKED_MINIMUM):
|
|
422
|
+
if not _whole(top, 1, 5):
|
|
423
|
+
raise ConfigError("linked: top must be a whole number from 1 to 5")
|
|
424
|
+
if not _whole(max_added, 0, 5):
|
|
425
|
+
raise ConfigError("linked: max_added must be a whole number from 0 to 5")
|
|
426
|
+
if not _fraction(minimum):
|
|
427
|
+
raise ConfigError("linked: minimum must be a number between 0 and 1")
|
|
428
|
+
self.top = top
|
|
429
|
+
self.max_added = max_added
|
|
430
|
+
self.minimum = float(minimum)
|
|
431
|
+
|
|
432
|
+
def prepare(self, candidates, ctx):
|
|
433
|
+
room = min(self.max_added, ctx.limit - len(candidates))
|
|
434
|
+
if room <= 0 or not candidates:
|
|
435
|
+
return candidates
|
|
436
|
+
try:
|
|
437
|
+
added = self._added(candidates, room, ctx)
|
|
438
|
+
except Exception as error: # noqa: BLE001 - this stage never fails a recall
|
|
439
|
+
ctx.fault("linked-failed", "stage=linked where=prepare error=%s" % type(error).__name__)
|
|
440
|
+
return candidates
|
|
441
|
+
return list(candidates) + added
|
|
442
|
+
|
|
443
|
+
def _added(self, candidates, room, ctx):
|
|
444
|
+
# the order the recall delivers in: best score first, a tie keeps the list order (a stable sort)
|
|
445
|
+
first = sorted(candidates, key=lambda c: -c.score)[:self.top]
|
|
446
|
+
taken = {(id(c.store), c.ref) for c in candidates}
|
|
447
|
+
ask = room + len(candidates) # enough that the memories already taken cannot crowd the others out
|
|
448
|
+
# All the lookups together wait at most this long, and never more than half of what is left: a store
|
|
449
|
+
# that hangs must not take the time the stages after this one (and the first-hop answer) need.
|
|
450
|
+
until = ctx.clock() + min(LINKED_WAIT, max(ctx.time_left(), 0.0) / 2)
|
|
451
|
+
found = {} # (id of store, ref) -> [similarity, order met, parent, hit]
|
|
452
|
+
for parent in first:
|
|
453
|
+
if ctx.clock() >= until:
|
|
454
|
+
break
|
|
455
|
+
if not callable(getattr(parent.store, "neighbours", None)):
|
|
456
|
+
continue
|
|
457
|
+
store = parent.store
|
|
458
|
+
ok, result = ctx.run(
|
|
459
|
+
lambda ctl, s=store, p=parent: s.neighbours(p.ref, ask, max(until - ctx.clock(), 0.05), ctl),
|
|
460
|
+
store=store, until=until)
|
|
461
|
+
hits = _hits(result) if ok else None
|
|
462
|
+
if hits is None:
|
|
463
|
+
ctx.fault("linked-failed", "stage=linked where=neighbours error=%s" % (
|
|
464
|
+
type(result).__name__ if isinstance(result, BaseException) else "no-result"))
|
|
465
|
+
continue
|
|
466
|
+
for hit in hits:
|
|
467
|
+
key = (id(store), hit.ref)
|
|
468
|
+
if key in taken or hit.ref == parent.ref or hit.score < self.minimum:
|
|
469
|
+
continue
|
|
470
|
+
if key not in found:
|
|
471
|
+
found[key] = [hit.score, len(found), parent, hit]
|
|
472
|
+
elif hit.score > found[key][0]:
|
|
473
|
+
found[key][0], found[key][2], found[key][3] = hit.score, parent, hit
|
|
474
|
+
ranked = sorted(found.values(), key=lambda item: (-item[0], item[1]))[:room]
|
|
475
|
+
# Behind every first-hop candidate, and in the order chosen (a later one never scores above an earlier one).
|
|
476
|
+
ceiling = math.nextafter(min(c.score for c in candidates), 0.0)
|
|
477
|
+
out = []
|
|
478
|
+
for similarity, _, parent, hit in ranked:
|
|
479
|
+
ceiling = min(ceiling, parent.score * similarity)
|
|
480
|
+
meta = dict(hit.meta)
|
|
481
|
+
meta["similarity"] = ceiling
|
|
482
|
+
meta["linked_from"] = parent.ref
|
|
483
|
+
out.append(Candidate(score=ceiling, source=parent.source, store=parent.store, ref=hit.ref,
|
|
484
|
+
text=hit.text, date=hit.date, meta=meta))
|
|
485
|
+
return out
|
|
486
|
+
|
|
487
|
+
|
|
377
488
|
def misplaced(stages):
|
|
378
489
|
"""Names of the stages in `stages` that stand before a stage they must come after. Works on
|
|
379
|
-
stage objects (the order of a built gateway);
|
|
490
|
+
stage objects (the order of a built gateway); newer_first and linked declare such a rule, in `after`."""
|
|
380
491
|
problems = []
|
|
381
492
|
for index, stage in enumerate(stages):
|
|
382
493
|
rule = getattr(stage, "after", None)
|
|
@@ -393,6 +504,8 @@ def misplaced(stages):
|
|
|
393
504
|
# a stage that changes scores (source_weight, freshness) goes between the two.
|
|
394
505
|
# newer_first only reorders the candidates that passed both thresholds, so it comes after them; it does
|
|
395
506
|
# nothing for memories without dates.
|
|
507
|
+
# linked acts after the lines (it never changes whether the gateway stays quiet) and before fill_text, so what it
|
|
508
|
+
# appends is read, redacted and counted like any other candidate; it does nothing for stores without `neighbours`.
|
|
396
509
|
# (drop_marker is not a default: add it after fill_text when something writes such markers.)
|
|
397
|
-
DEFAULT_STAGES = ("min_score", "relative_score", "newer_first", "
|
|
398
|
-
"budget")
|
|
510
|
+
DEFAULT_STAGES = ("min_score", "relative_score", "newer_first", "linked", "fill_text", "drop_oversize", "redact",
|
|
511
|
+
"dedupe", "budget")
|
package/src/config.js
CHANGED
|
@@ -162,6 +162,10 @@ const GROUPS = [
|
|
|
162
162
|
en: 'Leave out a memory that an earlier memory block of this conversation still shows, compared by its text. If nothing new is left, no block is added. Off: only a block identical to the previous one is left out.',
|
|
163
163
|
zh: '这个对话里前面的记忆块还留着的记忆,不再给第二次(按记忆的文字比较)。没有新的就不加记忆块。关掉:只有和上一个记忆块完全相同时才不加。',
|
|
164
164
|
}),
|
|
165
|
+
bool('linkedRecall', true, { en: 'Recall linked memories', zh: '顺带想起相连的记忆' }, {
|
|
166
|
+
en: 'With vector retrieval (the endpoint and local tiers, with or without retrieval.hybrid), after the usual lookup the gateway follows the first two memories it found to the memories closest to them and adds at most two, never beyond advanced.recallLimit. Under keyword retrieval it does nothing.',
|
|
167
|
+
zh: '用向量检索时(endpoint 和 local 两档,开不开 retrieval.hybrid 都一样),网关在平常的查找之后,顺着找到的前两条记忆去找和它们最接近的记忆,最多再加两条,总数不超过 advanced.recallLimit。用 keyword 检索时什么都不做。',
|
|
168
|
+
}),
|
|
165
169
|
bool('showAge', true, { en: "Show today's date and each memory's age", zh: '写明今天的日期和每条记忆的时间' }, {
|
|
166
170
|
en: "The memory block says today's date (the date on this computer) and how long ago each dated memory is, for example 3 weeks ago. Off: the block shows only the absolute dates.",
|
|
167
171
|
zh: '记忆块里写明今天的日期(这台电脑上的日期),以及每条有日期的记忆是多久以前的事,例如“3 周前”。关掉:只写具体日期。',
|
package/src/gateway.js
CHANGED
|
@@ -214,6 +214,8 @@ export function gatewayConfig({ port, dataDir, settings, facts = {}, utcOffsetHo
|
|
|
214
214
|
if (policy.forgetting) stages.push('freshness')
|
|
215
215
|
stages.push('relative_score')
|
|
216
216
|
if (policy.newerFirst) stages.push('newer_first')
|
|
217
|
+
// linked comes after the score lines and newer_first, before fill_text (DEFAULT_STAGES in core/stages.py).
|
|
218
|
+
if (policy.linkedRecall) stages.push('linked')
|
|
217
219
|
stages.push('fill_text', 'drop_oversize')
|
|
218
220
|
if (policy.redaction) stages.push('redact')
|
|
219
221
|
stages.push('dedupe', 'budget')
|
package/src/plugin.js
CHANGED
|
@@ -432,7 +432,7 @@ export function createPlugin(ctx, config, deps = {}) {
|
|
|
432
432
|
|
|
433
433
|
// The settings a gateway is built from; any change restarts it. Recall limits and the language are
|
|
434
434
|
// not among them: they are read per call.
|
|
435
|
-
const policyOf = (s) => [s.advanced.profile, s.advanced.dailyWrites, s.advanced.redaction, s.advanced.newerFirst, s.advanced.forgetting]
|
|
435
|
+
const policyOf = (s) => [s.advanced.profile, s.advanced.dailyWrites, s.advanced.redaction, s.advanced.newerFirst, s.advanced.linkedRecall, s.advanced.forgetting]
|
|
436
436
|
function tierKey(s, tier, f) {
|
|
437
437
|
if (tier === 'endpoint') return [s.retrieval.url, s.retrieval.model, s.retrieval.apiKey]
|
|
438
438
|
// The add-on appearing, changing model, restarting its server or going away changes this key.
|