Repository navigation
Improve "Delimiter for text" UX: clearer tooltip + live parsed-delimiter preview - #17385
Conversation
The previous tooltip described backticks as the multi-char delimiter wrapper but never named them as the meta-delimiter, leaving users to discover by trial-and-error that the same string yields different splits depending on file type (tracked in infiniflow#17383, infiniflow#17384, infiniflow#7436, infiniflow#4704, infiniflow#9680). Rewrite the copy for both knowledgeDetails.delimiterTip and knowledgeDetails.childrenDelimiterTip (en.ts) so it explicitly states the parsing rule: - The field is a string. - Backticks group characters into one multi-character delimiter. - Any character outside backticks is itself a delimiter. - Delimiters are matched longest-first. - Single-char delimiters need no backticks; multi-char ones must be backtick-wrapped. Refs infiniflow#17382
Add a small inline preview under the "Delimiter for text" input that shows, in real time, the list of delimiters the backend will derive from the current value. Each delimiter is rendered as a small Badge with whitespace characters shown as visible Unicode glyphs (↵ newline, ⇥ tab, ␣ space, ␍ CR, ␌ FF, ␋ VT) so that whitespace-only delimiter values are no longer invisible in the single-line input. The preview mirrors the backend parser rule (backticks group chars into a multi-character delimiter; anything outside is itself a delimiter) but is informational only — the actual chunking behavior is determined by the backend, which has six divergent implementations of this rule tracked in infiniflow#17383. The helper deduplicates by display form and preserves input order rather than sorting longest-first, so the preview is readable; the user-facing tooltip (infiniflow#17382) explains the actual rule. Files: - web/src/utils/delimiter-preview.ts (new) parsing logic - web/src/components/delimiter-preview.tsx (new) display component - web/src/components/delimiter-form-field.tsx render preview - web/src/components/children-delimiter-form.tsx render preview - web/src/locales/en.ts i18n keys Refs infiniflow#17382, infiniflow#17383
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughDelimiter parsing now produces display-ready tokens, including visible whitespace glyphs and deduplication. A reusable preview component displays those tokens and localized states beside both delimiter inputs. English help text documents the parsing rules and preview labels. ChangesDelimiter preview flow
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant DelimiterForm
participant DelimiterPreview
participant Parser
participant EnglishTranslations
DelimiterForm->>DelimiterPreview: pass current delimiter value
DelimiterPreview->>Parser: parseDelimitersForDisplay(value)
Parser-->>DelimiterPreview: return displayable delimiter tokens
DelimiterPreview->>EnglishTranslations: request preview labels and count
EnglishTranslations-->>DelimiterPreview: return localized strings
DelimiterPreview-->>DelimiterForm: render empty state or delimiter badges
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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: 2
🧹 Nitpick comments (1)
web/src/components/delimiter-preview.tsx (1)
11-14: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDescribe this as a best-effort preview.
The utility explicitly notes that its parsing can differ from the backend, but this comment says the preview shows exactly what the backend will derive. Change the wording to say the preview is derived from
valueand is informational only.🤖 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 `@web/src/components/delimiter-preview.tsx` around lines 11 - 14, Update the documentation comment for the delimiter preview component to describe the output as a best-effort, informational preview derived from value, rather than an exact representation of the backend’s derived delimiters. Preserve the clarification that it does not affect the stored value or chunking behavior.
🤖 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 `@web/src/locales/en.ts`:
- Around line 622-626: Update the delimiter explanation in both tooltip strings,
including the entries immediately preceding and at childrenDelimiterTip, to
explicitly state that backticks are the delimiter-of-delimiters and that
characters inside a matching pair form one multi-character delimiter. Preserve
the remaining parsing rules and examples.
In `@web/src/utils/delimiter-preview.ts`:
- Around line 47-70: Update parseDelimitersForDisplay so deduplication uses each
delimiter’s raw value rather than the display glyph: check and record raw in the
seen Set, while retaining display only for the resulting ParsedDelimiter
rendering. Preserve input order and existing display conversion behavior.
---
Nitpick comments:
In `@web/src/components/delimiter-preview.tsx`:
- Around line 11-14: Update the documentation comment for the delimiter preview
component to describe the output as a best-effort, informational preview derived
from value, rather than an exact representation of the backend’s derived
delimiters. Preserve the clarification that it does not affect the stored value
or chunking behavior.
🪄 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: 59b86214-2016-4a84-80dc-a2ab135db2f9
📒 Files selected for processing (5)
web/src/components/children-delimiter-form.tsxweb/src/components/delimiter-form-field.tsxweb/src/components/delimiter-preview.tsxweb/src/locales/en.tsweb/src/utils/delimiter-preview.ts
- parseDelimitersForDisplay: dedup by raw value, not display glyph, so distinct delimiters that share a display form (e.g. literal newline vs. user-typed U+21B5) are no longer silently merged. - DelimiterPreview: soften the docstring to describe the output as a best-effort, informational preview rather than an exact reflection of the backend parser, matching the parser's own caveat. - delimiterTip / childrenDelimiterTip: spell out that backticks are the delimiter-of-delimiters and that a matching pair wraps the characters inside it into a single multi-character delimiter. - toDisplay: add JSDoc to lift docstring coverage on the touched files.
|
@yuzhichang @Lynn-Inf @wangq8 @dcc123456 please review! |
…anonical helper (infiniflow#17383) Six sites used to read the same `parser_config.delimiter` field with divergent grammars: * rag.nlp.get_delimiters (PDF/DOCX/HTML/EPUB/JSON/CSV/XLSX/email/book) * rag.nlp.naive_merge (custom-delimiter branch) * rag.nlp.naive_merge_with_images * rag.nlp._build_cks * deepdoc.parser.txt_parser.parser_txt (.txt, code) * deepdoc.parser.markdown_parser.MarkdownElementExtractor.get_delimiters The six implementations disagreed on bare-vs-wrapped chars, dedupe, sort order, CRLF normalization, and `re.I` (infiniflow#17384). The shipped default `\n!?;。;!?` was a no-op for .md because the markdown path only matched backtick-wrapped tokens. This PR lands the consolidation on top of infiniflow#17385 (UX layer) and infiniflow#17386 (re.I removal). Both land independently first; the new branch is a 3-way merge base with the refactor + tests on top. Changes ------- * new: `rag/nlp/delim.py` with `parse_delimiter_field` and `compile_delimiter_pattern`. Single source of truth. CRLF normalization at the top; longest-first stable sort; insertion-ordered dedupe; no `re.I`. * refactor: all six call sites delegate to the helper. - `rag/nlp/__init__.py::get_delimiters` becomes a thin shim. - `deepdoc/parser/txt_parser.py::parser_txt` drops the encode/decode/unicode_escape round-trip on the delimiter. - `deepdoc/parser/markdown_parser.py` `get_delimiters` honors bare chars (fixes bug infiniflow#1: markdown default is no longer a no-op). * tests: `test/unit_test/rag/test_delim.py` (85 tests) covers the helper directly, the acceptance table from the issue, frontend parity with `web/src/utils/delimiter-preview.ts`, and a static guard that no site re-inlines the backtick regex. * tests: `test/unit_test/rag/test_delimiter_case_sensitive.py` (from infiniflow#17386) updated to point the static check at the new helper location and broadened with an AST-based scan. Acceptance criteria ------------------- * All six sites produce the same regex pattern for the same input. * Shipped default keeps working for .txt/.pdf/.docx. * Shipped default for .md now splits (was a silent no-op). * Tooltip example `\n`##`;` produces three effective delimiters regardless of file type. * Bare whitespace inputs (" ", "\t", "\n") split on every occurrence. * Backtick-wrapped whitespace (`` `\n\n` ``) splits only on the exact N-char sequence. * CRLF-line-ending documents split identically to LF-line-ending documents, regardless of file type. * New unit tests in test_delim.py cover every row of the issue's Proposed-solution table. * Existing tests in test_naive_merge.py still pass.
Closes #17384. ## Summary Drops a dead `re.I` flag from two outlier delimiter-parsing sites and adds regression tests so the inconsistency can't creep back. ## What's wrong Two of the six delimiter-parsing implementations pass `re.I` to `re.finditer`: - `rag/nlp/__init__.py::get_delimiters` (line 1633) - `deepdoc/parser/txt_parser.py::parser_txt` (line 51) The other four implementations correctly omit `re.I`: - `rag/nlp/__init__.py::naive_merge` custom-delimiter path (line 1195) - `rag/nlp/__init__.py::naive_merge_with_images` custom-delimiter path (line 1269) - `rag/nlp/__init__.py::_build_cks` (line 1389) - `rag/flow/chunker/token_chunker.py` (line 73) ## Why this matters (and why it doesn't break anything) The flag is **dead code** today. Verified empirically with a Python REPL: ```python >>> import re >>> for m in re.finditer(r"`([^`]+)`", "`end`", re.I): ... print(repr(m.group(1))) 'end' # plain string, no flag attached >>> re.split("(a)", "Class A is a Sample") ['Cl', 'a', '', 's', ' A i', 's', ' a Sample'] # Case-sensitive: only lowercase 'a' splits. Uppercase 'A' is preserved. ``` `re.I` does not propagate from `re.finditer` to `m.group(1)` or to downstream `re.split` / `re.match` calls (which all omit `re.I`). So the actual splitting behavior has always been case-sensitive — removing the flag is a **defensive cleanup**, not a behavioral fix. So why bother? 1. **Consistency** — the two sites were the only outliers in a six-way implementation cluster. The three sibling sites in `rag/nlp/__init__.py` already omit `re.I`, which strongly suggests the flag was accidental. 2. **Future-proofing** — a refactor could easily propagate the flag to a downstream `re.split` call where it *would* change behavior. The tests added here pin the case-sensitive semantics so that regression fails loudly. 3. **Reader clarity** — the flag is misleading. Anyone reading `re.finditer(..., re.I)` reasonably assumes case-insensitive matching, then has to trace all downstream calls to discover it's a no-op. ## Changes - `rag/nlp/__init__.py` — drop `re.I` from `get_delimiters` (line 1633). - `deepdoc/parser/txt_parser.py` — drop `re.I` from `parser_txt` (line 51). - `test/unit_test/rag/test_delimiter_case_sensitive.py` — new test file with: - 4 behavioral tests on `get_delimiters` (pattern output + `re.split` round-trip). - 3 end-to-end tests through `naive_merge` (bare-char + backtick-wrapped, both cases). - 2 parametrized static checks that `re.I` / `re.IGNORECASE` is not present at either of the two `re.finditer` sites. ## Testing ``` $ pytest test/unit_test/rag/test_delimiter_case_sensitive.py -v ============================= 9 passed in 0.19s ============================== ``` All tests pass on the patched code. Before the patch, the 2 static checks fail with a clear assertion message (the 7 behavioral tests pass either way, confirming `re.I` was dead code). ## Related - #17384 — the issue this PR closes. Note the issue's reproduction code (`re.split(..., flags=re.I)`) doesn't actually match what the production code does — the production `re.split` calls all omit `re.I`, which is why current behavior is already case-sensitive. The fix here is still valuable as a defensive cleanup + test coverage, but it's not a behavioral fix per se. - #17383 — broader parser consolidation (six implementations → one). The fix here is independent and small enough to land first. - #17385 — sibling UX PR (tooltip + live preview). Files are disjoint (`web/src/**` vs `rag/nlp/**` + `deepdoc/parser/**`), so no interaction. --------- Co-authored-by: Copilot App <[email protected]> Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
…anonical helper (#17383) (#17387) ## Summary Six sites used to read the same `parser_config.delimiter` field with divergent grammars: - `rag.nlp.get_delimiters` (PDF/DOCX/HTML/EPUB/JSON/CSV/XLSX/email/book) - `rag.nlp.naive_merge` (custom-delimiter branch) - `rag.nlp.naive_merge_with_images` - `rag.nlp._build_cks` - `deepdoc.parser.txt_parser.parser_txt` (.txt, code) - `deepdoc.parser.markdown_parser.MarkdownElementExtractor.get_delimiters` The six implementations disagreed on bare-vs-wrapped chars, dedupe, sort order, CRLF normalization, and `re.I` (#17384). The shipped default `` `\n!?;。;!?` `` was a no-op for `.md` because the markdown path only matched backtick-wrapped tokens. ## Changes - **new:** `rag/nlp/delim.py` with `parse_delimiter_field` and `compile_delimiter_pattern`. Single source of truth. CRLF normalization at the top; longest-first stable sort; insertion-ordered dedupe; no `re.I`. - **refactor:** all six call sites delegate to the helper. - `rag/nlp/__init__.py::get_delimiters` becomes a thin shim. - `deepdoc/parser/txt_parser.py::parser_txt` drops the `[encode/decode/unicode_escape]` round-trip. - `deepdoc/parser/markdown_parser.py::get_delimiters` honors bare chars (fixes [1]). - **tests:** `test/unit_test/rag/test_delim.py` (85 tests) — helper, acceptance table, frontend parity, static guard against re-inlining. - **tests:** `test/unit_test/rag/test_delimiter_case_sensitive.py` (from #17386) updated to retarget the static check at the new helper + AST-based broader scan. ## Acceptance criteria - All six sites produce the same regex pattern for the same input. - Shipped default keeps working for `.txt` / `.pdf` / `.docx`. - Shipped default for `.md` now splits (was a silent no-op). - Tooltip example `` `\n##;` `` produces three effective delimiters regardless of file type. - Bare whitespace inputs split on every occurrence. - Backtick-wrapped whitespace splits only on the exact N-char sequence. - CRLF-line-ending documents split identically to LF-line-ending documents. - 123 tests pass (85 new + 38 existing). ## Rebase protocol As #17385 and #17386 evolve, this branch will be rebased on top. The only overlap between this PR's diff and the other two is `test_delimiter_case_sensitive.py`, where #17383 modifies the static check to point at the new helper location. --------- Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
Summary
Improve the UX of the "Delimiter for text" field on the dataset configuration page. The field is a single string with a backtick-based mini-syntax, but both the tooltip and the surrounding UI failed to surface what delimiters the backend would actually derive from a given value — leaving users to discover by trial-and-error that the same string produces different splits depending on file type (see #7436, #4704, #9680).
This PR makes two additive, risk-free changes:
No backend changes. No API change. No schema change. Pure presentation.
Related issues
parser_config.delimiterfield #17383 — six divergent backend parser implementations; the markdown parser silently makes the shipped default value a no-op; CRLF normalization only in one path; etc.re.I(case-insensitive), causing unintended splits on both cases of the same character #17384 —re.Icase-insensitive delimiter matching (two-line fix).The backend fix is a separate, larger refactor tracked in #17383. This PR is intentionally limited to UX so users get immediate relief while the backend consolidation is scoped and reviewed.
Changes
Two commits on branch
feat/delimiter-ux:docs(i18n): clarify the "Delimiter for text" tooltip(9258824)Updates
web/src/locales/en.tsknowledgeDetails.delimiterTipandknowledgeDetails.childrenDelimiterTip. The previous tooltip described backticks as the multi-char delimiter wrapper but never named them as the meta-delimiter. The new copy explicitly states the parsing rule:Other locales are not touched — they fall through to the English copy via
defaultValue. If the project enforces 100% locale parity, please flag and I can extend in a follow-up commit.feat(ui): add live preview of parsed delimiters next to the input(cda59bf)web/src/utils/delimiter-preview.ts(new)web/src/components/delimiter-preview.tsx(new)Badgewith monospace styling. Renders whitespace as visible glyphs (↵newline,⇥tab,␣space,␍CR,␌FF,␋VT) so whitespace-only delimiter values are no longer invisible. Falls back to an italic "No delimiters — text will be chunked by size only." message when the value is empty.web/src/components/delimiter-form-field.tsx<DelimiterPreview value={field.value} />below the input.web/src/components/children-delimiter-form.tsxweb/src/locales/en.tsdelimiterPreviewLabel,delimiterPreviewEmpty,delimiterPreviewCount.The preview is display-only — it does not touch the stored value, the form state, or anything downstream of
field.value. Disabling the preview would have zero effect on chunking behavior.Visual verification
Tested in the running app at
http://localhost(datasettest txt kg rapotor, configuration page). Six cases verified:\n(default)Splits at: ↵ (1)\n`##`;Splits at: ↵ ## ; (3)(single space)Splits at: ␣ (1)No delimiters — text will be chunked by size only.\n\n##\tSplits at: ↵ ## ⇥ (3)\ndedupe to one ↵.\tshows as tab glyph. Count is (3).!?;END` (child)Splits at: ! ? ; END (4)The preview surfaces bug #1 from #17383 (the shipped markdown default is a no-op for
.mdfiles) before the user saves — the count and the "Splits at:" badges reflect what the value actually contains, not what the backend will honor. So a markdown user who keeps the default delimiter will seeNo delimiters — text will be chunked by size only.after enabling the preview, which is the correct diagnosis.Notes for reviewers
Badgecomponent,useTranslation, and the@/*path alias already configured inweb/tsconfig.json.tsc --noEmitreports zero errors in any of them; the pre-existing errors in unrelated files are unchanged).test_naive_merge.pycovers the backend parser behavior. If unit tests are required for UI helpers, say so and I'll add a minimalparseDelimitersForDisplaytest underweb/src/utils/__tests__/or wherever the project's convention lives.en.tsonly; other locales fall through viadefaultValueinreact-i18next. Confirm whether 100% locale parity is enforced; if so I'll add the same keys tode.ts,bg.ts,ar.ts, etc. in a follow-up.docs/clarify-delimiter-tooltip; renamed tofeat/delimiter-uxonce it grew the preview commit. The git history preserves both commits, so either could be cherry-picked independently.Out of scope (tracked separately)
parser_config.delimiterfield #17383 — Collapse the six divergent backend parser implementations into one shared helper. The preview makes the bugs visible to users; only the backend fix will eliminate them.re.I(case-insensitive), causing unintended splits on both cases of the same character #17384 — Removere.Ifromget_delimitersandparser_txt(two-line change).\f,\v,\u00a0,\\— currently silently mishandled inDelimiterInput'shandleInputChange. Tracked as bug feat: Implement authentication #10 in [Bug] Delimiter parsing has 7 divergent implementations that read the sameparser_config.delimiterfield #17383; a future UX fix could surface an "ⓘ auto-converted" hint when the conversion happens.