A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Rank a whole phrase over its pairs in recall, and keep every word
Fei2411e260c5d1dbc9
diff --git a/ds-bot/src/host/memory.js b/ds-bot/src/host/memory.jsindex e8f9e415..697bab81 100644--- a/ds-bot/src/host/memory.js+++ b/ds-bot/src/host/memory.js@@ -1224,13 +1224,18 @@ export function install(rt) {].join('\n')}).join('\n\n')}- // A continuous run of Han characters has no spaces to split on: its- // character pairs stand for the words inside it. Other words, and- // space-separated terms, match as they did.- const terms = [...new Set(squash(query).split(' ').filter(Boolean).flatMap((word) => {- const words = /[\u4e00-\u9fff]/.test(word) ? [...wordsOf(word)] : []- return words.length > 0 ? words : [word]- }))].slice(0, QUERY_TERMS_MAX)+ // The cap is on the user's own words, so a long phrase's pairs do not push+ // its end or later words out. A run of Han characters has no spaces to+ // split on: the word itself is a term, so an entry holding the whole+ // phrase outranks one holding only its parts; its character pairs stand+ // for the words inside it, and a Latin part of a mixed word is a term too.+ const words = squash(query).split(' ').filter(Boolean).slice(0, QUERY_TERMS_MAX)+ const terms = [...new Set(words.flatMap((word) => {+ if (!/[\u4e00-\u9fff]/.test(word)) return [word]+ const parts = new Set(word.match(/[a-z0-9]+/g) ?? [])+ for (const run of word.match(/[\u4e00-\u9fff]{2,}/g) ?? []) for (let at = 0; at + 1 < run.length; at += 1) parts.add(run.slice(at, at + 2))+ return [word, ...parts]+ }))]const scored = loaded.flatMap(({ tag, files }) => allEntries(files).map((entry) => {const hay = squash(`${entry.text} ${entry.file.topic ?? ''}`)return { entry, tag, count: terms.filter(term => hay.includes(term)).length }diff --git a/ds-bot/test/memory.test.js b/ds-bot/test/memory.test.jsindex 93816e4e..8329eef4 100644--- a/ds-bot/test/memory.test.js+++ b/ds-bot/test/memory.test.js@@ -249,6 +249,34 @@ test('recall finds a continuous Chinese phrase, and keeps space-separated and Laassert.match(await tool('recall', { query: 'green 生日' }, 'b2'), /No entry has all of "green 生日"/)})+test('recall caps the user\'s words, not their pairs, and a whole phrase outranks pair matches', async (t) => {+ const { tool, stop } = start()+ t.after(() => stop())+ await tool('remember', { text: '周末上海出差安排住外滩的酒店' }, 'b2')+ // The word after the phrase still counts: with 生日 missing, the hotel entry+ // is not a full match, only the closest.+ const trip = await tool('recall', { query: '周末上海出差安排 生日' }, 'b2')+ assert.match(trip, /No entry has all of "周末上海出差安排 生日"/)+ assert.match(trip, /周末上海出差安排住外滩的酒店/)+ // Of many entries that share the pairs and the one that holds the phrase+ // whole, only that one is a full match.+ for (let at = 1; at <= 30; at += 1) await tool('remember', { text: `周末上海出差安全事项第${at}条` }, 'b2')+ await tool('remember', { text: '周末上海出差安排在周五确认' }, 'b2')+ const hits = await tool('recall', { query: '周末上海出差安排' }, 'b2')+ assert.match(hits, /^Entries with "周末上海出差安排"/)+ assert.match(hits, /周末上海出差安排在周五确认/)+ assert.doesNotMatch(hits, /安全事项/)+})++test('a mixed word keeps its Latin part in recall', async (t) => {+ const { tool, stop } = start()+ t.after(() => stop())+ await tool('remember', { text: '中文资料保存在文档中' }, 'b2')+ await tool('remember', { text: 'AI中文教程在书架上' }, 'b2')+ // "AI中文" is more than 中文: only the entry that holds the phrase is a full match.+ assert.match(await tool('recall', { query: 'AI中文' }, 'b2'), /^Entries with "AI中文" in your memory and the team memory:\n\[yours · MEMORY\.md\] AI中文教程在书架上 \[source: /)+})+test('Main Bots and group admins write the team memory; only Main Bots touch another Bot\'s', async (t) => {const { tool, read, stop } = start()t.after(() => stop())