Separator Characters Incorrectly Removed During Chunk Splitting #15184

Closed
opened 2026-02-21 19:20:34 -05:00 by yindo · 4 comments
Owner

Originally created by @BXbing on GitHub (Jul 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.5.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

When performing chunk splitting, if the chunk length exceeds the configured maximum, the text is automatically split into multiple segments. However, during this process, the separators ['\n\n', '。', '. ', ' ', '’'] are incorrectly removed based on their match order.The correct behavior should be to preserve these separators—they should only be used to split, not removed.

✔️ Expected Behavior

Image The chunk size did not exceed the limit

Actual Behavior

Image `\n\n` is incorrectly removed
Originally created by @BXbing on GitHub (Jul 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.5.1 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce When performing chunk splitting, if the chunk length exceeds the configured maximum, the text is automatically split into multiple segments. However, during this process, the separators `['\n\n', '。', '. ', ' ', '’'] ` are incorrectly removed based on their match order.The correct behavior should be to preserve these separators—they should only be used to split, not removed. ### ✔️ Expected Behavior <img width="1771" height="680" alt="Image" src="https://github.com/user-attachments/assets/2599a1d0-441e-474f-b022-0a546878601a" /> The chunk size did not exceed the limit ### ❌ Actual Behavior <img width="1743" height="587" alt="Image" src="https://github.com/user-attachments/assets/fbe8febf-fa05-43c4-98ae-a6c37534c797" /> `\n\n` is incorrectly removed
yindo added the 🐞 buggood first issue labels 2026-02-21 19:20:34 -05:00
yindo closed this issue 2026-02-21 19:20:34 -05:00
Author
Owner

@BXbing commented on GitHub (Jul 8, 2025):

I modified the file api/core/rag/splitter/fixed_text_splitter.py

# line 102
splits = text.split(separator)

# Changed to:
splits = text.split(separator)
splits = [item + separator if i < len(splits) else item for i, item in splits]
# Re-appending the separator directly instead of using regex for rejoining

it works

Image
@BXbing commented on GitHub (Jul 8, 2025): I modified the file `api/core/rag/splitter/fixed_text_splitter.py` ```python # line 102 splits = text.split(separator) # Changed to: splits = text.split(separator) splits = [item + separator if i < len(splits) else item for i, item in splits] # Re-appending the separator directly instead of using regex for rejoining ``` it works <img width="1749" height="762" alt="Image" src="https://github.com/user-attachments/assets/dcc76b4a-313f-497a-9d35-8f9f41a021ed" />
Author
Owner

@BXbing commented on GitHub (Jul 8, 2025):

By the way, the Dify documentation mentions that regex can be used as segment identifiers, but I haven't found any actual implementation that supports this.

@BXbing commented on GitHub (Jul 8, 2025): By the way, the Dify documentation mentions that regex can be used as segment identifiers, but I haven't found any actual implementation that supports this.
Author
Owner

@crazywoola commented on GitHub (Jul 8, 2025):

By the way, the Dify documentation mentions that regex can be used as segment identifiers, but I haven't found any actual implementation that supports this.

I think this doc is outdated.

Thanks for the investigation https://github.com/langgenius/dify/issues/22046#issuecomment-3048113919
Feel free to open a PR to fix this. 🥇

@crazywoola commented on GitHub (Jul 8, 2025): > By the way, the Dify documentation mentions that regex can be used as segment identifiers, but I haven't found any actual implementation that supports this. I think this doc is outdated. Thanks for the investigation https://github.com/langgenius/dify/issues/22046#issuecomment-3048113919 Feel free to open a PR to fix this. 🥇
Author
Owner

@jubinsoni commented on GitHub (Jul 18, 2025):

pr
https://github.com/langgenius/dify/pull/22596

@jubinsoni commented on GitHub (Jul 18, 2025): pr https://github.com/langgenius/dify/pull/22596
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#15184