記憶: a page to see it, a few lines picked while typing, a local model
The memory had grown into a list carried whole, a top-14 recalled by a
trigram index and pasted into the system prompt with the clock, and a
page that broke its own layout. Nobody could see what went to the
model, the prompt cache missed every message, and 「記住」 kept saying
the same thing twice. Rebuilt per the spec (docs/memory.md):
- Three kinds in memory.db: 記得的事 (fact), 做過的事 (event, a line per
finished turn), 整理過的 (rollup). Each keeps pinned, uses,
last_used, deleted, superseded_by, span. state.json keeps the facts
as the copy that syncs; the page reads SQLite.
- Search: jieba words ∪ CJK bigrams in an FTS5 unicode61 table
(Traditional text goes through Simplified first), weighted share of
query terms hit; plus local vectors, vec = clamp((cos−0.35)/0.35).
score = max + 0.15×min, events ×0.9. ≥0.15 suggested, ≥0.5 ticked,
≥0.55 carried when nobody chose (3 at most).
- What the model gets: the system prompt has the time zone and the
pinned memories only, the same every turn. Each person message gets
〔送出時間〕 and 〔相關記憶〕 from Message.memories, built in
group_history into a transient Message.context, so the beginning of
a chat reads the same next turn (cache hits) and the event log,
skills and audit see only what was typed. A memory already carried
in view isn't carried again; each carry counts a use.
- Picks travel with the message: Cmd::Send / POST send / sync act
"memories" (empty = none; absent = the brain chooses, once, saved).
- remember finds the like one (cos ≥ 0.85 or the same words) and asks
for `replaces`; the old one is superseded, never carried. A fact
forgotten and remembered again comes back. New search_memory
(query, kind), with dates; read-only.
- Nightly on the brain, no model: events past 30 days fold into a line
per week (「11/3–11/9 做過的事(14 件):整理照片 ×3…」, ≤400 chars,
like with like by words or vectors), weeks past 180 days into months;
the folded go to 最近刪除 for 30 days. Facts are never removed. The
page offers duplicates, facts unused for half a year, and what can
fold now.
- Local model: minishlab/potion-multilingual-128M through m2v.rs (same
token ids as model2vec-rs on 13/13 sentences, cos ≥ 0.9999, without
tokenizers' 1.1 GB). Converted while downloading: vocab.bin,
table.i8 (int8 + row scales), dims.json, 137 MB kept of 530 MB;
ANYBOT_HF_BASE picks a mirror (now passed into the server's brain
container too). Loaded when first needed (34 ms), let go after 10
idle minutes. The brain loads it; a screen only with a document
folder set; hands and phones never. 設定 › 一般 › 語意搜尋:
本機模型/Ollama/關閉; a new engine clears every vector.
- Three files, three connections: memory.db (backed up nightly, 7
kept), docs.db (a cache), oplog/audit.db (30 days). An old audit.db
hands its memories and documents over once and shrinks (a real one:
172 MB → 16 KB). docs_search scans every chunk now, vectors cached
in RAM (it stopped at 8000); FTS optimize + VACUUM daily (260 MB of
tombstones over 31 MB of text).
- API: POST /api/memory (owner) and /api/sync/memory (mirror). Reads
answer on the HTTP thread; writes go through phone_act("memory").
- Screens: a memory dialog (Bot menu 記憶…, Bot settings 打開記憶) with
counts, live search, filters, suggestions, per-item kind/date/uses
and pin/edit/forget/restore; chips above the composer 300 ms after
typing stops, with a token estimate; 「帶了 N 條記憶」 under person
messages. The phone has the same as a 記憶 tab, chips and tag.
Checked: make test passes (app 297, relay 16), with new tests for the
scores and thresholds, Traditional Chinese segmentation, remember's
dedupe and replaces, two turns sending the same beginning, no double
carry, weekly/monthly folding and the trash, and the audit.db move.
Brain idle 37 MB as before, ~230 MB with the model loaded; search on
the brain 0.2–0.5 ms, 7–44 ms from the phone page. A deadlock found on
the way (stats re-taking the lock) is fixed and tested.
Docs: docs/memory.md has the whole design; FEATURES.md, protocol,
architecture (zh/en), multi-device and install say what changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3SYw9JJ9dXwaNvYh4
2026-11-10 23:46:50 +00:00
|
|
|
|
# 記憶怎麼運作
|
|
|
|
|
|
|
2026-11-11 01:35:59 +00:00
|
|
|
|
每個 Bot 有自己的記憶:你要它記住的事,和它幫你做過的事。每個 Bot 只讀寫自己的記憶,看不到別的 Bot 的。這份文件說明記憶存在哪裡、怎麼找、每次送給模型的是什麼,以及怎麼整理。
|
記憶: a page to see it, a few lines picked while typing, a local model
The memory had grown into a list carried whole, a top-14 recalled by a
trigram index and pasted into the system prompt with the clock, and a
page that broke its own layout. Nobody could see what went to the
model, the prompt cache missed every message, and 「記住」 kept saying
the same thing twice. Rebuilt per the spec (docs/memory.md):
- Three kinds in memory.db: 記得的事 (fact), 做過的事 (event, a line per
finished turn), 整理過的 (rollup). Each keeps pinned, uses,
last_used, deleted, superseded_by, span. state.json keeps the facts
as the copy that syncs; the page reads SQLite.
- Search: jieba words ∪ CJK bigrams in an FTS5 unicode61 table
(Traditional text goes through Simplified first), weighted share of
query terms hit; plus local vectors, vec = clamp((cos−0.35)/0.35).
score = max + 0.15×min, events ×0.9. ≥0.15 suggested, ≥0.5 ticked,
≥0.55 carried when nobody chose (3 at most).
- What the model gets: the system prompt has the time zone and the
pinned memories only, the same every turn. Each person message gets
〔送出時間〕 and 〔相關記憶〕 from Message.memories, built in
group_history into a transient Message.context, so the beginning of
a chat reads the same next turn (cache hits) and the event log,
skills and audit see only what was typed. A memory already carried
in view isn't carried again; each carry counts a use.
- Picks travel with the message: Cmd::Send / POST send / sync act
"memories" (empty = none; absent = the brain chooses, once, saved).
- remember finds the like one (cos ≥ 0.85 or the same words) and asks
for `replaces`; the old one is superseded, never carried. A fact
forgotten and remembered again comes back. New search_memory
(query, kind), with dates; read-only.
- Nightly on the brain, no model: events past 30 days fold into a line
per week (「11/3–11/9 做過的事(14 件):整理照片 ×3…」, ≤400 chars,
like with like by words or vectors), weeks past 180 days into months;
the folded go to 最近刪除 for 30 days. Facts are never removed. The
page offers duplicates, facts unused for half a year, and what can
fold now.
- Local model: minishlab/potion-multilingual-128M through m2v.rs (same
token ids as model2vec-rs on 13/13 sentences, cos ≥ 0.9999, without
tokenizers' 1.1 GB). Converted while downloading: vocab.bin,
table.i8 (int8 + row scales), dims.json, 137 MB kept of 530 MB;
ANYBOT_HF_BASE picks a mirror (now passed into the server's brain
container too). Loaded when first needed (34 ms), let go after 10
idle minutes. The brain loads it; a screen only with a document
folder set; hands and phones never. 設定 › 一般 › 語意搜尋:
本機模型/Ollama/關閉; a new engine clears every vector.
- Three files, three connections: memory.db (backed up nightly, 7
kept), docs.db (a cache), oplog/audit.db (30 days). An old audit.db
hands its memories and documents over once and shrinks (a real one:
172 MB → 16 KB). docs_search scans every chunk now, vectors cached
in RAM (it stopped at 8000); FTS optimize + VACUUM daily (260 MB of
tombstones over 31 MB of text).
- API: POST /api/memory (owner) and /api/sync/memory (mirror). Reads
answer on the HTTP thread; writes go through phone_act("memory").
- Screens: a memory dialog (Bot menu 記憶…, Bot settings 打開記憶) with
counts, live search, filters, suggestions, per-item kind/date/uses
and pin/edit/forget/restore; chips above the composer 300 ms after
typing stops, with a token estimate; 「帶了 N 條記憶」 under person
messages. The phone has the same as a 記憶 tab, chips and tag.
Checked: make test passes (app 297, relay 16), with new tests for the
scores and thresholds, Traditional Chinese segmentation, remember's
dedupe and replaces, two turns sending the same beginning, no double
carry, weekly/monthly folding and the trash, and the audit.db move.
Brain idle 37 MB as before, ~230 MB with the model loaded; search on
the brain 0.2–0.5 ms, 7–44 ms from the phone page. A deadlock found on
the way (stats re-taking the lock) is fixed and tested.
Docs: docs/memory.md has the whole design; FEATURES.md, protocol,
architecture (zh/en), multi-device and install say what changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3SYw9JJ9dXwaNvYh4
2026-11-10 23:46:50 +00:00
|
|
|
|
|
|
|
|
|
|
設計的四個原則:
|
|
|
|
|
|
|
|
|
|
|
|
- **少帶**:只帶跟這則訊息有關的幾條,不是全部。
|
|
|
|
|
|
- **看得到**:打字時就看得到會帶哪幾條,可以自己勾選;每則訊息下面標著帶了什麼。
|
|
|
|
|
|
- **在本機做**:斷詞、語意向量、每晚整理都在自己的機器上算,不呼叫模型,什麼都不上傳。
|
|
|
|
|
|
- **快取會中**:同一段聊天,每一回合送給模型的前段都一樣。
|
|
|
|
|
|
|
|
|
|
|
|
程式在這幾個檔:
|
|
|
|
|
|
|
|
|
|
|
|
| 檔案 | 做什麼 |
|
|
|
|
|
|
|---|---|
|
|
|
|
|
|
| `src/memstore.rs` | 記憶庫:存、找、分數、整理建議、每晚整理 |
|
|
|
|
|
|
| `src/memory.rs` | 挑哪幾條帶上、remember/forget/search_memory 工具、記憶頁的 API |
|
|
|
|
|
|
| `src/embed.rs`、`src/m2v.rs` | 語意向量:本機模型的下載、載入、計算 |
|
|
|
|
|
|
| `src/store.rs` | 三個資料庫檔、舊資料搬家、備份、壓縮 |
|
|
|
|
|
|
| `src/app/memory_ui.rs` | 電腦版的記憶頁、輸入框的記憶小卡片、訊息下的標籤 |
|
|
|
|
|
|
| `mobile/index.html` | 手機版的記憶分頁、小卡片、標籤 |
|
|
|
|
|
|
|
|
|
|
|
|
## 三種記憶
|
|
|
|
|
|
|
|
|
|
|
|
| 種類 | 從哪裡來 | 會不會自動刪 |
|
|
|
|
|
|
|---|---|---|
|
|
|
|
|
|
| 記得的事(`fact`) | 你說「記住…」,Bot 用 remember 記下;或在記憶頁自己新增 | 永遠不會 |
|
2026-11-11 01:35:59 +00:00
|
|
|
|
| 做過的事(`event`) | 有動手做事的回合做完自動寫一行,例如「11-08:幫我發一篇 Threads… → 發好了…」 | 30 天後壓成每週一行 |
|
記憶: a page to see it, a few lines picked while typing, a local model
The memory had grown into a list carried whole, a top-14 recalled by a
trigram index and pasted into the system prompt with the clock, and a
page that broke its own layout. Nobody could see what went to the
model, the prompt cache missed every message, and 「記住」 kept saying
the same thing twice. Rebuilt per the spec (docs/memory.md):
- Three kinds in memory.db: 記得的事 (fact), 做過的事 (event, a line per
finished turn), 整理過的 (rollup). Each keeps pinned, uses,
last_used, deleted, superseded_by, span. state.json keeps the facts
as the copy that syncs; the page reads SQLite.
- Search: jieba words ∪ CJK bigrams in an FTS5 unicode61 table
(Traditional text goes through Simplified first), weighted share of
query terms hit; plus local vectors, vec = clamp((cos−0.35)/0.35).
score = max + 0.15×min, events ×0.9. ≥0.15 suggested, ≥0.5 ticked,
≥0.55 carried when nobody chose (3 at most).
- What the model gets: the system prompt has the time zone and the
pinned memories only, the same every turn. Each person message gets
〔送出時間〕 and 〔相關記憶〕 from Message.memories, built in
group_history into a transient Message.context, so the beginning of
a chat reads the same next turn (cache hits) and the event log,
skills and audit see only what was typed. A memory already carried
in view isn't carried again; each carry counts a use.
- Picks travel with the message: Cmd::Send / POST send / sync act
"memories" (empty = none; absent = the brain chooses, once, saved).
- remember finds the like one (cos ≥ 0.85 or the same words) and asks
for `replaces`; the old one is superseded, never carried. A fact
forgotten and remembered again comes back. New search_memory
(query, kind), with dates; read-only.
- Nightly on the brain, no model: events past 30 days fold into a line
per week (「11/3–11/9 做過的事(14 件):整理照片 ×3…」, ≤400 chars,
like with like by words or vectors), weeks past 180 days into months;
the folded go to 最近刪除 for 30 days. Facts are never removed. The
page offers duplicates, facts unused for half a year, and what can
fold now.
- Local model: minishlab/potion-multilingual-128M through m2v.rs (same
token ids as model2vec-rs on 13/13 sentences, cos ≥ 0.9999, without
tokenizers' 1.1 GB). Converted while downloading: vocab.bin,
table.i8 (int8 + row scales), dims.json, 137 MB kept of 530 MB;
ANYBOT_HF_BASE picks a mirror (now passed into the server's brain
container too). Loaded when first needed (34 ms), let go after 10
idle minutes. The brain loads it; a screen only with a document
folder set; hands and phones never. 設定 › 一般 › 語意搜尋:
本機模型/Ollama/關閉; a new engine clears every vector.
- Three files, three connections: memory.db (backed up nightly, 7
kept), docs.db (a cache), oplog/audit.db (30 days). An old audit.db
hands its memories and documents over once and shrinks (a real one:
172 MB → 16 KB). docs_search scans every chunk now, vectors cached
in RAM (it stopped at 8000); FTS optimize + VACUUM daily (260 MB of
tombstones over 31 MB of text).
- API: POST /api/memory (owner) and /api/sync/memory (mirror). Reads
answer on the HTTP thread; writes go through phone_act("memory").
- Screens: a memory dialog (Bot menu 記憶…, Bot settings 打開記憶) with
counts, live search, filters, suggestions, per-item kind/date/uses
and pin/edit/forget/restore; chips above the composer 300 ms after
typing stops, with a token estimate; 「帶了 N 條記憶」 under person
messages. The phone has the same as a 記憶 tab, chips and tag.
Checked: make test passes (app 297, relay 16), with new tests for the
scores and thresholds, Traditional Chinese segmentation, remember's
dedupe and replaces, two turns sending the same beginning, no double
carry, weekly/monthly folding and the trash, and the audit.db move.
Brain idle 37 MB as before, ~230 MB with the model loaded; search on
the brain 0.2–0.5 ms, 7–44 ms from the phone page. A deadlock found on
the way (stats re-taking the lock) is fixed and tested.
Docs: docs/memory.md has the whole design; FEATURES.md, protocol,
architecture (zh/en), multi-device and install say what changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3SYw9JJ9dXwaNvYh4
2026-11-10 23:46:50 +00:00
|
|
|
|
| 整理過的(`rollup`) | 每晚整理產生,例如「11/3–11/9 做過的事(14 件):整理照片 ×3、追蹤 FSD ×5…」 | 每週那行過了 180 天,再壓成每月一行 |
|
|
|
|
|
|
|
|
|
|
|
|
每條記憶另外記錄:
|
|
|
|
|
|
|
|
|
|
|
|
- 有沒有釘選。
|
|
|
|
|
|
- 帶過幾次、上次帶入的時間。
|
|
|
|
|
|
- 刪除時間(在「最近刪除」裡時)。
|
|
|
|
|
|
- 被哪一條取代。
|
|
|
|
|
|
- 涵蓋的期間(整理過的那幾條才有)。
|
|
|
|
|
|
|
|
|
|
|
|
「記得的事」每個 Bot 最多 200 條、每條最多 500 字。
|
|
|
|
|
|
|
2026-11-11 01:35:59 +00:00
|
|
|
|
**做過的事只記有做事的回合**:這一回合有改變東西的步驟(改檔案、發文、填表、設定、建例行任務…),或查資料查了 5 步以上,才寫一行。閒聊、簡單問答、查一次資料不記。
|
|
|
|
|
|
|
記憶: a page to see it, a few lines picked while typing, a local model
The memory had grown into a list carried whole, a top-14 recalled by a
trigram index and pasted into the system prompt with the clock, and a
page that broke its own layout. Nobody could see what went to the
model, the prompt cache missed every message, and 「記住」 kept saying
the same thing twice. Rebuilt per the spec (docs/memory.md):
- Three kinds in memory.db: 記得的事 (fact), 做過的事 (event, a line per
finished turn), 整理過的 (rollup). Each keeps pinned, uses,
last_used, deleted, superseded_by, span. state.json keeps the facts
as the copy that syncs; the page reads SQLite.
- Search: jieba words ∪ CJK bigrams in an FTS5 unicode61 table
(Traditional text goes through Simplified first), weighted share of
query terms hit; plus local vectors, vec = clamp((cos−0.35)/0.35).
score = max + 0.15×min, events ×0.9. ≥0.15 suggested, ≥0.5 ticked,
≥0.55 carried when nobody chose (3 at most).
- What the model gets: the system prompt has the time zone and the
pinned memories only, the same every turn. Each person message gets
〔送出時間〕 and 〔相關記憶〕 from Message.memories, built in
group_history into a transient Message.context, so the beginning of
a chat reads the same next turn (cache hits) and the event log,
skills and audit see only what was typed. A memory already carried
in view isn't carried again; each carry counts a use.
- Picks travel with the message: Cmd::Send / POST send / sync act
"memories" (empty = none; absent = the brain chooses, once, saved).
- remember finds the like one (cos ≥ 0.85 or the same words) and asks
for `replaces`; the old one is superseded, never carried. A fact
forgotten and remembered again comes back. New search_memory
(query, kind), with dates; read-only.
- Nightly on the brain, no model: events past 30 days fold into a line
per week (「11/3–11/9 做過的事(14 件):整理照片 ×3…」, ≤400 chars,
like with like by words or vectors), weeks past 180 days into months;
the folded go to 最近刪除 for 30 days. Facts are never removed. The
page offers duplicates, facts unused for half a year, and what can
fold now.
- Local model: minishlab/potion-multilingual-128M through m2v.rs (same
token ids as model2vec-rs on 13/13 sentences, cos ≥ 0.9999, without
tokenizers' 1.1 GB). Converted while downloading: vocab.bin,
table.i8 (int8 + row scales), dims.json, 137 MB kept of 530 MB;
ANYBOT_HF_BASE picks a mirror (now passed into the server's brain
container too). Loaded when first needed (34 ms), let go after 10
idle minutes. The brain loads it; a screen only with a document
folder set; hands and phones never. 設定 › 一般 › 語意搜尋:
本機模型/Ollama/關閉; a new engine clears every vector.
- Three files, three connections: memory.db (backed up nightly, 7
kept), docs.db (a cache), oplog/audit.db (30 days). An old audit.db
hands its memories and documents over once and shrinks (a real one:
172 MB → 16 KB). docs_search scans every chunk now, vectors cached
in RAM (it stopped at 8000); FTS optimize + VACUUM daily (260 MB of
tombstones over 31 MB of text).
- API: POST /api/memory (owner) and /api/sync/memory (mirror). Reads
answer on the HTTP thread; writes go through phone_act("memory").
- Screens: a memory dialog (Bot menu 記憶…, Bot settings 打開記憶) with
counts, live search, filters, suggestions, per-item kind/date/uses
and pin/edit/forget/restore; chips above the composer 300 ms after
typing stops, with a token estimate; 「帶了 N 條記憶」 under person
messages. The phone has the same as a 記憶 tab, chips and tag.
Checked: make test passes (app 297, relay 16), with new tests for the
scores and thresholds, Traditional Chinese segmentation, remember's
dedupe and replaces, two turns sending the same beginning, no double
carry, weekly/monthly folding and the trash, and the audit.db move.
Brain idle 37 MB as before, ~230 MB with the model loaded; search on
the brain 0.2–0.5 ms, 7–44 ms from the phone page. A deadlock found on
the way (stats re-taking the lock) is fixed and tested.
Docs: docs/memory.md has the whole design; FEATURES.md, protocol,
architecture (zh/en), multi-device and install say what changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3SYw9JJ9dXwaNvYh4
2026-11-10 23:46:50 +00:00
|
|
|
|
## 存在哪裡
|
|
|
|
|
|
|
|
|
|
|
|
| 檔案(在 AnyBot 資料夾裡) | 內容 |
|
|
|
|
|
|
|---|---|
|
|
|
|
|
|
| `memory.db` | 記憶、斷詞索引、向量。最重要的一個:每晚在 `backups/memory-日期.db` 留一份,保留 7 天 |
|
|
|
|
|
|
| `docs.db` | 文件索引(文件資料夾的段落和向量)。是快取,刪掉會重建 |
|
|
|
|
|
|
| `oplog/audit.db` | 稽核紀錄,留 30 天 |
|
|
|
|
|
|
| `models/potion-multilingual-128M/` | 本機語意模型 |
|
|
|
|
|
|
|
|
|
|
|
|
- 三個檔各用自己的連線。背景算向量、每晚整理、寫稽核紀錄時,打字搜尋不用等。
|
|
|
|
|
|
- `state.json` 裡每個 Bot 的 `memories` 是「記得的事」的副本,給螢幕同步、匯出和帳號備份用。記憶頁以 `memory.db` 為準。
|
|
|
|
|
|
- 斷詞索引是 FTS5 表 `memories_words`(`unicode61`,rowid 就是記憶的 id)。向量存在記憶那一列。用的是哪個引擎記在 `meta` 表的 `embed_engine`。
|
|
|
|
|
|
- 每台每天整理一次資料庫:重整全文索引,空出來的空間超過 16 MB 時 VACUUM。文件刪掉後全文索引會留下痕跡,以前曾經讓 31 MB 的內容佔掉 260 MB。
|
|
|
|
|
|
|
|
|
|
|
|
**從舊版搬過來**:舊版把記憶和文件索引放在 `audit.db`。新版第一次啟動時,會把這兩部分搬到 `memory.db` 和 `docs.db`,然後刪掉舊表、縮小檔案。用一台實際在用的 Mac 試過,`audit.db` 從 172 MB 變成 16 KB。
|
|
|
|
|
|
|
|
|
|
|
|
## 怎麼找
|
|
|
|
|
|
|
|
|
|
|
|
每條記憶算兩個 0 到 1 的分數,再合成一個。
|
|
|
|
|
|
|
|
|
|
|
|
### 文字分數
|
|
|
|
|
|
|
|
|
|
|
|
- **索引**:jieba 切出來的詞,加上所有中文連續兩字。繁體會先轉成簡體再切,因為 jieba 的字典是簡體。jieba 對繁體常用詞切得對(靠窗、週五、台南),但會切錯一些(長途、記憶頁面),連續兩字可以補上這些。
|
|
|
|
|
|
- **查詢詞**:jieba 從你打的字切出來的詞。
|
|
|
|
|
|
- 中文至少 2 個字,英文至少 2 個字母。
|
|
|
|
|
|
- 去掉停用詞(幫我、一下、可以、什麼、沒有…)。
|
|
|
|
|
|
- 3 個字以上的詞,再加上它裡面的兩字詞,權重較低。
|
|
|
|
|
|
- 越少見的詞權重越高(IDF),長的詞也稍微重一點。
|
|
|
|
|
|
- **分數**:命中的查詢詞佔全部查詢詞的比例(照權重算)。
|
|
|
|
|
|
|
|
|
|
|
|
### 語意分數
|
|
|
|
|
|
|
|
|
|
|
|
- 用本機模型把你打的字和每條記憶各算成一個 256 維的向量,再算相似度(cos)。
|
|
|
|
|
|
- 這個模型的分數很集中:相關的大約 0.35–0.45,不相關的 0.13–0.32。所以換算成:
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
語意 = clamp((cos − 0.35) / 0.35, 0, 1)
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 總分和門檻
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
總分 = max(文字, 語意) + 0.15 × min(文字, 語意)
|
|
|
|
|
|
做過的事、整理過的:總分 × 0.9
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
| 總分 | 用在哪 |
|
|
|
|
|
|
|---|---|
|
|
|
|
|
|
| ≥ 0.15 | 列成建議,最多 8 條 |
|
|
|
|
|
|
| ≥ 0.5 | 建議裡預先勾好 |
|
|
|
|
|
|
| ≥ 0.55 | 沒人選的時候自動帶上,最多 3 條 |
|
|
|
|
|
|
|
|
|
|
|
|
釘選的、被取代的、在「最近刪除」裡的,都不會出現在建議裡(釘選的本來就每次都帶)。
|
|
|
|
|
|
|
2026-11-11 01:35:59 +00:00
|
|
|
|
整句剛好出現在某條記憶裡時直接給滿分,但只限這句話有實際的詞。「謝謝」「繼續」「好的」這類應答詞不算,否則會把以前每一次說「謝謝」的做過的事都帶上。記憶頁的搜尋框不受這個限制,打什麼就找什麼。
|
|
|
|
|
|
|
記憶: a page to see it, a few lines picked while typing, a local model
The memory had grown into a list carried whole, a top-14 recalled by a
trigram index and pasted into the system prompt with the clock, and a
page that broke its own layout. Nobody could see what went to the
model, the prompt cache missed every message, and 「記住」 kept saying
the same thing twice. Rebuilt per the spec (docs/memory.md):
- Three kinds in memory.db: 記得的事 (fact), 做過的事 (event, a line per
finished turn), 整理過的 (rollup). Each keeps pinned, uses,
last_used, deleted, superseded_by, span. state.json keeps the facts
as the copy that syncs; the page reads SQLite.
- Search: jieba words ∪ CJK bigrams in an FTS5 unicode61 table
(Traditional text goes through Simplified first), weighted share of
query terms hit; plus local vectors, vec = clamp((cos−0.35)/0.35).
score = max + 0.15×min, events ×0.9. ≥0.15 suggested, ≥0.5 ticked,
≥0.55 carried when nobody chose (3 at most).
- What the model gets: the system prompt has the time zone and the
pinned memories only, the same every turn. Each person message gets
〔送出時間〕 and 〔相關記憶〕 from Message.memories, built in
group_history into a transient Message.context, so the beginning of
a chat reads the same next turn (cache hits) and the event log,
skills and audit see only what was typed. A memory already carried
in view isn't carried again; each carry counts a use.
- Picks travel with the message: Cmd::Send / POST send / sync act
"memories" (empty = none; absent = the brain chooses, once, saved).
- remember finds the like one (cos ≥ 0.85 or the same words) and asks
for `replaces`; the old one is superseded, never carried. A fact
forgotten and remembered again comes back. New search_memory
(query, kind), with dates; read-only.
- Nightly on the brain, no model: events past 30 days fold into a line
per week (「11/3–11/9 做過的事(14 件):整理照片 ×3…」, ≤400 chars,
like with like by words or vectors), weeks past 180 days into months;
the folded go to 最近刪除 for 30 days. Facts are never removed. The
page offers duplicates, facts unused for half a year, and what can
fold now.
- Local model: minishlab/potion-multilingual-128M through m2v.rs (same
token ids as model2vec-rs on 13/13 sentences, cos ≥ 0.9999, without
tokenizers' 1.1 GB). Converted while downloading: vocab.bin,
table.i8 (int8 + row scales), dims.json, 137 MB kept of 530 MB;
ANYBOT_HF_BASE picks a mirror (now passed into the server's brain
container too). Loaded when first needed (34 ms), let go after 10
idle minutes. The brain loads it; a screen only with a document
folder set; hands and phones never. 設定 › 一般 › 語意搜尋:
本機模型/Ollama/關閉; a new engine clears every vector.
- Three files, three connections: memory.db (backed up nightly, 7
kept), docs.db (a cache), oplog/audit.db (30 days). An old audit.db
hands its memories and documents over once and shrinks (a real one:
172 MB → 16 KB). docs_search scans every chunk now, vectors cached
in RAM (it stopped at 8000); FTS optimize + VACUUM daily (260 MB of
tombstones over 31 MB of text).
- API: POST /api/memory (owner) and /api/sync/memory (mirror). Reads
answer on the HTTP thread; writes go through phone_act("memory").
- Screens: a memory dialog (Bot menu 記憶…, Bot settings 打開記憶) with
counts, live search, filters, suggestions, per-item kind/date/uses
and pin/edit/forget/restore; chips above the composer 300 ms after
typing stops, with a token estimate; 「帶了 N 條記憶」 under person
messages. The phone has the same as a 記憶 tab, chips and tag.
Checked: make test passes (app 297, relay 16), with new tests for the
scores and thresholds, Traditional Chinese segmentation, remember's
dedupe and replaces, two turns sending the same beginning, no double
carry, weekly/monthly folding and the trash, and the audit.db move.
Brain idle 37 MB as before, ~230 MB with the model loaded; search on
the brain 0.2–0.5 ms, 7–44 ms from the phone page. A deadlock found on
the way (stats re-taking the lock) is fixed and tested.
Docs: docs/memory.md has the whole design; FEATURES.md, protocol,
architecture (zh/en), multi-device and install say what changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3SYw9JJ9dXwaNvYh4
2026-11-10 23:46:50 +00:00
|
|
|
|
## 每次送給模型的內容
|
|
|
|
|
|
|
|
|
|
|
|
### 系統指示(每次都一樣)
|
|
|
|
|
|
|
|
|
|
|
|
- 只放使用者的時區,不放現在幾點。現在幾點看訊息後面的〔送出時間〕。
|
|
|
|
|
|
- 釘選的記憶(核心記憶)。
|
|
|
|
|
|
- 說明訊息後面的〔送出時間〕和〔相關記憶〕是什麼,以及不夠時用 search_memory 查。
|
|
|
|
|
|
|
|
|
|
|
|
### 每則你的訊息後面
|
|
|
|
|
|
|
|
|
|
|
|
送給模型時,每則你的訊息後面會接上一小段:
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
VPN 連不上了,怎麼辦
|
|
|
|
|
|
〔送出時間:2026-11-11(週三)10:00〕
|
|
|
|
|
|
〔相關記憶(AnyBot 依這則訊息找出來的,不一定都用得上):
|
|
|
|
|
|
- 公司的 VPN 用 Tailscale,伺服器在 10.0.0.25〕
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
- 這段在 `group_history` 組,放在不存檔的 `Message.context`,送出時才接上。事件記錄、技能學習、稽核看到的都只有你打的字。
|
2026-11-11 01:35:59 +00:00
|
|
|
|
- 隔了 10 分鐘以上才回覆的訊息(隔天按「重新產生」、中斷後接續),最後一則後面會多一行〔現在時間:…〕,模型以它為準。
|
記憶: a page to see it, a few lines picked while typing, a local model
The memory had grown into a list carried whole, a top-14 recalled by a
trigram index and pasted into the system prompt with the clock, and a
page that broke its own layout. Nobody could see what went to the
model, the prompt cache missed every message, and 「記住」 kept saying
the same thing twice. Rebuilt per the spec (docs/memory.md):
- Three kinds in memory.db: 記得的事 (fact), 做過的事 (event, a line per
finished turn), 整理過的 (rollup). Each keeps pinned, uses,
last_used, deleted, superseded_by, span. state.json keeps the facts
as the copy that syncs; the page reads SQLite.
- Search: jieba words ∪ CJK bigrams in an FTS5 unicode61 table
(Traditional text goes through Simplified first), weighted share of
query terms hit; plus local vectors, vec = clamp((cos−0.35)/0.35).
score = max + 0.15×min, events ×0.9. ≥0.15 suggested, ≥0.5 ticked,
≥0.55 carried when nobody chose (3 at most).
- What the model gets: the system prompt has the time zone and the
pinned memories only, the same every turn. Each person message gets
〔送出時間〕 and 〔相關記憶〕 from Message.memories, built in
group_history into a transient Message.context, so the beginning of
a chat reads the same next turn (cache hits) and the event log,
skills and audit see only what was typed. A memory already carried
in view isn't carried again; each carry counts a use.
- Picks travel with the message: Cmd::Send / POST send / sync act
"memories" (empty = none; absent = the brain chooses, once, saved).
- remember finds the like one (cos ≥ 0.85 or the same words) and asks
for `replaces`; the old one is superseded, never carried. A fact
forgotten and remembered again comes back. New search_memory
(query, kind), with dates; read-only.
- Nightly on the brain, no model: events past 30 days fold into a line
per week (「11/3–11/9 做過的事(14 件):整理照片 ×3…」, ≤400 chars,
like with like by words or vectors), weeks past 180 days into months;
the folded go to 最近刪除 for 30 days. Facts are never removed. The
page offers duplicates, facts unused for half a year, and what can
fold now.
- Local model: minishlab/potion-multilingual-128M through m2v.rs (same
token ids as model2vec-rs on 13/13 sentences, cos ≥ 0.9999, without
tokenizers' 1.1 GB). Converted while downloading: vocab.bin,
table.i8 (int8 + row scales), dims.json, 137 MB kept of 530 MB;
ANYBOT_HF_BASE picks a mirror (now passed into the server's brain
container too). Loaded when first needed (34 ms), let go after 10
idle minutes. The brain loads it; a screen only with a document
folder set; hands and phones never. 設定 › 一般 › 語意搜尋:
本機模型/Ollama/關閉; a new engine clears every vector.
- Three files, three connections: memory.db (backed up nightly, 7
kept), docs.db (a cache), oplog/audit.db (30 days). An old audit.db
hands its memories and documents over once and shrinks (a real one:
172 MB → 16 KB). docs_search scans every chunk now, vectors cached
in RAM (it stopped at 8000); FTS optimize + VACUUM daily (260 MB of
tombstones over 31 MB of text).
- API: POST /api/memory (owner) and /api/sync/memory (mirror). Reads
answer on the HTTP thread; writes go through phone_act("memory").
- Screens: a memory dialog (Bot menu 記憶…, Bot settings 打開記憶) with
counts, live search, filters, suggestions, per-item kind/date/uses
and pin/edit/forget/restore; chips above the composer 300 ms after
typing stops, with a token estimate; 「帶了 N 條記憶」 under person
messages. The phone has the same as a 記憶 tab, chips and tag.
Checked: make test passes (app 297, relay 16), with new tests for the
scores and thresholds, Traditional Chinese segmentation, remember's
dedupe and replaces, two turns sending the same beginning, no double
carry, weekly/monthly folding and the trash, and the audit.db move.
Brain idle 37 MB as before, ~230 MB with the model loaded; search on
the brain 0.2–0.5 ms, 7–44 ms from the phone page. A deadlock found on
the way (stats re-taking the lock) is fixed and tested.
Docs: docs/memory.md has the whole design; FEATURES.md, protocol,
architecture (zh/en), multi-device and install say what changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3SYw9JJ9dXwaNvYh4
2026-11-10 23:46:50 +00:00
|
|
|
|
- 送出時間用的是訊息自己的時間,記憶用的是存在訊息上的 `Message.memories`,兩個都不會再變。所以同一段聊天下一回合再送,前段一個字都不差,模型服務的提示快取會中。
|
|
|
|
|
|
|
|
|
|
|
|
### 哪幾條記憶跟著這則訊息
|
|
|
|
|
|
|
|
|
|
|
|
開始回覆時決定,決定後存回訊息(`memories`,以及 `memories_set` 表示選過了),之後不再改:
|
|
|
|
|
|
|
2026-11-11 01:35:59 +00:00
|
|
|
|
1. 你在輸入框勾過,就照你勾的,連「全部拿掉」也算。只收這個 Bot 真的有的記憶,其他文字會被丟掉。
|
記憶: a page to see it, a few lines picked while typing, a local model
The memory had grown into a list carried whole, a top-14 recalled by a
trigram index and pasted into the system prompt with the clock, and a
page that broke its own layout. Nobody could see what went to the
model, the prompt cache missed every message, and 「記住」 kept saying
the same thing twice. Rebuilt per the spec (docs/memory.md):
- Three kinds in memory.db: 記得的事 (fact), 做過的事 (event, a line per
finished turn), 整理過的 (rollup). Each keeps pinned, uses,
last_used, deleted, superseded_by, span. state.json keeps the facts
as the copy that syncs; the page reads SQLite.
- Search: jieba words ∪ CJK bigrams in an FTS5 unicode61 table
(Traditional text goes through Simplified first), weighted share of
query terms hit; plus local vectors, vec = clamp((cos−0.35)/0.35).
score = max + 0.15×min, events ×0.9. ≥0.15 suggested, ≥0.5 ticked,
≥0.55 carried when nobody chose (3 at most).
- What the model gets: the system prompt has the time zone and the
pinned memories only, the same every turn. Each person message gets
〔送出時間〕 and 〔相關記憶〕 from Message.memories, built in
group_history into a transient Message.context, so the beginning of
a chat reads the same next turn (cache hits) and the event log,
skills and audit see only what was typed. A memory already carried
in view isn't carried again; each carry counts a use.
- Picks travel with the message: Cmd::Send / POST send / sync act
"memories" (empty = none; absent = the brain chooses, once, saved).
- remember finds the like one (cos ≥ 0.85 or the same words) and asks
for `replaces`; the old one is superseded, never carried. A fact
forgotten and remembered again comes back. New search_memory
(query, kind), with dates; read-only.
- Nightly on the brain, no model: events past 30 days fold into a line
per week (「11/3–11/9 做過的事(14 件):整理照片 ×3…」, ≤400 chars,
like with like by words or vectors), weeks past 180 days into months;
the folded go to 最近刪除 for 30 days. Facts are never removed. The
page offers duplicates, facts unused for half a year, and what can
fold now.
- Local model: minishlab/potion-multilingual-128M through m2v.rs (same
token ids as model2vec-rs on 13/13 sentences, cos ≥ 0.9999, without
tokenizers' 1.1 GB). Converted while downloading: vocab.bin,
table.i8 (int8 + row scales), dims.json, 137 MB kept of 530 MB;
ANYBOT_HF_BASE picks a mirror (now passed into the server's brain
container too). Loaded when first needed (34 ms), let go after 10
idle minutes. The brain loads it; a screen only with a document
folder set; hands and phones never. 設定 › 一般 › 語意搜尋:
本機模型/Ollama/關閉; a new engine clears every vector.
- Three files, three connections: memory.db (backed up nightly, 7
kept), docs.db (a cache), oplog/audit.db (30 days). An old audit.db
hands its memories and documents over once and shrinks (a real one:
172 MB → 16 KB). docs_search scans every chunk now, vectors cached
in RAM (it stopped at 8000); FTS optimize + VACUUM daily (260 MB of
tombstones over 31 MB of text).
- API: POST /api/memory (owner) and /api/sync/memory (mirror). Reads
answer on the HTTP thread; writes go through phone_act("memory").
- Screens: a memory dialog (Bot menu 記憶…, Bot settings 打開記憶) with
counts, live search, filters, suggestions, per-item kind/date/uses
and pin/edit/forget/restore; chips above the composer 300 ms after
typing stops, with a token estimate; 「帶了 N 條記憶」 under person
messages. The phone has the same as a 記憶 tab, chips and tag.
Checked: make test passes (app 297, relay 16), with new tests for the
scores and thresholds, Traditional Chinese segmentation, remember's
dedupe and replaces, two turns sending the same beginning, no double
carry, weekly/monthly folding and the trash, and the audit.db move.
Brain idle 37 MB as before, ~230 MB with the model loaded; search on
the brain 0.2–0.5 ms, 7–44 ms from the phone page. A deadlock found on
the way (stats re-taking the lock) is fixed and tested.
Docs: docs/memory.md has the whole design; FEATURES.md, protocol,
architecture (zh/en), multi-device and install say what changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3SYw9JJ9dXwaNvYh4
2026-11-10 23:46:50 +00:00
|
|
|
|
2. 沒人勾過(手機沒等到卡片、例行任務、訊息管道),大腦自己挑:總分 ≥ 0.55,最多 3 條。
|
|
|
|
|
|
3. 目前看得到的歷史(最新的摘要之後)裡已經帶過的,不再重複帶。
|
|
|
|
|
|
4. 每帶一次,那條的「帶過幾次」加 1,「上次帶入」更新。
|
|
|
|
|
|
|
|
|
|
|
|
## 工具
|
|
|
|
|
|
|
|
|
|
|
|
| 工具 | 做什麼 |
|
|
|
|
|
|
|---|---|
|
2026-11-11 01:35:59 +00:00
|
|
|
|
| `remember(fact, replaces?, separate?)` | 記住一件事 |
|
|
|
|
|
|
| `forget(what)` | 忘記一件記得的事,放進「最近刪除」,30 天內可以還原。不會動到做過的事 |
|
記憶: a page to see it, a few lines picked while typing, a local model
The memory had grown into a list carried whole, a top-14 recalled by a
trigram index and pasted into the system prompt with the clock, and a
page that broke its own layout. Nobody could see what went to the
model, the prompt cache missed every message, and 「記住」 kept saying
the same thing twice. Rebuilt per the spec (docs/memory.md):
- Three kinds in memory.db: 記得的事 (fact), 做過的事 (event, a line per
finished turn), 整理過的 (rollup). Each keeps pinned, uses,
last_used, deleted, superseded_by, span. state.json keeps the facts
as the copy that syncs; the page reads SQLite.
- Search: jieba words ∪ CJK bigrams in an FTS5 unicode61 table
(Traditional text goes through Simplified first), weighted share of
query terms hit; plus local vectors, vec = clamp((cos−0.35)/0.35).
score = max + 0.15×min, events ×0.9. ≥0.15 suggested, ≥0.5 ticked,
≥0.55 carried when nobody chose (3 at most).
- What the model gets: the system prompt has the time zone and the
pinned memories only, the same every turn. Each person message gets
〔送出時間〕 and 〔相關記憶〕 from Message.memories, built in
group_history into a transient Message.context, so the beginning of
a chat reads the same next turn (cache hits) and the event log,
skills and audit see only what was typed. A memory already carried
in view isn't carried again; each carry counts a use.
- Picks travel with the message: Cmd::Send / POST send / sync act
"memories" (empty = none; absent = the brain chooses, once, saved).
- remember finds the like one (cos ≥ 0.85 or the same words) and asks
for `replaces`; the old one is superseded, never carried. A fact
forgotten and remembered again comes back. New search_memory
(query, kind), with dates; read-only.
- Nightly on the brain, no model: events past 30 days fold into a line
per week (「11/3–11/9 做過的事(14 件):整理照片 ×3…」, ≤400 chars,
like with like by words or vectors), weeks past 180 days into months;
the folded go to 最近刪除 for 30 days. Facts are never removed. The
page offers duplicates, facts unused for half a year, and what can
fold now.
- Local model: minishlab/potion-multilingual-128M through m2v.rs (same
token ids as model2vec-rs on 13/13 sentences, cos ≥ 0.9999, without
tokenizers' 1.1 GB). Converted while downloading: vocab.bin,
table.i8 (int8 + row scales), dims.json, 137 MB kept of 530 MB;
ANYBOT_HF_BASE picks a mirror (now passed into the server's brain
container too). Loaded when first needed (34 ms), let go after 10
idle minutes. The brain loads it; a screen only with a document
folder set; hands and phones never. 設定 › 一般 › 語意搜尋:
本機模型/Ollama/關閉; a new engine clears every vector.
- Three files, three connections: memory.db (backed up nightly, 7
kept), docs.db (a cache), oplog/audit.db (30 days). An old audit.db
hands its memories and documents over once and shrinks (a real one:
172 MB → 16 KB). docs_search scans every chunk now, vectors cached
in RAM (it stopped at 8000); FTS optimize + VACUUM daily (260 MB of
tombstones over 31 MB of text).
- API: POST /api/memory (owner) and /api/sync/memory (mirror). Reads
answer on the HTTP thread; writes go through phone_act("memory").
- Screens: a memory dialog (Bot menu 記憶…, Bot settings 打開記憶) with
counts, live search, filters, suggestions, per-item kind/date/uses
and pin/edit/forget/restore; chips above the composer 300 ms after
typing stops, with a token estimate; 「帶了 N 條記憶」 under person
messages. The phone has the same as a 記憶 tab, chips and tag.
Checked: make test passes (app 297, relay 16), with new tests for the
scores and thresholds, Traditional Chinese segmentation, remember's
dedupe and replaces, two turns sending the same beginning, no double
carry, weekly/monthly folding and the trash, and the audit.db move.
Brain idle 37 MB as before, ~230 MB with the model loaded; search on
the brain 0.2–0.5 ms, 7–44 ms from the phone page. A deadlock found on
the way (stats re-taking the lock) is fixed and tested.
Docs: docs/memory.md has the whole design; FEATURES.md, protocol,
architecture (zh/en), multi-device and install say what changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3SYw9JJ9dXwaNvYh4
2026-11-10 23:46:50 +00:00
|
|
|
|
| `search_memory(query, kind?)` | 翻記憶。`kind` 是 `all`、`fact` 或 `event`。回傳的每條都附日期。只是看,不用核准 |
|
|
|
|
|
|
|
2026-11-11 01:35:59 +00:00
|
|
|
|
**要不要記由 Bot 自己判斷,不問你。** 系統指示告訴它:
|
|
|
|
|
|
|
|
|
|
|
|
- 像人一樣:重要的記,小事不記。要記的是你教它的和你告訴它的、之後還用得到的事。不用等你說「記住」。
|
|
|
|
|
|
- 你教它怎麼操作或怎麼做一件事:步驟多的存成技能(save_skill),一句話講得完的規則用 remember。
|
|
|
|
|
|
- 你告訴它的事:偏好和習慣、關於你和身邊的人的事實、說定的做法和決定。
|
|
|
|
|
|
- 你糾正它的地方。
|
|
|
|
|
|
- 不確定重不重要就不記。閒聊、隨口問的問題、只有這次用得到的、一次性的要求、它自己做了什麼、從記憶裡讀到的、猜的,都不記。
|
|
|
|
|
|
- 不問「要我記下來嗎」。記了只在回答最後帶一句「(記下了:…)」。
|
|
|
|
|
|
|
記憶: a page to see it, a few lines picked while typing, a local model
The memory had grown into a list carried whole, a top-14 recalled by a
trigram index and pasted into the system prompt with the clock, and a
page that broke its own layout. Nobody could see what went to the
model, the prompt cache missed every message, and 「記住」 kept saying
the same thing twice. Rebuilt per the spec (docs/memory.md):
- Three kinds in memory.db: 記得的事 (fact), 做過的事 (event, a line per
finished turn), 整理過的 (rollup). Each keeps pinned, uses,
last_used, deleted, superseded_by, span. state.json keeps the facts
as the copy that syncs; the page reads SQLite.
- Search: jieba words ∪ CJK bigrams in an FTS5 unicode61 table
(Traditional text goes through Simplified first), weighted share of
query terms hit; plus local vectors, vec = clamp((cos−0.35)/0.35).
score = max + 0.15×min, events ×0.9. ≥0.15 suggested, ≥0.5 ticked,
≥0.55 carried when nobody chose (3 at most).
- What the model gets: the system prompt has the time zone and the
pinned memories only, the same every turn. Each person message gets
〔送出時間〕 and 〔相關記憶〕 from Message.memories, built in
group_history into a transient Message.context, so the beginning of
a chat reads the same next turn (cache hits) and the event log,
skills and audit see only what was typed. A memory already carried
in view isn't carried again; each carry counts a use.
- Picks travel with the message: Cmd::Send / POST send / sync act
"memories" (empty = none; absent = the brain chooses, once, saved).
- remember finds the like one (cos ≥ 0.85 or the same words) and asks
for `replaces`; the old one is superseded, never carried. A fact
forgotten and remembered again comes back. New search_memory
(query, kind), with dates; read-only.
- Nightly on the brain, no model: events past 30 days fold into a line
per week (「11/3–11/9 做過的事(14 件):整理照片 ×3…」, ≤400 chars,
like with like by words or vectors), weeks past 180 days into months;
the folded go to 最近刪除 for 30 days. Facts are never removed. The
page offers duplicates, facts unused for half a year, and what can
fold now.
- Local model: minishlab/potion-multilingual-128M through m2v.rs (same
token ids as model2vec-rs on 13/13 sentences, cos ≥ 0.9999, without
tokenizers' 1.1 GB). Converted while downloading: vocab.bin,
table.i8 (int8 + row scales), dims.json, 137 MB kept of 530 MB;
ANYBOT_HF_BASE picks a mirror (now passed into the server's brain
container too). Loaded when first needed (34 ms), let go after 10
idle minutes. The brain loads it; a screen only with a document
folder set; hands and phones never. 設定 › 一般 › 語意搜尋:
本機模型/Ollama/關閉; a new engine clears every vector.
- Three files, three connections: memory.db (backed up nightly, 7
kept), docs.db (a cache), oplog/audit.db (30 days). An old audit.db
hands its memories and documents over once and shrinks (a real one:
172 MB → 16 KB). docs_search scans every chunk now, vectors cached
in RAM (it stopped at 8000); FTS optimize + VACUUM daily (260 MB of
tombstones over 31 MB of text).
- API: POST /api/memory (owner) and /api/sync/memory (mirror). Reads
answer on the HTTP thread; writes go through phone_act("memory").
- Screens: a memory dialog (Bot menu 記憶…, Bot settings 打開記憶) with
counts, live search, filters, suggestions, per-item kind/date/uses
and pin/edit/forget/restore; chips above the composer 300 ms after
typing stops, with a token estimate; 「帶了 N 條記憶」 under person
messages. The phone has the same as a 記憶 tab, chips and tag.
Checked: make test passes (app 297, relay 16), with new tests for the
scores and thresholds, Traditional Chinese segmentation, remember's
dedupe and replaces, two turns sending the same beginning, no double
carry, weekly/monthly folding and the trash, and the audit.db move.
Brain idle 37 MB as before, ~230 MB with the model loaded; search on
the brain 0.2–0.5 ms, 7–44 ms from the phone page. A deadlock found on
the way (stats re-taking the lock) is fixed and tested.
Docs: docs/memory.md has the whole design; FEATURES.md, protocol,
architecture (zh/en), multi-device and install say what changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3SYw9JJ9dXwaNvYh4
2026-11-10 23:46:50 +00:00
|
|
|
|
remember 不會記重複的:
|
|
|
|
|
|
|
2026-11-11 01:35:59 +00:00
|
|
|
|
- 「很像」要兩邊都像才算:兩句的詞(含連續兩字)有六成以上相同,或舊的那句整句包含在新的裡,或語意很像(cos ≥ 0.85)。只是主題相同不算,例如已經有「女兒小安對花生過敏」,「我對花生過敏」照樣記。
|
|
|
|
|
|
- 很像時先不新增,回傳已經有的那條,由 Bot 三選一:同一件事就不記;是更新或更正,再呼叫一次並把 `replaces` 設成舊的那條;是不同的兩件事,再呼叫一次並把 `separate` 設成 true。
|
記憶: a page to see it, a few lines picked while typing, a local model
The memory had grown into a list carried whole, a top-14 recalled by a
trigram index and pasted into the system prompt with the clock, and a
page that broke its own layout. Nobody could see what went to the
model, the prompt cache missed every message, and 「記住」 kept saying
the same thing twice. Rebuilt per the spec (docs/memory.md):
- Three kinds in memory.db: 記得的事 (fact), 做過的事 (event, a line per
finished turn), 整理過的 (rollup). Each keeps pinned, uses,
last_used, deleted, superseded_by, span. state.json keeps the facts
as the copy that syncs; the page reads SQLite.
- Search: jieba words ∪ CJK bigrams in an FTS5 unicode61 table
(Traditional text goes through Simplified first), weighted share of
query terms hit; plus local vectors, vec = clamp((cos−0.35)/0.35).
score = max + 0.15×min, events ×0.9. ≥0.15 suggested, ≥0.5 ticked,
≥0.55 carried when nobody chose (3 at most).
- What the model gets: the system prompt has the time zone and the
pinned memories only, the same every turn. Each person message gets
〔送出時間〕 and 〔相關記憶〕 from Message.memories, built in
group_history into a transient Message.context, so the beginning of
a chat reads the same next turn (cache hits) and the event log,
skills and audit see only what was typed. A memory already carried
in view isn't carried again; each carry counts a use.
- Picks travel with the message: Cmd::Send / POST send / sync act
"memories" (empty = none; absent = the brain chooses, once, saved).
- remember finds the like one (cos ≥ 0.85 or the same words) and asks
for `replaces`; the old one is superseded, never carried. A fact
forgotten and remembered again comes back. New search_memory
(query, kind), with dates; read-only.
- Nightly on the brain, no model: events past 30 days fold into a line
per week (「11/3–11/9 做過的事(14 件):整理照片 ×3…」, ≤400 chars,
like with like by words or vectors), weeks past 180 days into months;
the folded go to 最近刪除 for 30 days. Facts are never removed. The
page offers duplicates, facts unused for half a year, and what can
fold now.
- Local model: minishlab/potion-multilingual-128M through m2v.rs (same
token ids as model2vec-rs on 13/13 sentences, cos ≥ 0.9999, without
tokenizers' 1.1 GB). Converted while downloading: vocab.bin,
table.i8 (int8 + row scales), dims.json, 137 MB kept of 530 MB;
ANYBOT_HF_BASE picks a mirror (now passed into the server's brain
container too). Loaded when first needed (34 ms), let go after 10
idle minutes. The brain loads it; a screen only with a document
folder set; hands and phones never. 設定 › 一般 › 語意搜尋:
本機模型/Ollama/關閉; a new engine clears every vector.
- Three files, three connections: memory.db (backed up nightly, 7
kept), docs.db (a cache), oplog/audit.db (30 days). An old audit.db
hands its memories and documents over once and shrinks (a real one:
172 MB → 16 KB). docs_search scans every chunk now, vectors cached
in RAM (it stopped at 8000); FTS optimize + VACUUM daily (260 MB of
tombstones over 31 MB of text).
- API: POST /api/memory (owner) and /api/sync/memory (mirror). Reads
answer on the HTTP thread; writes go through phone_act("memory").
- Screens: a memory dialog (Bot menu 記憶…, Bot settings 打開記憶) with
counts, live search, filters, suggestions, per-item kind/date/uses
and pin/edit/forget/restore; chips above the composer 300 ms after
typing stops, with a token estimate; 「帶了 N 條記憶」 under person
messages. The phone has the same as a 記憶 tab, chips and tag.
Checked: make test passes (app 297, relay 16), with new tests for the
scores and thresholds, Traditional Chinese segmentation, remember's
dedupe and replaces, two turns sending the same beginning, no double
carry, weekly/monthly folding and the trash, and the audit.db move.
Brain idle 37 MB as before, ~230 MB with the model loaded; search on
the brain 0.2–0.5 ms, 7–44 ms from the phone page. A deadlock found on
the way (stats re-taking the lock) is fixed and tested.
Docs: docs/memory.md has the whole design; FEATURES.md, protocol,
architecture (zh/en), multi-device and install say what changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3SYw9JJ9dXwaNvYh4
2026-11-10 23:46:50 +00:00
|
|
|
|
- 被取代的舊記憶放進「最近刪除」,標上被哪一條取代,之後不會再帶。
|
|
|
|
|
|
- 以前刪掉的事再 remember 一次,會把原來那條還原。
|
|
|
|
|
|
|
|
|
|
|
|
## 每晚整理
|
|
|
|
|
|
|
2026-11-11 01:35:59 +00:00
|
|
|
|
只在存記憶的那台(大腦)上做,螢幕和手腳不做。照使用者的時區,每天凌晨 3 點後做一次。全部在本機算,不呼叫模型。
|
記憶: a page to see it, a few lines picked while typing, a local model
The memory had grown into a list carried whole, a top-14 recalled by a
trigram index and pasted into the system prompt with the clock, and a
page that broke its own layout. Nobody could see what went to the
model, the prompt cache missed every message, and 「記住」 kept saying
the same thing twice. Rebuilt per the spec (docs/memory.md):
- Three kinds in memory.db: 記得的事 (fact), 做過的事 (event, a line per
finished turn), 整理過的 (rollup). Each keeps pinned, uses,
last_used, deleted, superseded_by, span. state.json keeps the facts
as the copy that syncs; the page reads SQLite.
- Search: jieba words ∪ CJK bigrams in an FTS5 unicode61 table
(Traditional text goes through Simplified first), weighted share of
query terms hit; plus local vectors, vec = clamp((cos−0.35)/0.35).
score = max + 0.15×min, events ×0.9. ≥0.15 suggested, ≥0.5 ticked,
≥0.55 carried when nobody chose (3 at most).
- What the model gets: the system prompt has the time zone and the
pinned memories only, the same every turn. Each person message gets
〔送出時間〕 and 〔相關記憶〕 from Message.memories, built in
group_history into a transient Message.context, so the beginning of
a chat reads the same next turn (cache hits) and the event log,
skills and audit see only what was typed. A memory already carried
in view isn't carried again; each carry counts a use.
- Picks travel with the message: Cmd::Send / POST send / sync act
"memories" (empty = none; absent = the brain chooses, once, saved).
- remember finds the like one (cos ≥ 0.85 or the same words) and asks
for `replaces`; the old one is superseded, never carried. A fact
forgotten and remembered again comes back. New search_memory
(query, kind), with dates; read-only.
- Nightly on the brain, no model: events past 30 days fold into a line
per week (「11/3–11/9 做過的事(14 件):整理照片 ×3…」, ≤400 chars,
like with like by words or vectors), weeks past 180 days into months;
the folded go to 最近刪除 for 30 days. Facts are never removed. The
page offers duplicates, facts unused for half a year, and what can
fold now.
- Local model: minishlab/potion-multilingual-128M through m2v.rs (same
token ids as model2vec-rs on 13/13 sentences, cos ≥ 0.9999, without
tokenizers' 1.1 GB). Converted while downloading: vocab.bin,
table.i8 (int8 + row scales), dims.json, 137 MB kept of 530 MB;
ANYBOT_HF_BASE picks a mirror (now passed into the server's brain
container too). Loaded when first needed (34 ms), let go after 10
idle minutes. The brain loads it; a screen only with a document
folder set; hands and phones never. 設定 › 一般 › 語意搜尋:
本機模型/Ollama/關閉; a new engine clears every vector.
- Three files, three connections: memory.db (backed up nightly, 7
kept), docs.db (a cache), oplog/audit.db (30 days). An old audit.db
hands its memories and documents over once and shrinks (a real one:
172 MB → 16 KB). docs_search scans every chunk now, vectors cached
in RAM (it stopped at 8000); FTS optimize + VACUUM daily (260 MB of
tombstones over 31 MB of text).
- API: POST /api/memory (owner) and /api/sync/memory (mirror). Reads
answer on the HTTP thread; writes go through phone_act("memory").
- Screens: a memory dialog (Bot menu 記憶…, Bot settings 打開記憶) with
counts, live search, filters, suggestions, per-item kind/date/uses
and pin/edit/forget/restore; chips above the composer 300 ms after
typing stops, with a token estimate; 「帶了 N 條記憶」 under person
messages. The phone has the same as a 記憶 tab, chips and tag.
Checked: make test passes (app 297, relay 16), with new tests for the
scores and thresholds, Traditional Chinese segmentation, remember's
dedupe and replaces, two turns sending the same beginning, no double
carry, weekly/monthly folding and the trash, and the audit.db move.
Brain idle 37 MB as before, ~230 MB with the model loaded; search on
the brain 0.2–0.5 ms, 7–44 ms from the phone page. A deadlock found on
the way (stats re-taking the lock) is fixed and tested.
Docs: docs/memory.md has the whole design; FEATURES.md, protocol,
architecture (zh/en), multi-device and install say what changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3SYw9JJ9dXwaNvYh4
2026-11-10 23:46:50 +00:00
|
|
|
|
|
|
|
|
|
|
- **做過的事超過 30 天**:每週(週一到週日)壓成一行。內容相近的放在一起數次數,次數多的排前面,整行最多 400 字,放不下的寫「…還有 N 件」。
|
|
|
|
|
|
- **每週那行超過 180 天**:每月再壓成一行,例如「2026 年 4 月做過的事(14 件):整理照片 ×3、修 Docker…」。
|
|
|
|
|
|
- **壓掉的原文**放進「最近刪除」,30 天後才真的清掉。
|
|
|
|
|
|
- **記得的事**永遠不會自動刪。
|
|
|
|
|
|
- 順便把 `memory.db` 備份一份。
|
|
|
|
|
|
|
|
|
|
|
|
「內容相近」的判斷方式是詞重疊一半以上,或本機模型的語意相似度 0.8 以上。
|
|
|
|
|
|
|
|
|
|
|
|
### 整理建議
|
|
|
|
|
|
|
|
|
|
|
|
打開記憶頁時才算,你按了才做:
|
|
|
|
|
|
|
|
|
|
|
|
- **重複**:兩條記得的事語意很像(cos > 0.9)、字幾乎一樣(詞重疊 70% 以上),或新的一條包含舊的全部內容。可以合併(留下較新的)或兩條都留著。
|
|
|
|
|
|
- **可能過時**:半年(180 天)沒被帶入過的記得的事。可以一條條看、一次全部忘記。
|
|
|
|
|
|
- **可以壓縮**:有幾條做過的事、幾行每週的整理已經可以壓。可以「現在整理」,不用等晚上。
|
|
|
|
|
|
|
|
|
|
|
|
## 本機語意模型
|
|
|
|
|
|
|
|
|
|
|
|
- 模型是 `minishlab/potion-multilingual-128M`(Model2Vec 靜態模型,256 維)。算向量只是查表加平均,沒有神經網路要跑。
|
|
|
|
|
|
- 不用官方的 `model2vec-rs` 執行:它用的 `tokenizers` 讀這個 50 萬字的字表要約 1.1 GB 記憶體。`m2v.rs` 是自己寫的精簡版,跟官方比過:13 句測試文字的 token id 全部一樣,向量的 cos ≥ 0.9999。
|
|
|
|
|
|
- **下載時直接轉檔**,不留原始的 512 MB:
|
|
|
|
|
|
- `tokenizer.json` 轉成 `vocab.bin`
|
|
|
|
|
|
- `model.safetensors` 一邊下載一邊量化成 `table.i8`(int8,每列一個縮放值)
|
|
|
|
|
|
- 另存 `dims.json`
|
2026-11-11 01:35:59 +00:00
|
|
|
|
- 總共下載約 530 MB,存下來約 137 MB。設定頁顯示下載進度,失敗了過幾分鐘會再試。整個下載沒有時間上限,只有連續 60 秒收不到資料才算失敗。
|
記憶: a page to see it, a few lines picked while typing, a local model
The memory had grown into a list carried whole, a top-14 recalled by a
trigram index and pasted into the system prompt with the clock, and a
page that broke its own layout. Nobody could see what went to the
model, the prompt cache missed every message, and 「記住」 kept saying
the same thing twice. Rebuilt per the spec (docs/memory.md):
- Three kinds in memory.db: 記得的事 (fact), 做過的事 (event, a line per
finished turn), 整理過的 (rollup). Each keeps pinned, uses,
last_used, deleted, superseded_by, span. state.json keeps the facts
as the copy that syncs; the page reads SQLite.
- Search: jieba words ∪ CJK bigrams in an FTS5 unicode61 table
(Traditional text goes through Simplified first), weighted share of
query terms hit; plus local vectors, vec = clamp((cos−0.35)/0.35).
score = max + 0.15×min, events ×0.9. ≥0.15 suggested, ≥0.5 ticked,
≥0.55 carried when nobody chose (3 at most).
- What the model gets: the system prompt has the time zone and the
pinned memories only, the same every turn. Each person message gets
〔送出時間〕 and 〔相關記憶〕 from Message.memories, built in
group_history into a transient Message.context, so the beginning of
a chat reads the same next turn (cache hits) and the event log,
skills and audit see only what was typed. A memory already carried
in view isn't carried again; each carry counts a use.
- Picks travel with the message: Cmd::Send / POST send / sync act
"memories" (empty = none; absent = the brain chooses, once, saved).
- remember finds the like one (cos ≥ 0.85 or the same words) and asks
for `replaces`; the old one is superseded, never carried. A fact
forgotten and remembered again comes back. New search_memory
(query, kind), with dates; read-only.
- Nightly on the brain, no model: events past 30 days fold into a line
per week (「11/3–11/9 做過的事(14 件):整理照片 ×3…」, ≤400 chars,
like with like by words or vectors), weeks past 180 days into months;
the folded go to 最近刪除 for 30 days. Facts are never removed. The
page offers duplicates, facts unused for half a year, and what can
fold now.
- Local model: minishlab/potion-multilingual-128M through m2v.rs (same
token ids as model2vec-rs on 13/13 sentences, cos ≥ 0.9999, without
tokenizers' 1.1 GB). Converted while downloading: vocab.bin,
table.i8 (int8 + row scales), dims.json, 137 MB kept of 530 MB;
ANYBOT_HF_BASE picks a mirror (now passed into the server's brain
container too). Loaded when first needed (34 ms), let go after 10
idle minutes. The brain loads it; a screen only with a document
folder set; hands and phones never. 設定 › 一般 › 語意搜尋:
本機模型/Ollama/關閉; a new engine clears every vector.
- Three files, three connections: memory.db (backed up nightly, 7
kept), docs.db (a cache), oplog/audit.db (30 days). An old audit.db
hands its memories and documents over once and shrinks (a real one:
172 MB → 16 KB). docs_search scans every chunk now, vectors cached
in RAM (it stopped at 8000); FTS optimize + VACUUM daily (260 MB of
tombstones over 31 MB of text).
- API: POST /api/memory (owner) and /api/sync/memory (mirror). Reads
answer on the HTTP thread; writes go through phone_act("memory").
- Screens: a memory dialog (Bot menu 記憶…, Bot settings 打開記憶) with
counts, live search, filters, suggestions, per-item kind/date/uses
and pin/edit/forget/restore; chips above the composer 300 ms after
typing stops, with a token estimate; 「帶了 N 條記憶」 under person
messages. The phone has the same as a 記憶 tab, chips and tag.
Checked: make test passes (app 297, relay 16), with new tests for the
scores and thresholds, Traditional Chinese segmentation, remember's
dedupe and replaces, two turns sending the same beginning, no double
carry, weekly/monthly folding and the trash, and the audit.db move.
Brain idle 37 MB as before, ~230 MB with the model loaded; search on
the brain 0.2–0.5 ms, 7–44 ms from the phone page. A deadlock found on
the way (stats re-taking the lock) is fixed and tested.
Docs: docs/memory.md has the whole design; FEATURES.md, protocol,
architecture (zh/en), multi-device and install say what changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3SYw9JJ9dXwaNvYh4
2026-11-10 23:46:50 +00:00
|
|
|
|
- 環境變數 `ANYBOT_HF_BASE` 可以換成 Hugging Face 的鏡像站(例如 `https://hf-mirror.com`)。
|
|
|
|
|
|
- 第一次要用時才載入(34 毫秒),閒置 10 分鐘就放掉。載入時程式多用約 190 MB 記憶體,一句話約 1.5 微秒。
|
|
|
|
|
|
|
|
|
|
|
|
每台機器各自決定要不要載入:
|
|
|
|
|
|
|
|
|
|
|
|
| 機器 | 載不載 |
|
|
|
|
|
|
|---|---|
|
|
|
|
|
|
| 大腦 | 載(記憶都在大腦上) |
|
|
|
|
|
|
| 螢幕(例如這台 Mac) | 在設定裡明確加了文件索引資料夾才載 |
|
|
|
|
|
|
| 手腳 | 不載 |
|
|
|
|
|
|
| 手機 | 不載(搜尋在大腦上做) |
|
|
|
|
|
|
|
|
|
|
|
|
**設定 › 一般 › 語意搜尋**:本機模型(預設)/Ollama/關閉。
|
|
|
|
|
|
|
|
|
|
|
|
- 關閉時只用文字分數,一樣能找,只是聽不懂換句話說。
|
|
|
|
|
|
- 設定存在 `embed_model`:空的或 `local` 是本機模型,`off` 是關閉,`ollama` 會自己找 Ollama 裡的 embedding 模型,也可以直接寫 Ollama 的模型名稱。
|
|
|
|
|
|
- 換引擎時,所有向量清掉重算(向量是背景慢慢算的,搜尋不會等它)。
|
|
|
|
|
|
|
|
|
|
|
|
## API
|
|
|
|
|
|
|
|
|
|
|
|
手機和螢幕都用同一組操作,送 `POST`,內容是 `{op, bot, …}`:
|
|
|
|
|
|
|
|
|
|
|
|
| 路徑 | 誰用 |
|
|
|
|
|
|
|---|---|
|
2026-11-11 01:35:59 +00:00
|
|
|
|
| `/api/memory` | 手機,只限擁有者。團隊成員讀聊天時,訊息不附帶了哪些記憶;成員送出的 `memories` 也不收 |
|
記憶: a page to see it, a few lines picked while typing, a local model
The memory had grown into a list carried whole, a top-14 recalled by a
trigram index and pasted into the system prompt with the clock, and a
page that broke its own layout. Nobody could see what went to the
model, the prompt cache missed every message, and 「記住」 kept saying
the same thing twice. Rebuilt per the spec (docs/memory.md):
- Three kinds in memory.db: 記得的事 (fact), 做過的事 (event, a line per
finished turn), 整理過的 (rollup). Each keeps pinned, uses,
last_used, deleted, superseded_by, span. state.json keeps the facts
as the copy that syncs; the page reads SQLite.
- Search: jieba words ∪ CJK bigrams in an FTS5 unicode61 table
(Traditional text goes through Simplified first), weighted share of
query terms hit; plus local vectors, vec = clamp((cos−0.35)/0.35).
score = max + 0.15×min, events ×0.9. ≥0.15 suggested, ≥0.5 ticked,
≥0.55 carried when nobody chose (3 at most).
- What the model gets: the system prompt has the time zone and the
pinned memories only, the same every turn. Each person message gets
〔送出時間〕 and 〔相關記憶〕 from Message.memories, built in
group_history into a transient Message.context, so the beginning of
a chat reads the same next turn (cache hits) and the event log,
skills and audit see only what was typed. A memory already carried
in view isn't carried again; each carry counts a use.
- Picks travel with the message: Cmd::Send / POST send / sync act
"memories" (empty = none; absent = the brain chooses, once, saved).
- remember finds the like one (cos ≥ 0.85 or the same words) and asks
for `replaces`; the old one is superseded, never carried. A fact
forgotten and remembered again comes back. New search_memory
(query, kind), with dates; read-only.
- Nightly on the brain, no model: events past 30 days fold into a line
per week (「11/3–11/9 做過的事(14 件):整理照片 ×3…」, ≤400 chars,
like with like by words or vectors), weeks past 180 days into months;
the folded go to 最近刪除 for 30 days. Facts are never removed. The
page offers duplicates, facts unused for half a year, and what can
fold now.
- Local model: minishlab/potion-multilingual-128M through m2v.rs (same
token ids as model2vec-rs on 13/13 sentences, cos ≥ 0.9999, without
tokenizers' 1.1 GB). Converted while downloading: vocab.bin,
table.i8 (int8 + row scales), dims.json, 137 MB kept of 530 MB;
ANYBOT_HF_BASE picks a mirror (now passed into the server's brain
container too). Loaded when first needed (34 ms), let go after 10
idle minutes. The brain loads it; a screen only with a document
folder set; hands and phones never. 設定 › 一般 › 語意搜尋:
本機模型/Ollama/關閉; a new engine clears every vector.
- Three files, three connections: memory.db (backed up nightly, 7
kept), docs.db (a cache), oplog/audit.db (30 days). An old audit.db
hands its memories and documents over once and shrinks (a real one:
172 MB → 16 KB). docs_search scans every chunk now, vectors cached
in RAM (it stopped at 8000); FTS optimize + VACUUM daily (260 MB of
tombstones over 31 MB of text).
- API: POST /api/memory (owner) and /api/sync/memory (mirror). Reads
answer on the HTTP thread; writes go through phone_act("memory").
- Screens: a memory dialog (Bot menu 記憶…, Bot settings 打開記憶) with
counts, live search, filters, suggestions, per-item kind/date/uses
and pin/edit/forget/restore; chips above the composer 300 ms after
typing stops, with a token estimate; 「帶了 N 條記憶」 under person
messages. The phone has the same as a 記憶 tab, chips and tag.
Checked: make test passes (app 297, relay 16), with new tests for the
scores and thresholds, Traditional Chinese segmentation, remember's
dedupe and replaces, two turns sending the same beginning, no double
carry, weekly/monthly folding and the trash, and the audit.db move.
Brain idle 37 MB as before, ~230 MB with the model loaded; search on
the brain 0.2–0.5 ms, 7–44 ms from the phone page. A deadlock found on
the way (stats re-taking the lock) is fixed and tested.
Docs: docs/memory.md has the whole design; FEATURES.md, protocol,
architecture (zh/en), multi-device and install say what changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3SYw9JJ9dXwaNvYh4
2026-11-10 23:46:50 +00:00
|
|
|
|
| `/api/sync/memory` | 螢幕(`mirror` 角色,當作擁有者) |
|
|
|
|
|
|
|
|
|
|
|
|
讀取直接在 HTTP 執行緒回答。沒有視窗的大腦主迴圈每圈會睡 250 毫秒,交給它會讓打字搜尋變慢:
|
|
|
|
|
|
|
|
|
|
|
|
| op | 參數 | 回傳 |
|
|
|
|
|
|
|---|---|---|
|
|
|
|
|
|
| `suggest`、`search` | `q` | 符合的記憶,含分數、要不要預先勾、約多少 token |
|
|
|
|
|
|
| `list` | `filter`(`all`、`fact`、`event`、`pinned`、`trash`)、`q`、`offset`、`limit` | 一頁記憶、總數、花了幾毫秒 |
|
|
|
|
|
|
| `stats` | | 各種的條數、釘選的約多少 token、三個檔的大小、語意搜尋的狀態 |
|
|
|
|
|
|
| `overview` | | `stats` 再加整理建議 |
|
|
|
|
|
|
|
|
|
|
|
|
寫入交給 App 的執行緒(`phone_act("memory")`),因為記得的事也要改到 `state.json` 的副本:
|
|
|
|
|
|
|
|
|
|
|
|
| op | 參數 |
|
|
|
|
|
|
|---|---|
|
|
|
|
|
|
| `add` | `text`、`pinned` |
|
|
|
|
|
|
| `pin` | `id`、`on` |
|
|
|
|
|
|
| `edit` | `id`、`text` |
|
|
|
|
|
|
| `forget` | `id` 或 `ids` |
|
|
|
|
|
|
| `restore` | `id` |
|
|
|
|
|
|
| `merge` | `keep`、`drop`、`text`(合併後的文字,可省略) |
|
|
|
|
|
|
| `tidy` | |
|
|
|
|
|
|
| `empty_trash` | |
|
|
|
|
|
|
|
|
|
|
|
|
這台自己就是大腦時,直接呼叫函式,不經過 HTTP。
|
|
|
|
|
|
|
|
|
|
|
|
送出訊息時帶上你勾的記憶:
|
|
|
|
|
|
|
|
|
|
|
|
- 手機:`POST /api/bots/<id>/send` 加 `"memories": [...]`。
|
|
|
|
|
|
- 螢幕:`/api/sync/act` 的 `send` 一樣加 `memories`。
|
|
|
|
|
|
- 程式內部:`Cmd::Send` 的 `memories: Option<Vec<String>>`。
|
|
|
|
|
|
- 空陣列表示你選了「這次不帶」;沒有這個欄位表示沒人選過,由大腦自己挑。
|
|
|
|
|
|
|
|
|
|
|
|
## 介面
|
|
|
|
|
|
|
|
|
|
|
|
### 電腦版
|
|
|
|
|
|
|
|
|
|
|
|
- **記憶頁**(一個獨立的視窗):
|
|
|
|
|
|
- 入口:Bot 選單的「記憶…」,或 Bot 設定裡「記憶」卡片的「打開記憶」。
|
|
|
|
|
|
- 最上面:記得的事、做過的事、釘選、最近刪除各有幾條;釘選的每次約帶多少 token;三個檔的大小;語意搜尋現在的狀態。
|
|
|
|
|
|
- 搜尋框,打字就找,旁邊顯示花了幾毫秒;新增一條要記得的事。
|
|
|
|
|
|
- 篩選:全部/記得的事/做過的事/釘選/最近刪除。
|
|
|
|
|
|
- 整理建議卡,一鍵套用。
|
|
|
|
|
|
- 每條顯示種類、日期、帶過幾次、上次帶入;可以釘選、編輯、忘記,在「最近刪除」裡可以還原。
|
2026-11-11 01:35:59 +00:00
|
|
|
|
- **輸入框上方的記憶小卡片**:打字停 300 毫秒就搜尋,最多 8 張。Bot 工作中不顯示(那時送出的是插話,不帶記憶)。分數高的預先勾好,旁邊寫「帶 N 條,約 T token」或「這次不帶」。點一下卡片就加入或拿掉;滑過去看得到全文、種類、日期和相關度。
|
記憶: a page to see it, a few lines picked while typing, a local model
The memory had grown into a list carried whole, a top-14 recalled by a
trigram index and pasted into the system prompt with the clock, and a
page that broke its own layout. Nobody could see what went to the
model, the prompt cache missed every message, and 「記住」 kept saying
the same thing twice. Rebuilt per the spec (docs/memory.md):
- Three kinds in memory.db: 記得的事 (fact), 做過的事 (event, a line per
finished turn), 整理過的 (rollup). Each keeps pinned, uses,
last_used, deleted, superseded_by, span. state.json keeps the facts
as the copy that syncs; the page reads SQLite.
- Search: jieba words ∪ CJK bigrams in an FTS5 unicode61 table
(Traditional text goes through Simplified first), weighted share of
query terms hit; plus local vectors, vec = clamp((cos−0.35)/0.35).
score = max + 0.15×min, events ×0.9. ≥0.15 suggested, ≥0.5 ticked,
≥0.55 carried when nobody chose (3 at most).
- What the model gets: the system prompt has the time zone and the
pinned memories only, the same every turn. Each person message gets
〔送出時間〕 and 〔相關記憶〕 from Message.memories, built in
group_history into a transient Message.context, so the beginning of
a chat reads the same next turn (cache hits) and the event log,
skills and audit see only what was typed. A memory already carried
in view isn't carried again; each carry counts a use.
- Picks travel with the message: Cmd::Send / POST send / sync act
"memories" (empty = none; absent = the brain chooses, once, saved).
- remember finds the like one (cos ≥ 0.85 or the same words) and asks
for `replaces`; the old one is superseded, never carried. A fact
forgotten and remembered again comes back. New search_memory
(query, kind), with dates; read-only.
- Nightly on the brain, no model: events past 30 days fold into a line
per week (「11/3–11/9 做過的事(14 件):整理照片 ×3…」, ≤400 chars,
like with like by words or vectors), weeks past 180 days into months;
the folded go to 最近刪除 for 30 days. Facts are never removed. The
page offers duplicates, facts unused for half a year, and what can
fold now.
- Local model: minishlab/potion-multilingual-128M through m2v.rs (same
token ids as model2vec-rs on 13/13 sentences, cos ≥ 0.9999, without
tokenizers' 1.1 GB). Converted while downloading: vocab.bin,
table.i8 (int8 + row scales), dims.json, 137 MB kept of 530 MB;
ANYBOT_HF_BASE picks a mirror (now passed into the server's brain
container too). Loaded when first needed (34 ms), let go after 10
idle minutes. The brain loads it; a screen only with a document
folder set; hands and phones never. 設定 › 一般 › 語意搜尋:
本機模型/Ollama/關閉; a new engine clears every vector.
- Three files, three connections: memory.db (backed up nightly, 7
kept), docs.db (a cache), oplog/audit.db (30 days). An old audit.db
hands its memories and documents over once and shrinks (a real one:
172 MB → 16 KB). docs_search scans every chunk now, vectors cached
in RAM (it stopped at 8000); FTS optimize + VACUUM daily (260 MB of
tombstones over 31 MB of text).
- API: POST /api/memory (owner) and /api/sync/memory (mirror). Reads
answer on the HTTP thread; writes go through phone_act("memory").
- Screens: a memory dialog (Bot menu 記憶…, Bot settings 打開記憶) with
counts, live search, filters, suggestions, per-item kind/date/uses
and pin/edit/forget/restore; chips above the composer 300 ms after
typing stops, with a token estimate; 「帶了 N 條記憶」 under person
messages. The phone has the same as a 記憶 tab, chips and tag.
Checked: make test passes (app 297, relay 16), with new tests for the
scores and thresholds, Traditional Chinese segmentation, remember's
dedupe and replaces, two turns sending the same beginning, no double
carry, weekly/monthly folding and the trash, and the audit.db move.
Brain idle 37 MB as before, ~230 MB with the model loaded; search on
the brain 0.2–0.5 ms, 7–44 ms from the phone page. A deadlock found on
the way (stats re-taking the lock) is fixed and tested.
Docs: docs/memory.md has the whole design; FEATURES.md, protocol,
architecture (zh/en), multi-device and install say what changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3SYw9JJ9dXwaNvYh4
2026-11-10 23:46:50 +00:00
|
|
|
|
- **你的訊息下面**:「帶了 N 條記憶」,點開看是哪幾條,也可以從這裡打開記憶頁。
|
|
|
|
|
|
|
|
|
|
|
|
### 手機版
|
|
|
|
|
|
|
|
|
|
|
|
- 對話詳細資訊多一個「記憶」分頁(只有擁有者看得到),功能和電腦版的記憶頁一樣。
|
|
|
|
|
|
- 輸入框上方有一樣的記憶小卡片,排成一行,可以左右滑。
|
|
|
|
|
|
- 你的訊息下面一樣標「帶了 N 條記憶」。
|
|
|
|
|
|
|
|
|
|
|
|
## 實測數字(2026-11)
|
|
|
|
|
|
|
|
|
|
|
|
| 項目 | 結果 |
|
|
|
|
|
|
|---|---|
|
|
|
|
|
|
| 模型載入 | 34 毫秒 |
|
|
|
|
|
|
| 打字搜尋(在大腦上算) | 0.2–0.5 毫秒 |
|
|
|
|
|
|
| 打字搜尋(手機頁面,含 HTTP) | 7–44 毫秒 |
|
|
|
|
|
|
| 停手到出現卡片 | 約 0.32 秒(其中 0.3 秒是刻意等你打完) |
|
|
|
|
|
|
| 大腦閒置的記憶體 | 37 MB(跟改版前一樣) |
|
|
|
|
|
|
| 大腦載入模型後 | 約 230 MB |
|
|
|
|
|
|
| 舊 `audit.db` 搬家 | 172 MB → 16 KB |
|
|
|
|
|
|
|
|
|
|
|
|
## 測試
|
|
|
|
|
|
|
|
|
|
|
|
`make test` 會跑到這些:
|
|
|
|
|
|
|
|
|
|
|
|
- 分數與門檻:`the_shelf_answers_with_scores`、`a_message_carries_little_and_never_twice`
|
|
|
|
|
|
- 繁體中文斷詞:`traditional_text_cuts_into_words_that_meet`、`the_memory_index_answers_in_chinese`
|
2026-11-11 01:35:59 +00:00
|
|
|
|
- remember 去重與 `replaces`:`remember_says_when_it_already_knows_and_replaces_on_request`、`remember_tells_the_same_thing_from_another_fact`
|
|
|
|
|
|
- 只記有做事的回合:`only_a_turn_that_did_something_is_remembered`
|
|
|
|
|
|
- 應答詞不帶記憶、各 Bot 只讀自己的、forget 不動做過的事:`small_talk_carries_nothing_and_each_bot_keeps_its_own`
|
記憶: a page to see it, a few lines picked while typing, a local model
The memory had grown into a list carried whole, a top-14 recalled by a
trigram index and pasted into the system prompt with the clock, and a
page that broke its own layout. Nobody could see what went to the
model, the prompt cache missed every message, and 「記住」 kept saying
the same thing twice. Rebuilt per the spec (docs/memory.md):
- Three kinds in memory.db: 記得的事 (fact), 做過的事 (event, a line per
finished turn), 整理過的 (rollup). Each keeps pinned, uses,
last_used, deleted, superseded_by, span. state.json keeps the facts
as the copy that syncs; the page reads SQLite.
- Search: jieba words ∪ CJK bigrams in an FTS5 unicode61 table
(Traditional text goes through Simplified first), weighted share of
query terms hit; plus local vectors, vec = clamp((cos−0.35)/0.35).
score = max + 0.15×min, events ×0.9. ≥0.15 suggested, ≥0.5 ticked,
≥0.55 carried when nobody chose (3 at most).
- What the model gets: the system prompt has the time zone and the
pinned memories only, the same every turn. Each person message gets
〔送出時間〕 and 〔相關記憶〕 from Message.memories, built in
group_history into a transient Message.context, so the beginning of
a chat reads the same next turn (cache hits) and the event log,
skills and audit see only what was typed. A memory already carried
in view isn't carried again; each carry counts a use.
- Picks travel with the message: Cmd::Send / POST send / sync act
"memories" (empty = none; absent = the brain chooses, once, saved).
- remember finds the like one (cos ≥ 0.85 or the same words) and asks
for `replaces`; the old one is superseded, never carried. A fact
forgotten and remembered again comes back. New search_memory
(query, kind), with dates; read-only.
- Nightly on the brain, no model: events past 30 days fold into a line
per week (「11/3–11/9 做過的事(14 件):整理照片 ×3…」, ≤400 chars,
like with like by words or vectors), weeks past 180 days into months;
the folded go to 最近刪除 for 30 days. Facts are never removed. The
page offers duplicates, facts unused for half a year, and what can
fold now.
- Local model: minishlab/potion-multilingual-128M through m2v.rs (same
token ids as model2vec-rs on 13/13 sentences, cos ≥ 0.9999, without
tokenizers' 1.1 GB). Converted while downloading: vocab.bin,
table.i8 (int8 + row scales), dims.json, 137 MB kept of 530 MB;
ANYBOT_HF_BASE picks a mirror (now passed into the server's brain
container too). Loaded when first needed (34 ms), let go after 10
idle minutes. The brain loads it; a screen only with a document
folder set; hands and phones never. 設定 › 一般 › 語意搜尋:
本機模型/Ollama/關閉; a new engine clears every vector.
- Three files, three connections: memory.db (backed up nightly, 7
kept), docs.db (a cache), oplog/audit.db (30 days). An old audit.db
hands its memories and documents over once and shrinks (a real one:
172 MB → 16 KB). docs_search scans every chunk now, vectors cached
in RAM (it stopped at 8000); FTS optimize + VACUUM daily (260 MB of
tombstones over 31 MB of text).
- API: POST /api/memory (owner) and /api/sync/memory (mirror). Reads
answer on the HTTP thread; writes go through phone_act("memory").
- Screens: a memory dialog (Bot menu 記憶…, Bot settings 打開記憶) with
counts, live search, filters, suggestions, per-item kind/date/uses
and pin/edit/forget/restore; chips above the composer 300 ms after
typing stops, with a token estimate; 「帶了 N 條記憶」 under person
messages. The phone has the same as a 記憶 tab, chips and tag.
Checked: make test passes (app 297, relay 16), with new tests for the
scores and thresholds, Traditional Chinese segmentation, remember's
dedupe and replaces, two turns sending the same beginning, no double
carry, weekly/monthly folding and the trash, and the audit.db move.
Brain idle 37 MB as before, ~230 MB with the model loaded; search on
the brain 0.2–0.5 ms, 7–44 ms from the phone page. A deadlock found on
the way (stats re-taking the lock) is fixed and tested.
Docs: docs/memory.md has the whole design; FEATURES.md, protocol,
architecture (zh/en), multi-device and install say what changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3SYw9JJ9dXwaNvYh4
2026-11-10 23:46:50 +00:00
|
|
|
|
- 兩回合送出的前段一樣:`two_turns_send_the_same_beginning`、`a_message_reads_the_same_every_turn`
|
|
|
|
|
|
- 帶過的不重複帶:`a_memory_rides_once_per_chat`
|
|
|
|
|
|
- 每週、每月壓縮與最近刪除:`old_events_fold_into_weeks_then_months`、`folded_lines_read_back`、`forgetting_is_a_trash_you_can_take_back`
|
|
|
|
|
|
- 整理建議:`duplicates_and_forgotten_facts_are_offered`、`the_page_reads_counts_and_suggestions`
|
|
|
|
|
|
- 舊 `audit.db` 搬家:`an_old_audit_db_moves_into_its_own_files`、`documents_stay_findable_after_compaction`
|
|
|
|
|
|
|
|
|
|
|
|
## 已知的限制
|
|
|
|
|
|
|
|
|
|
|
|
- **自動帶入很保守**:句子越長,查詢詞越多,文字分數越容易被稀釋,很少到 0.55。例如「幫我訂下週去台南的高鐵票,要靠窗」會列出卡片,但不會預先勾。你自己勾選不受影響。
|
|
|
|
|
|
- **帳號的加密備份只有 `state.json`**:裡面有記得的事的副本,但做過的事、整理過的、釘選和使用次數不在裡面,要靠 `backups/` 裡每晚的 `memory.db` 備份。
|
|
|
|
|
|
- **螢幕沒有明確設定文件資料夾時不載模型**:只用預設的 `~/Documents` 不算,那台的文件搜尋就只用文字分數。
|