Skip to content

[codex] 忽略语义分块中的空标题#836

Open
guoyi8 wants to merge 1 commit into
xerrors:mainfrom
guoyi8:codex/fix-semantic-empty-headings
Open

[codex] 忽略语义分块中的空标题#836
guoyi8 wants to merge 1 commit into
xerrors:mainfrom
guoyi8:codex/fix-semantic-empty-headings

Conversation

@guoyi8

@guoyi8 guoyi8 commented Jul 17, 2026

Copy link
Copy Markdown

变更内容

  • Semantic 分块器遇到空 Markdown 标题时直接忽略该标题。
  • 空标题不再清空当前标题路径,也不会无意义地截断前后正文。
  • 增加独立单元测试覆盖父标题、子标题、空标题与前后正文场景。

问题原因

HTML 转 Markdown 等处理可能产生空 ATX 标题,例如 ###。MarkdownIt 会将其解析为标题节点,但标题内容为空。原实现仍会刷新当前内容并用空字符串更新标题栈,导致后续 Chunk 丢失有效的子标题上下文。

影响

仅改变空标题这一退化输入的处理方式;正常非空标题的分块和标题路径行为保持不变。

验证

  • 21 passed, 1 skipped:Semantic 与 RagFlow-like 相关单元测试。
  • Ruff 检查通过。
  • Ruff 格式检查通过。
  • git diff --check 通过。

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies the markdown chunking parser to correctly handle empty headings by skipping them and preserving the current title context, and adds a corresponding unit test. The review feedback suggests adding a boundary check when accessing the next token in the stream to prevent a potential IndexError if the token stream is truncated.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +165 to +166
inline_token = tokens[i + 1]
full_title = inline_token.content.strip() if inline_token.type == "inline" else ""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

为了确保健壮的防御性编程,并防止在 Token 流格式错误或被截断时发生潜在的 IndexError 崩溃,在获取 inline token 之前,对前瞻索引访问 tokens[i + 1] 进行边界检查会更加安全。

Suggested change
inline_token = tokens[i + 1]
full_title = inline_token.content.strip() if inline_token.type == "inline" else ""
inline_token = tokens[i + 1] if i + 1 < len(tokens) else None
full_title = inline_token.content.strip() if inline_token and inline_token.type == "inline" else ""

@guoyi8
guoyi8 marked this pull request as ready for review July 17, 2026 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant