Skip to content

fix(api): default delimiter must be a real newline, not the r"\n" escape - #17591

Merged
xugangqiang merged 1 commit into
infiniflow:mainfrom
deadtrickster:ik-txt-delimiter-escape
Aug 4, 2026
Merged

xugangqiang merged 1 commit into
infiniflow:mainfrom
deadtrickster:ik-txt-delimiter-escape

Conversation

@deadtrickster

@deadtrickster deadtrickster commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Found this reading arXiv chunks back from storage, every n was gone. "analysis increasingly involves information" came back as "a\nalysis i\ncreasi\ngly i\nvolves i\nformatio". No error, chunk count normal, status 100%. The stored .txt on disk was fine.

The cause - a dataset created via the API without an explicit delimiter stores the default as the escape \n (backslash + the literal letter n). Two chunker paths read it and disagree. deepdoc/parser/txt_parser.py runs the delimiter through a unicode_escape round-trip (txt_parser.py:34), so \n becomes a real newline and it splits correctly. But rag/nlp/get_delimiters (used by naive_merge) does not decode. It splits the delimiter into individual characters (list(delimiter)), so \n becomes backslash and the letter n, and every oversized section gets split on the letter n and drops it.

For a .txt file both run. TxtParser splits it into sections (fine, it decoded), then naive_merge re-splits every oversized section on the letter n. So the corpus comes back with every n gone. It hid for a long time. Non-Latin corpora look fine (no n to lose), and small sections never reach the naive_merge re-split.

Reproduced on v0.26.4 (the version I ingested arxiv with, image infiniflow/ragflow:v0.26.4) and still on current main 611e0596. The repro is a normal API create with a parser_config present but no delimiter, then a large .txt.

Fix, both in get_delimiters - decode escape sequences the same way txt_parser does, so \n splits on a newline. And drop bare ASCII-letter delimiter characters with a warning, keeping backtick-quoted delimiters, so any residual letter degrades to no split instead of silent corruption. txt_parser keeps the same letter guard and stays whole when nothing is left to split on.

markdown_parser.get_delimiters is backtick-only already and is safe. Go compileDelimPattern compiles only backtick delimiters and splits oversized sections on a fixed newline/punctuation pattern, so Go never char-splits the config delimiter. Added Go tests that assert it.

Splitting a document on a letter is never a real config, so nothing legitimate changes. Normal delimiters (newline, !?。;!?, backtick groups) are untouched.

Tests - test/unit_test/deepdoc/parser/test_txt_parser.py, test/unit_test/rag/test_naive_merge.py, and internal/ingestion/component/chunker/delimiter_safety_test.go cover the letter delimiter (red before the fix), the \n escape, normal delimiters, the all-letters case, and the Go parity.


UPD: main refactored the delimiter parsers into one canonical helper rag.nlp.delim.parse_delimiter_field (#17383), so the original two-path fix no longer applies - get_delimiters and the txt_parser inline split are gone.

Re-checked against current main and the shred is still live, but the cause narrows to the stored default, not the parser. The canonical parser is correct on a real newline. What reaches it as backslash + n is the default itself - three configs default the delimiter to a raw r"\n" (a Python raw string, so backslash + the literal letter n):

  • api/utils/api_utils.py:393 (knowledge_graph)
  • api/utils/validation_utils.py:427 (ParserConfig)
  • api/utils/validation_utils.py:399 (ParentChildConfig children_delimiter)

parse_delimiter_field(r"\n") returns ['\\', 'n'] and splits "information" into "i","formatio". The naive default at api_utils.py:341 is already a real "\n" and the frontend sends a real newline, so these three were just missed.

Fix is now those three defaults, r"\n" -> "\n", matching the naive default. No parser change, so delim.py and its tests are untouched. Regression test in test/unit_test/api/utils/test_default_delimiter.py asserts the three defaults parse to a single newline. Dropped the old txt_parser / naive_merge / Go changes - they targeted code that no longer exists.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 31, 2026
@coderabbitai

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Delimiter processing now decodes escapes, filters unsafe unquoted values, preserves quoted delimiters, logs discarded values, and avoids character-by-character splitting when no valid delimiters remain. Tests cover parser, chunker, and merge behavior.

Changes

Delimiter safety

Layer / File(s) Summary
Delimiter normalization and parser handling
common/string_utils.py, rag/nlp/__init__.py, deepdoc/parser/txt_parser.py
Shared decoding handles recognized and invalid escape sequences. Delimiter processing preserves quoted values, filters unquoted ASCII letters, digits, and backslashes, and keeps the full input when no valid delimiters remain.
Delimiter regression coverage
internal/ingestion/component/chunker/delimiter_safety_test.go, test/unit/...
Tests cover delimiter compilation, newline and punctuation splitting, quoted delimiters, malformed and double-escaped values, Unicode delimiters, and merged-text preservation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • infiniflow/ragflow#17386: Both changes modify delimiter extraction and matching in deepdoc/parser/txt_parser.py and rag/nlp/__init__.py.
  • infiniflow/ragflow#17387: Both changes modify delimiter parsing and splitting in deepdoc/parser/txt_parser.py and rag/nlp/__init__.py.

Suggested labels: 🐞 bug, 🌈 python, 🧪 test

Poem

A rabbit checks each splitting sign,
Keeps quoted marks in tidy line.
Bare letters hop away,
Newlines guide the chunks today,
No text is lost along the way.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the issue and intended fix, but its UPD section contradicts the committed parser, helper, and test changes. Update the description to match the committed changes and remove or correct the contradictory UPD section.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the delimiter escape issue, although it does not describe the parser sanitization changes in full.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@deadtrickster
deadtrickster force-pushed the ik-txt-delimiter-escape branch from 1e8a405 to c620985 Compare July 31, 2026 00:39

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 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 1635-1638: Update the delimiter decoding logic in the surrounding
initializer to avoid the Latin-1 round trip for non-Latin Unicode escapes such
as \u3002. Decode Unicode escapes directly, preserve the resolved delimiter
characters, and keep the existing delimiter expansion behavior; do not fall back
to a raw backslash form that can drop the escape marker.

In `@test/unit_test/rag/test_naive_merge.py`:
- Around line 225-235: Update test/unit_test/rag/test_naive_merge.py lines
225-235 in test_letter_delimiter_does_not_drop_letters to construct
bad_delimiter with two backslashes followed by n, so decoding leaves the bare n
corruption case; update lines 238-242 in the related test to append the same
double-escaped delimiter. No other sites require changes.
🪄 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 Plus

Run ID: 48451fed-c248-4d12-8a90-2545697ba56d

📥 Commits

Reviewing files that changed from the base of the PR and between 611e059 and c620985.

📒 Files selected for processing (5)
  • deepdoc/parser/txt_parser.py
  • internal/ingestion/component/chunker/delimiter_safety_test.go
  • rag/nlp/__init__.py
  • test/unit_test/deepdoc/parser/test_txt_parser.py
  • test/unit_test/rag/test_naive_merge.py

Comment thread rag/nlp/__init__.py Resolved
Comment thread test/unit_test/rag/test_naive_merge.py Resolved
@deadtrickster
deadtrickster force-pushed the ik-txt-delimiter-escape branch from c620985 to 6750c37 Compare July 31, 2026 08:15

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🧹 Nitpick comments (2)
test/unit_test/rag/test_naive_merge.py (2)

244-249: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Exercise the raw-backslash fallback for \u3002.

With the supplied get_delimiters implementation, this value falls back to raw characters. The filter removes u and the digits but can retain \. The current input, "2024 results", contains no backslash, so the test can pass while the pattern still splits on \. Add a backslash-containing input and assert the intended fallback behavior, or assert the decoded 。 delimiter if Unicode escapes should be supported.

🤖 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 `@test/unit_test/rag/test_naive_merge.py` around lines 244 - 249, The
test_get_delimiters_ignores_escaped_non_ascii_digits test does not exercise the
retained backslash in the raw fallback. Update its input and assertion to
include a backslash-containing string and verify that the generated pattern does
not split on that backslash, or instead validate the decoded 。 delimiter if
get_delimiters is intended to support Unicode escapes.

237-242: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert each delimiter that the test claims to retain.

The test only proves that ! remains active. It does not prove that newline or ? remains active. Add one match for each retained delimiter.

Proposed test strengthening
     assert not re.search(pattern, "information")
     assert re.search(pattern, "a!b")
+    assert re.search(pattern, "a\nb")
+    assert re.search(pattern, "a?b")
🤖 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 `@test/unit_test/rag/test_naive_merge.py` around lines 237 - 242, Strengthen
test_get_delimiters_drops_bare_letters_keeps_punctuation by adding separate
assertions that the generated pattern matches text containing a newline and text
containing “?”. Keep the existing assertions for excluding “n” and retaining
“!”, so each delimiter claimed by the test is explicitly verified.
🤖 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 `@deepdoc/parser/txt_parser.py`:
- Around line 35-40: Update the delimiter escape handling near the round-trip
conversion and the related filtering logic around the parser’s escape-token
processing so invalid escape tokens are discarded with their leading backslash,
while valid tokens in mixed input such as `r"\n\u3002"` are decoded
independently. Ensure inputs like `r"\u3002"` cannot leave a standalone
backslash that affects splitting or document text, and add regression coverage
for mixed escapes and literal backslashes.

In `@test/unit_test/deepdoc/parser/test_txt_parser.py`:
- Around line 20-31: Strengthen the regression assertions in the
malformed-escape tests around test_letter_delimiter_does_not_eat_content and the
related tests at the referenced ranges: assert the joined parsed text exactly
matches the original input, add a backslash to the Unicode-escape test input so
residual delimiters are detected, and require len(chunks) > 1 in the punctuation
test to verify splitting occurred.

---

Nitpick comments:
In `@test/unit_test/rag/test_naive_merge.py`:
- Around line 244-249: The test_get_delimiters_ignores_escaped_non_ascii_digits
test does not exercise the retained backslash in the raw fallback. Update its
input and assertion to include a backslash-containing string and verify that the
generated pattern does not split on that backslash, or instead validate the
decoded 。 delimiter if get_delimiters is intended to support Unicode escapes.
- Around line 237-242: Strengthen
test_get_delimiters_drops_bare_letters_keeps_punctuation by adding separate
assertions that the generated pattern matches text containing a newline and text
containing “?”. Keep the existing assertions for excluding “n” and retaining
“!”, so each delimiter claimed by the test is explicitly verified.
🪄 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 Plus

Run ID: bf354dea-6ebf-4b0d-9e41-1d43cc7d352d

📥 Commits

Reviewing files that changed from the base of the PR and between c620985 and 6750c37.

📒 Files selected for processing (5)
  • deepdoc/parser/txt_parser.py
  • internal/ingestion/component/chunker/delimiter_safety_test.go
  • rag/nlp/__init__.py
  • test/unit_test/deepdoc/parser/test_txt_parser.py
  • test/unit_test/rag/test_naive_merge.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • rag/nlp/init.py

Comment thread deepdoc/parser/txt_parser.py Resolved
@deadtrickster
deadtrickster force-pushed the ik-txt-delimiter-escape branch from 6750c37 to 276b82c Compare July 31, 2026 09:04

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
common/string_utils.py (1)

83-100: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Add debug logging when the decoder changes a delimiter.

A valid escaped delimiter changes split behavior without a diagnostic. Log a debug message only when the decoded value differs from delimiters. Do not include document content in the message.

Proposed change
 def decode_delimiter_escapes(delimiters: str) -> str:
+    ...
+    decoded = _DELIMITER_ESCAPE.sub(_decode, delimiters)
+    if decoded != delimiters:
+        logging.debug("Decoded escape sequences in configured delimiter")
+    return decoded
-    return _DELIMITER_ESCAPE.sub(_decode, delimiters)

As per coding guidelines, “**/*.py: Add logging for new flows”.

🤖 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 `@common/string_utils.py` around lines 83 - 100, Add debug logging to
decode_delimiter_escapes only when the final decoded result differs from the
original delimiters value, using the module’s existing logger and a message that
excludes document content; leave unchanged inputs silent and preserve the
per-token decoding behavior in _decode.

Source: Coding guidelines

🤖 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 `@deepdoc/parser/txt_parser.py`:
- Around line 52-72: The delimiter list in RAGFlowTxtParser.parser_txt must
prefer longer alternatives to prevent shorter delimiters from partially matching
them. After filtering invalid delimiters and before re.escape, sort dels by
descending length; apply this ordering consistently to both quoted and unquoted
delimiter-processing paths while preserving the existing filtering behavior.
- Around line 52-72: Preserve quote provenance by tracking whether each
delimiter token came from backtick quoting rather than storing quoted delimiter
values in a shared set. Update both the delimiter-processing logic in
RAGFlowTxtParser.parser_txt and rag.nlp.get_delimiters so duplicate values such
as a quoted “n” followed by an unquoted “n” filter only the unquoted unsafe
token. Add a regression covering that quoted-then-unquoted sequence and verify
the unquoted character cannot split or be removed from chunks.

---

Nitpick comments:
In `@common/string_utils.py`:
- Around line 83-100: Add debug logging to decode_delimiter_escapes only when
the final decoded result differs from the original delimiters value, using the
module’s existing logger and a message that excludes document content; leave
unchanged inputs silent and preserve the per-token decoding behavior in _decode.
🪄 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 Plus

Run ID: b49f638e-c2e3-4d1e-97bf-573ef8b57e22

📥 Commits

Reviewing files that changed from the base of the PR and between 6750c37 and 276b82c.

📒 Files selected for processing (6)
  • common/string_utils.py
  • deepdoc/parser/txt_parser.py
  • internal/ingestion/component/chunker/delimiter_safety_test.go
  • rag/nlp/__init__.py
  • test/unit_test/deepdoc/parser/test_txt_parser.py
  • test/unit_test/rag/test_naive_merge.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • rag/nlp/init.py

Comment thread deepdoc/parser/txt_parser.py Resolved

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

🤖 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 `@deepdoc/parser/txt_parser.py`:
- Line 36: Align delimiter normalization between RAGFlowTxtParser.parser_txt and
naive_merge by decoding the delimiter once before selecting the custom-delimiter
parsing path, ensuring backtick-quoted escaped sequences produce the same
delimiter in both flows. Preserve literal backtick handling and add a focused
regression test covering the escaped newline delimiter and section splitting.

In `@test/unit_test/deepdoc/parser/test_txt_parser.py`:
- Around line 64-72: Update test_mixed_escape_delimiter_splits_on_both to assert
that the decoded CJK period character is absent from joined parsed content,
while retaining the existing word-presence and multi-chunk assertions.
- Around line 97-107: The test_quoted_char_tracked_by_position_not_value test
assertions do not actually verify that the bare `n` is being ignored by
position-based filtering. To properly validate this behavior, capture and assert
on the warning message that reports the discarded bare `n` token. Add an
assertion that checks for this warning to confirm position-based filtering is
working, since the current end-result assertions alone could be satisfied even
if both `n` tokens remained active.
🪄 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 Plus

Run ID: 5fb20e23-7d64-4ac3-a1bb-5276df158099

📥 Commits

Reviewing files that changed from the base of the PR and between 276b82c and a163a57.

📒 Files selected for processing (6)
  • common/string_utils.py
  • deepdoc/parser/txt_parser.py
  • internal/ingestion/component/chunker/delimiter_safety_test.go
  • rag/nlp/__init__.py
  • test/unit_test/deepdoc/parser/test_txt_parser.py
  • test/unit_test/rag/test_naive_merge.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • rag/nlp/init.py
  • common/string_utils.py

Comment thread deepdoc/parser/txt_parser.py Resolved
Comment on lines +64 to +72
def test_mixed_escape_delimiter_splits_on_both():
# "\n。" means newline and the CJK period. Both must split, letters kept.
delimiter = chr(92) + "n" + chr(92) + "u3002" # \n。
text = "alpha。beta\ngamma"
chunks = RAGFlowTxtParser.parser_txt(text, chunk_token_num=1, delimiter=delimiter)
joined = " ".join(c for c, _ in chunks)
for word in ("alpha", "beta", "gamma"):
assert word in joined
assert len(chunks) > 1

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert that the decoded CJK delimiter is consumed.

len(chunks) > 1 can pass when only the decoded newline delimiter works. The test does not prove that \u3002 decodes and splits. Assert that the CJK period is absent from the parsed content.

Proposed test change
     for word in ("alpha", "beta", "gamma"):
         assert word in joined
+    assert "。" not in joined
     assert len(chunks) > 1
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def test_mixed_escape_delimiter_splits_on_both():
# "\n。" means newline and the CJK period. Both must split, letters kept.
delimiter = chr(92) + "n" + chr(92) + "u3002" # \n。
text = "alpha。beta\ngamma"
chunks = RAGFlowTxtParser.parser_txt(text, chunk_token_num=1, delimiter=delimiter)
joined = " ".join(c for c, _ in chunks)
for word in ("alpha", "beta", "gamma"):
assert word in joined
assert len(chunks) > 1
def test_mixed_escape_delimiter_splits_on_both():
# "\n。" means newline and the CJK period. Both must split, letters kept.
delimiter = chr(92) + "n" + chr(92) + "u3002" # \n。
text = "alpha。beta\ngamma"
chunks = RAGFlowTxtParser.parser_txt(text, chunk_token_num=1, delimiter=delimiter)
joined = " ".join(c for c, _ in chunks)
for word in ("alpha", "beta", "gamma"):
assert word in joined
assert "。" not in joined
assert len(chunks) > 1
🤖 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 `@test/unit_test/deepdoc/parser/test_txt_parser.py` around lines 64 - 72,
Update test_mixed_escape_delimiter_splits_on_both to assert that the decoded CJK
period character is absent from joined parsed content, while retaining the
existing word-presence and multi-chunk assertions.

Comment on lines +97 to +107
def test_quoted_char_tracked_by_position_not_value():
# A backtick-quoted "n" is honored as an explicit delimiter even with a literal
# "n" in the same config. Quote status is tracked per token position, so the
# literal "n" is still filtered on its own rather than shielded by the quoted
# one sharing its value.
delimiter = "`n`n" # quoted n, then literal n
text = "an informative analysis"
chunks = RAGFlowTxtParser.parser_txt(text, chunk_token_num=1, delimiter=delimiter)
joined = "".join(c for c, _ in chunks)
assert "n" not in joined # the explicit quoted n splits, consuming the n's
assert "iformative" in joined # non-n content preserved

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert that the bare n is ignored.

The quoted and bare n tokens produce the same parsed output if both remain active. The current assertions therefore do not verify position-based filtering. Capture the warning that reports the discarded bare n.

Proposed test change
-def test_quoted_char_tracked_by_position_not_value():
+def test_quoted_char_tracked_by_position_not_value(caplog):
...
     assert "n" not in joined  # the explicit quoted n splits, consuming the n's
     assert "iformative" in joined  # non-n content preserved
+    assert any(
+        "ignoring delimiter character(s) ['n']" in record.getMessage()
+        for record in caplog.records
+    )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def test_quoted_char_tracked_by_position_not_value():
# A backtick-quoted "n" is honored as an explicit delimiter even with a literal
# "n" in the same config. Quote status is tracked per token position, so the
# literal "n" is still filtered on its own rather than shielded by the quoted
# one sharing its value.
delimiter = "`n`n" # quoted n, then literal n
text = "an informative analysis"
chunks = RAGFlowTxtParser.parser_txt(text, chunk_token_num=1, delimiter=delimiter)
joined = "".join(c for c, _ in chunks)
assert "n" not in joined # the explicit quoted n splits, consuming the n's
assert "iformative" in joined # non-n content preserved
def test_quoted_char_tracked_by_position_not_value(caplog):
# A backtick-quoted "n" is honored as an explicit delimiter even with a literal
# "n" in the same config. Quote status is tracked per token position, so the
# literal "n" is still filtered on its own rather than shielded by the quoted
# one sharing its value.
delimiter = "`n`n" # quoted n, then literal n
text = "an informative analysis"
chunks = RAGFlowTxtParser.parser_txt(text, chunk_token_num=1, delimiter=delimiter)
joined = "".join(c for c, _ in chunks)
assert "n" not in joined # the explicit quoted n splits, consuming the n's
assert "iformative" in joined # non-n content preserved
assert any(
"ignoring delimiter character(s) ['n']" in record.getMessage()
for record in caplog.records
)
🤖 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 `@test/unit_test/deepdoc/parser/test_txt_parser.py` around lines 97 - 107, The
test_quoted_char_tracked_by_position_not_value test assertions do not actually
verify that the bare `n` is being ignored by position-based filtering. To
properly validate this behavior, capture and assert on the warning message that
reports the discarded bare `n` token. Add an assertion that checks for this
warning to confirm position-based filtering is working, since the current
end-result assertions alone could be satisfied even if both `n` tokens remained
active.

@deadtrickster

Copy link
Copy Markdown
Contributor Author

@xugangqiang could you add the ci label here? Tests skip without it.

Latest push addresses CodeRabbit's delimiter-parity Major - naive_merge now decodes backtick delimiters the same way txt_parser does, so a `\n` config splits on a newline in both paths instead of only the parser. Also the two test asserts it asked for. Rebased on current main. Would appreciate a look.

get_parser_config's knowledge_graph default and the ParserConfig /
ParentChildConfig validation defaults used r"\n" - a raw string, so a backslash
plus the letter n. rag.nlp.delim.parse_delimiter_field honours bare characters,
so that default splits documents on every n ("information" -> "i", "formatio")
and on the stray backslash. A dataset created via the API without an explicit
delimiter got this shredding default.

Use an actual newline, matching the naive default and what the frontend already
sends. Regression test asserts the three defaults parse to a single newline.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@deadtrickster
deadtrickster force-pushed the ik-txt-delimiter-escape branch from b9cb89b to 093c69d Compare August 3, 2026 11:34
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Aug 3, 2026
@deadtrickster deadtrickster changed the title fix(chunker): don't let a letter delimiter shred documents fix(api): default delimiter must be a real newline, not the r"\n" escape Aug 3, 2026
@deadtrickster

Copy link
Copy Markdown
Contributor Author

Separate from this PR, noticed while checking the round-trip. The delimiter help text in web/src/locales/en.ts tells users to type \n for a newline ("parses to three delimiters - newline (\n), double hash (##), semicolon (;)"), but parse_delimiter_field treats the field literally and does not decode \n. So a user who follows the help and types \n gets a split on the letter n, not a newline.

Not touching it here since it is the delim.py design call. But the doc and the parser disagree - either the help drops the \n example, or the parser decodes escapes on the way in. How do you want to handle it?

@xugangqiang xugangqiang added the ci Continue Integration label Aug 4, 2026
@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (a75e733) to head (093c69d).
⚠️ Report is 16 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #17591   +/-   ##
=======================================
  Coverage   90.65%   90.65%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          650      650           
  Misses         39       39           
  Partials       28       28           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@xugangqiang

xugangqiang commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

@deadtrickster Appreciate your contribution. For this PR, I think it's good and I will merge it. For other issues that's related to ingestion, I'd like to suggest that you can raise issues firstly but on-hold fixing(PR) for a while: since we are in the middle of migration from python to golang and we need a fixed baseline (though the baseline may not be good). Once golang migration completed (most likely no later than next month), we can continue bug fixing on ingestion related issues. Thank you.

@xugangqiang
xugangqiang merged commit 8c8c1e7 into infiniflow:main Aug 4, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants