feat(recall): 检索为王——op=search 模糊搜索 + days/day 按日期翻页,退役盲列 list
用户定调:记起的往往是「一段事」而非「第几条」,search 价值高于 list;list 也必须按日期走而非盲目罗列。
recall 从 list/files/link 升级为 search/days/day/files/link:
- op=search {query, count}:碎片级全库模糊检索(主入口)。空白/标点分词多词择优,
子串直匹;CJK 长词整串不中时二元字组过半即模糊命中(得分 0.9 折算),英文大小写不敏感;
结果按相关度排序、标注匹配百分比与所属日期,默认 10 条上限 30;无命中回友好提示并引导 days。
- op=days:日期索引(哪天、几条)——只记得「大概哪天」时的入口;op=day {date} 取整天完整日记。
- 开场注入头行与工具 description 同步改口径(提起旧事 → search;记时间 → days/day);
存储/存在性判定/files/link 不变。op=list 退役(含 skip 盲翻页参数)。
探针 12 项全过:精确/模糊(打折分)/多词排名/大小写/无命中/days 计数/day 整天/空天/日期校验/退役提示。
This commit is contained in:
@@ -235,7 +235,7 @@
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "recall",
|
||||
"description": "Access your long-term memory: the work diary. Each finished session leaves one short fragment (a few dozen characters, headed by the source session id), stored permanently; only the newest fragments were injected at session start. Read-only.\n\nop=list Older diary fragments beyond the injected window. Optional: skip (default = skip the injected window), count (default 20, max 50).\nop=files List files of a past session that still exist on disk right now. Requires id (the session id from a diary fragment's 【…】 heading).\nop=link Mint a temporary download link for one of those files. Requires id and path (a name from op=files).",
|
||||
"description": "Access your long-term memory: the work diary. Each finished session leaves one short fragment (a few dozen characters, headed by the source session id), stored permanently; only the newest fragments were injected at session start. When the user vaguely recalls something from the past, search is your primary entry — you cannot know what you have forgotten. Read-only.\n\nop=search Requires query (keywords; space-separated words rank better, e.g. '身份证 水印'). Fuzzy fragment-level match across ALL dates (Chinese tolerant to partial phrases), best matches first. Optional count (default 10, max 30).\nop=days No arguments. Index of diary days (date + fragment count) — use when the user remembers roughly WHEN but not what; then op=day.\nop=day Requires date (YYYY-MM-DD, as listed by op=days). Full fragments of that day.\nop=files Requires id (the session id from a diary fragment's 【…】 heading). Files of that past session that still exist on disk right now.\nop=link Requires id and path (a name from op=files). Mint a temporary download link.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
@@ -245,19 +245,25 @@
|
||||
"op": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"list",
|
||||
"search",
|
||||
"days",
|
||||
"day",
|
||||
"files",
|
||||
"link"
|
||||
],
|
||||
"description": "What to recall: list = older diary fragments; files = a past session's current artifacts; link = a download link for one of them."
|
||||
"description": "What to recall: search = keyword fuzzy over all diary fragments (primary); days = which dates have entries; day = one date's full diary; files = a past session's current artifacts; link = a download link for one of them."
|
||||
},
|
||||
"skip": {
|
||||
"type": "integer",
|
||||
"description": "op=list: how many newest fragments to skip. Default = the window already injected at session start."
|
||||
"query": {
|
||||
"type": "string",
|
||||
"description": "op=search: keywords to look for (space-separated words rank best, e.g. '身份证 水印'). Chinese and English both supported, case-insensitive."
|
||||
},
|
||||
"count": {
|
||||
"type": "integer",
|
||||
"description": "op=list: fragments to return (default 20, max 50)."
|
||||
"description": "op=search: max fragments to return (default 10, max 30)."
|
||||
},
|
||||
"date": {
|
||||
"type": "string",
|
||||
"description": "op=day: the day to open, YYYY-MM-DD exactly as shown by op=days."
|
||||
},
|
||||
"id": {
|
||||
"type": "string",
|
||||
|
||||
@@ -1226,9 +1226,23 @@ function toolRecall(ctx, args) {
|
||||
return { sid: sid, title: s.title || sid, dir: path.join(root, sid) };
|
||||
};
|
||||
switch (op) {
|
||||
case 'list': {
|
||||
const txt = memory.olderFragments(db, ctx.cfg, user, args.skip, args.count);
|
||||
return txt || '更早的日记没有了:开场注入的就是全部记忆。需要某次工作的成果文件用 op=files。';
|
||||
case 'search': {
|
||||
const q = String(args.query || '').trim();
|
||||
if (!q) throw new Error('op=search 需要 query(关键词;空格分隔多个词更好,如「身份证 水印」)');
|
||||
const txt = memory.searchFragments(db, user, q, args.count);
|
||||
return txt || '日记库里没有匹配「' + q + '」的条目。换个更宽泛的关键词再试,或 op=days 看哪天有什么;成果文件走 op=files。';
|
||||
}
|
||||
case 'days': {
|
||||
const list = memory.daysIndex(db, user);
|
||||
if (!list.length) return '日记库是空的:还没有任何收口条目(开场注入的日记也出自这里)。';
|
||||
return '【日记日期索引】共 ' + list.length + ' 天有记录(新在前):\n' + list.join('\n')
|
||||
+ '\n用 op=day {date} 看某天的完整日记;记得关键词就直接 op=search。';
|
||||
}
|
||||
case 'day': {
|
||||
const date = String(args.date || '').trim();
|
||||
if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) throw new Error('op=day 需要 date(YYYY-MM-DD,先用 op=days 查有哪些天)');
|
||||
const txt = memory.dayEntry(db, user, date);
|
||||
return txt ? date + ' 的日记:\n' + txt : date + ' 没有日记(当天无交互或条目已裁剪;op=days 可看有哪些天)。';
|
||||
}
|
||||
case 'files': {
|
||||
const t = resolveSession();
|
||||
@@ -1260,7 +1274,7 @@ function toolRecall(ctx, args) {
|
||||
return pl.base_url + '/p/' + publicFiles.mint({ sessionId: t.sid, rel: rel, ttlMs: pl.ttl_ms });
|
||||
}
|
||||
default:
|
||||
throw new Error('未知的 op:"' + op + '"。可用:list(翻更早日记,可选 skip/count)/ files(需 id,列那次会话现存成果文件)/ link(需 id+path,产临时下载链接)');
|
||||
throw new Error('未知的 op:"' + op + '"。可用:search(需 query,可选 count)/ days(日期索引)/ day(需 date)/ files(需 id)/ link(需 id+path)');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user