HTML knowledge-base files lose every block boundary: get_text() welds the words together

未关闭
#42,348 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

Start in api/core/rag/extractor/html_extractor.py at HtmlExtractor._load_as_text, then inspect the existing HTML extractor test that currently checks only that characters survive. Run that test and reproduce the provided HTML example; done means block-level boundaries remain separate while inline text keeps its spacing and punctuation.

由索引模型根据 Issue 内容生成。

描述

Self Checks
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report.
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.
Dify version

main (api/core/rag/extractor/html_extractor.py)

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

Upload an ordinary .html file to a knowledge base — or call the extractor
directly:

from core.rag.extractor.html_extractor import HtmlExtractor

# <h1>Quarterly Report</h1><p>Revenue rose.</p><p>Costs fell.</p>
# <ul><li>Item one</li><li>Item two</li></ul>
print(HtmlExtractor("report.html")._load_as_text())
✔️ Expected Behavior

One block per line, the way the page reads:

Quarterly Report
Revenue rose.
Costs fell.
Item one
Item two
❌ Actual Behavior
Quarterly ReportRevenue rose.Costs fell.Item oneItem two

_load_as_text returns soup.get_text(), which concatenates every text node
with nothing in between. A page's block structure lives in the markup, not in the
text, so every boundary disappears and the words on either side are welded into
one: ReportRevenue, fell.Item, oneItem.

That string is what gets chunked and embedded. ReportRevenue is not a word in
any vocabulary, so the chunk that holds the heading is not retrievable by the
heading, and a chunk boundary can now fall in the middle of what used to be two
separate blocks.

The existing test pins only that the characters survive —
"".join(page_content.split()) == "TitleHello" — which is true either way, so
nothing catches it today.

Note for whoever picks this up: the obvious fix is wrong. get_text(" ") or
get_text("\n") also inserts the separator between inline elements, so
<p>Hello <b>world</b>! See <a href="#">this</a>.</p> turns into
Hello world ! See this . The end of each block-level element has to be marked
instead.

I have a patch ready with tests for both halves and will open the PR against this
issue.

主要语言
TypeScript
星标
157k
派生
24.7k
平均合并
22 小时 32 分钟
30 天内合并 PR
611

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

langgenius/dify 的其他 Issue

查看 langgenius/dify 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。