Repository navigation
Fix naive chunking for windows - #16767
Conversation
📝 WalkthroughWalkthroughThe ChangesNewline Normalization
Estimated code review effort: 1 (Trivial) | ~3 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@rag/nlp/__init__.py`:
- Around line 1165-1166: `naive_merge_with_images` still splits the original
text without normalizing line endings, so Windows-style inputs can produce
different chunk boundaries than `naive_merge`. Update the
`naive_merge_with_images` path to apply the same `\r\n` and `\r` normalization
used in `naive_merge` before any delimiter splitting, and keep the behavior
consistent with the existing `sections` normalization logic.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: df8bcb40-daad-449f-a52b-88561a18c626
📒 Files selected for processing (1)
rag/nlp/__init__.py
| # Normalize line endings so delimiter ``\n`` matches ``\r\n`` and standalone ``\r``. | ||
| sections = [(s.replace("\r\n", "\n").replace("\r", "\n"), pos) for s, pos in sections] |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check if naive_merge_with_images has its own splitting logic or calls naive_merge
rg -n "def naive_merge_with_images" rag/nlp/__init__.py
# Show the function body to inspect for newline handling
ast-grep outline rag/nlp/__init__.py --match naive_merge_with_images --view expandedRepository: infiniflow/ragflow
Length of output: 401
🏁 Script executed:
#!/bin/bash
sed -n '1230,1325p' rag/nlp/__init__.pyRepository: infiniflow/ragflow
Length of output: 4568
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== callers of naive_merge_with_images =="
rg -n "naive_merge_with_images\s*\(" -S rag . || true
echo
echo "== nearby text normalization around naive_merge/naive_merge_with_images =="
sed -n '1080,1325p' rag/nlp/__init__.py | rg -n "normalize line endings|replace\\(\"\\\\r\\\\n\"|replace\\(\"\\\\r\"|naive_merge|naive_merge_with_images|get_delimiters|re.split|text_str|text_pos"
echo
echo "== definitions of get_delimiters and naive_merge =="
rg -n "def get_delimiters|def naive_merge\\(" rag/nlp/__init__.py
sed -n '1010,1185p' rag/nlp/__init__.pyRepository: infiniflow/ragflow
Length of output: 9457
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== caller context =="
sed -n '1190,1255p' rag/app/naive.py
echo
echo "== behavior probe for CRLF/CR on the current split path =="
python3 - <<'PY'
import re
delimiter = r"\n。;!?"
dels = delimiter
def split_current(text):
pieces = []
for sub_sec in re.split(r"(%s)" % dels, text, flags=re.DOTALL):
if not sub_sec or re.fullmatch(dels, sub_sec):
continue
pieces.append(sub_sec)
return pieces
samples = {
"lf": "a\nb",
"crlf": "a\r\nb",
"cr": "a\rb",
}
for name, s in samples.items():
print(name, split_current(s))
PYRepository: infiniflow/ragflow
Length of output: 3468
Normalize line endings in naive_merge_with_images. rag/nlp/__init__.py:1230 still splits raw text directly and never applies the \r\n/\r normalization used by naive_merge, so Windows files can chunk differently on this path.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@rag/nlp/__init__.py` around lines 1165 - 1166, `naive_merge_with_images`
still splits the original text without normalizing line endings, so
Windows-style inputs can produce different chunk boundaries than `naive_merge`.
Update the `naive_merge_with_images` path to apply the same `\r\n` and `\r`
normalization used in `naive_merge` before any delimiter splitting, and keep the
behavior consistent with the existing `sections` normalization logic.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16767 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
\ris ignored for splitting boundaries