Repository navigation
fix(search): event summary unreachable regex + ratio threshold + blank speaker turns (#3598) - #3617
RerankerGuo wants to merge 1 commit into
Conversation
…ines (#3598) Issue #3598 reports three small defects that compound so recall spends nearly its whole `max_chars` budget on verbatim event transcripts - on production samples 92.5% of event-doc chars were ChatLog, and 55% of turns were tool-only blanks lines. A single "summary-mode" fragment was observed at 6466 chars when the real `# Summary` section was 465 chars. ### Defect #1 — `_extract_event_summary()` never matched template output (verified in issue correction comment, was TWO mismatches not one). Template writes `# Summary` + `# YYYY-MM-DD (Weekday) ChatLog:`. The regex wanted `Summary:` + a bare `<date> ChatLog:` with no heading marker. Neither anchor nor terminator matched, so `fallback` (full doc) was always used. Relax the regex: - anchor: `^\s*\#*\s*Summary:?\s*` — optional heading mark, optional colon (accepts current heading style, legacy field form, resource-event prose) - terminator: `\n\s*\#*\s*(?:<date>|ChatLog:)` plus MEMORY_FIELDS sentinel and end-of-string for summary-only docs. ### Defect #3 — template hardcoded `ratio_threshold=0` `events.yaml` content_template called `get_event_content(ranges, summary, 0)`, short-circuiting `len(summary)/len(original) >= 0` to always return the full verbatim transcript. Drop the third positional arg so the function default (0.2) kicks in, matching the default intent. ### Defect #4 — blank speaker lines in ChatLog `_format_contiguous_group.flush_current()` unconditionally appended `**speaker**: {content}`. Tool-call-only turns carry no TextPart, so merged content was `""`; every such turn added a blank 36-byte line, and those lines then fed into the embedding template. Guard append with `if content.strip():`; a session with 55% blank turns now saves ~40% of its rendered event-doc bytes. Tests added in `tests/unit/test_issue3598_event_summary.py`: - TestExtractEventSummaryAnchorMatch: 6 parametrized cases covering all writer shapes (current template, legacy field form, MEMORY_FIELDS terminator, summary-only resource branch, heading variances, fallback) plus exact minimal-repro body from issue. - TestGetEventContentDefaultRatio: signature default = 0.2 (not 0); ratio boundary behavior at 0.2. - TestFormatContiguousGroupSkipsBlankTurns: pure-tool groups yield [], text+tool mixture keeps only text turns.
|
感谢这个 PR,也感谢 #3598 那份报告 —— 定位到具体行号、四条缺陷分别给了最小复现,还在复验后自己纠正了 defect #2 属有意设计。这种质量的报告对我们非常有用。 关闭的原因是召回读取端正在整体重做。 #3534(实现 RFC #3372,目前还是 draft,在评审中)把召回组装搬到服务端, 比把正则修对更进一步的是:新的档位模型让 Summary 抽取成为 events 的默认档,而不是"超出预算才走的退路"。你观测到的 6466 → 465 这个收益在默认路径上直接拿到,不需要先触发降级。 所以你对这个文件的改动会和 #3534 冲突(你改、我们删), 本 PR 里另外两处改动( In short (EN): closing because the recall read path is being rewritten server-side in #3534 (RFC #3372, still a draft), which deletes The other two changes here — |
背景
Issue #3598 报告召回(
POST /api/v1/search/recall)在 mode=summary 时,事件(events)层几乎把全部max_chars预算花在完整逐字聊天记录上——观测到线上 17 篇事件文档共 51,752 字符,其中 92.5% 是 ChatLog,单篇最高 88% 的 turn 是工具调用空 turn。一个type="summary"片段本应只有 465 字符,却渲染出 6466 字符(相当于 full 片段)。原因是 3 个小缺陷各自独立,但组合起来放大了开销:_extract_event_summary()正则从未匹配:模板写# Summary/# 2026-07-24 (Friday) ChatLog:,旧正则要求Summary:/<date> ChatLog:(均无#标题前缀),两个端点都错位 → 始终走 fallback(全文)。Reporter 第一次验证时以为只改锚点即可,重验后确认 锚点 + 终止符 都需要放松([Bug]: Event summary degradation in recall is unreachable —# Summaryheading vsSummary:regex, and three defects that compound with it #3598 correction Bump actions/download-artifact from 4 to 7 #1)。ratio_threshold=0:events.yaml的content_template把get_event_content(ranges, summary, 0)第三参写死为 0,len(summary) / len(original) >= 0永远为 true → 永远返回逐字 pretty-print transcript,而不是当 summary 是原文 20% 以内时优先用 summary。方法默认值 0.2,模板单点覆写使分支成为死代码。_format_contiguous_group.flush_current()无条件追加**speaker**: {content}。纯 ToolCallPart / ToolPart 的 turn 没有 TextPart,_format_merged_content为空串,每 turn 产生 36 字节**alice**:空行;样本里 55% 的 turn 是空 turn,占单文档字节数 40%,并且这些空行继续进入 embedding template。Defect #2(fallback 片段不计入 type 级 budget)Reporter 已纠正为有意设计(见代码里
type_quota_recall.py:449-451原注释),因此未改动。改动内容
openviking/retrieve/type_quota_recall.py— 放松正则两端_extract_event_summary():^\s*\#*\s*Summary:?\s*— 支持当前# Summary标题风格 / 历史Summary:字段形式 / 不带 chatlog 的 resource branch 散文形式。\s*\#*\s*前缀,保留 MEMORY_FIELDS sentinel 与$,保证 resource-event 分支 / summary-only 文档正确终止。# Summaryheading vsSummary:regex, and three defects that compound with it #3598 defect Bump actions/download-artifact from 4 to 7 #1 与 correction Bump actions/download-artifact from 4 to 7 #1 以便后续回溯。openviking/prompts/templates/memory/events.yaml— 删除 ratio_threshold=0L103 原来:
{{ extract_context.get_event_content(ranges, summary, 0) }}改成:
{{ extract_context.get_event_content(ranges, summary) }}→ 走
ExtractContext.get_event_content方法签名默认值0.2。openviking/session/memory/memory_updater.py— flush_current 跳过空内容_format_contiguous_group.flush_current()在 append 前加if content.strip():。纯 ToolCall/ToolResult 消息不再产生空 speaker 行,同时减少进入embedding_template: EventName / Goal / {{ content }}的垃圾字符。tests/unit/test_issue3598_event_summary.py— 回归测试 3 组[],以及 text + tool 混合时只保留有文本的 speaker 行。验证方式
python3 <<'PYEOF'对 [Bug]: Event summary degradation in recall is unreachable —# Summaryheading vsSummary:regex, and three defects that compound with it #3598 最小样例精确复现:修改前返回fallback=全文,修改后返回"Shipped the thing."。"Summary: Legacy.\n2025-01-01 ChatLog:\n..."→ 返回"Legacy."。$终止均验证通过。注:项目根 conftest 导入链路中
openviking_cli/utils/async_utils.py:15使用了asyncio.AbstractEventLoop | None(Python 3.10+ union 语法),而当前执行环境是 Python 3.9,这与本次改动无关,是仓库已有的 baseline 环境限制。在配备 Python 3.10+ 的 CI 环境中可正常跑pytest tests/unit/test_issue3598_event_summary.py。影响范围
search_type_quota_recall在 mode="summary" 下的片段体积从「全文」量级降到「实际 Summary section」量级(即 Reporter 观察到的 6466 → 465 char)。get_event_content激活 20% 比例门限,summary 紧凑时 ChatLog 改为 summary,减小落盘与向量 embedding 体积。{{ content }}不再包含数百字节的 "speaker: " 空行,召回相关性可提升(纯噪声被移除)。Summary:字段形式仍被正确识别;$终止保证 resource-event branch 不被破坏。Checklist
pytest tests/unit/test_issue3598_event_summary.py -xvs。