Chunking ignored all texts before hash sign in markdown documents #14483

Closed
opened 2026-02-21 19:17:27 -05:00 by yindo · 3 comments
Owner

Originally created by @tjroamer on GitHub (Jun 8, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.4.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. Create Knowledge
  2. Upload a markdown file as attached, click Next
  3. Leave all settings as default, click the button Preview Chunk

buggy_md_doc.md

✔️ Expected Behavior

The texts before hash sign are considered as a chunk.

Actual Behavior

All texts before the hash sign are ignored, and no chunk was created.

Originally created by @tjroamer on GitHub (Jun 8, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.4.1 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce 1. Create Knowledge 2. Upload a markdown file as attached, click Next 3. Leave all settings as default, click the button Preview Chunk [buggy_md_doc.md](https://github.com/user-attachments/files/20644152/buggy_md_doc.md) ### ✔️ Expected Behavior The texts before hash sign are considered as a chunk. ### ❌ Actual Behavior All texts before the hash sign are ignored, and no chunk was created.
yindo added the stale label 2026-02-21 19:17:27 -05:00
yindo closed this issue 2026-02-21 19:17:27 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jun 8, 2025):

The markdown chunking logic in Dify is designed to preserve text before the first header (hash sign) as a chunk with empty metadata. If this pre-header text is missing in your chunks, it's likely being filtered out later in the pipeline—often due to metadata-based filtering that excludes chunks with empty metadata fields. This behavior is intentional and configurable: if your dataset or retrieval settings require a metadata field (like "Section") to be "not empty," any chunk without that metadata (including pre-header content) will be ignored in results. To include the introductory text, review your metadata filtering settings and ensure they don't exclude chunks with empty metadata.
You can see the relevant chunking and filtering logic in the code here:
MarkdownHeaderTextSplitter implementation
Metadata filtering in retrieval

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Jun 8, 2025): <!-- Answer --> The markdown chunking logic in Dify is designed to preserve text before the first header (hash sign) as a chunk with empty metadata. If this pre-header text is missing in your chunks, it's likely being filtered out later in the pipeline—often due to metadata-based filtering that excludes chunks with empty metadata fields. This behavior is intentional and configurable: if your dataset or retrieval settings require a metadata field (like "Section") to be "not empty," any chunk without that metadata (including pre-header content) will be ignored in results. To include the introductory text, review your metadata filtering settings and ensure they don't exclude chunks with empty metadata. You can see the relevant chunking and filtering logic in the code here: [MarkdownHeaderTextSplitter implementation](https://github.com/langgenius/dify/blob/65c7c01d90e5af44d4c9ff41689a855a7a82c772/api/core/rag/splitter/text_splitter.py) [Metadata filtering in retrieval](https://github.com/langgenius/dify/blob/65c7c01d90e5af44d4c9ff41689a855a7a82c772/api/core/rag/retrieval/dataset_retrieval.py) <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/9b195dc5-0757-49d2-b439-bf27f8d270e5?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/9b195dc5-0757-49d2-b439-bf27f8d270e5?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/9b195dc5-0757-49d2-b439-bf27f8d270e5?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/9b195dc5-0757-49d2-b439-bf27f8d270e5?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/9b195dc5-0757-49d2-b439-bf27f8d270e5?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/9b195dc5-0757-49d2-b439-bf27f8d270e5?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/9b195dc5-0757-49d2-b439-bf27f8d270e5?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/20789)
Author
Owner

@suncle1993 commented on GitHub (Jun 30, 2025):

same issue.

@suncle1993 commented on GitHub (Jun 30, 2025): same issue.
Author
Owner

@dosubot[bot] commented on GitHub (Aug 28, 2025):

Hi, @tjroamer. I'm Dosu, and I'm helping the Dify team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported that in Dify v1.4.1 self-hosted, text before the first markdown header (#) was ignored during chunking.
  • The chunking logic does preserve this pre-header text as chunks with empty metadata.
  • These chunks may be filtered out later due to metadata-based filtering settings.
  • Adjusting the metadata filtering to include chunks with empty metadata resolves the issue.
  • Another user, suncle1993, confirmed experiencing the same behavior.

Next Steps:

  • Please confirm if this issue is still relevant with the latest version of Dify.
  • If it is, feel free to keep the discussion open by commenting; otherwise, I will automatically close this issue in 15 days.

Thanks for your understanding and contribution!

@dosubot[bot] commented on GitHub (Aug 28, 2025): Hi, @tjroamer. I'm [Dosu](https://dosu.dev), and I'm helping the Dify team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported that in Dify v1.4.1 self-hosted, text before the first markdown header (#) was ignored during chunking. - The chunking logic does preserve this pre-header text as chunks with empty metadata. - These chunks may be filtered out later due to metadata-based filtering settings. - Adjusting the metadata filtering to include chunks with empty metadata resolves the issue. - Another user, suncle1993, confirmed experiencing the same behavior. **Next Steps:** - Please confirm if this issue is still relevant with the latest version of Dify. - If it is, feel free to keep the discussion open by commenting; otherwise, I will automatically close this issue in 15 days. Thanks for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#14483