Skip to content

Feat: optimize title chunk - #14325

Merged
yingfeng merged 4 commits into
infiniflow:mainfrom
Magicbook1108:resume
Apr 23, 2026
Merged

yingfeng merged 4 commits into
infiniflow:mainfrom
Magicbook1108:resume

Conversation

@Magicbook1108

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Feat: optimize title chunk

  1. Add a new button to enable "Use root chunk as H0 heading", so that the first chunk is carried on to all remaining chunks.
  2. Update resume agent template

Type of change

  • New Feature (non-breaking change which adds functionality)
img_v3_02111_63b04951-b3d7-4001-a08b-539db6d5298g image

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

coderabbitai Bot commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This pull request introduces a new configurable root_chunk_as_heading option that enables the first chunk's text to be propagated as a heading prefix to subsequent chunks. The feature is implemented across the backend processing logic, frontend form validation and UI controls, localization strings, and pipeline templates.

Changes

Cohort / File(s) Summary
Backend Chunking Logic
rag/flow/chunker/title_chunker/common.py
Adds root_chunk_as_heading parameter to TitleChunkerParam. Refactors build_chunks_from_record_groups to construct chunks as variables, enabling post-processing logic that copies the root chunk's text prefix to all subsequent chunks when the option is enabled and multiple chunks exist.
Frontend Localization
web/src/locales/en.ts
Adds two translation keys: flow.preprocess.rootAsHeading and flow.preprocess.rootAsHeadingTip to support UI labeling of the new feature.
Frontend Configuration & Constants
web/src/pages/agent/constant/pipeline.tsx
Updates initialTitleChunkerValues and initialGroupValues configuration objects with root_chunk_as_heading: false default.
Frontend Form Transformation & Schema
web/src/pages/agent/form/title-chunker-form/hook.ts, web/src/pages/agent/form/title-chunker-form/index.tsx
Extends form Zod schema to include optional root_chunk_as_heading boolean field. Adds API response transformation to extract the field, handles field reset during mode transitions, and introduces new switch UI control for toggling the option in hierarchy mode.
Frontend Parameter Transformation
web/src/pages/agent/utils.ts
Updates transformTitleChunkerParams to forward the root_chunk_as_heading value from form schema to backend-ready parameters payload.
Pipeline Template Configuration
agent/templates/ingestion_pipeline_resume.json
Enables root_chunk_as_heading: true in the résumé template's hierarchy configuration. Updates UI graph edge definitions with corrected metadata and adjusts node layout positions and selection state.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

size:L

Suggested reviewers

  • yingfeng
  • dcc123456

Poem

🐰 A root becomes a heading bright,
With chunks now wearing hierarchy's light,
From backend to the UI's gleam,
Configuration flows like a stream,
Hop hop, the hierarchy's a dream! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Feat: optimize title chunk' is vague and generic; it uses the non-descriptive term 'optimize' without clarifying what specific optimization is being implemented. Replace with a more descriptive title such as 'Feat: add root chunk as heading option to title chunker' that clearly conveys the main feature being added.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description includes required sections ('What problem does this PR solve?' and 'Type of change') and provides implementation details, though the problem statement could be more thorough.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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 and usage tips.

@dosubot dosubot Bot added 🌈 python Pull requests that update Python code 💞 feature Feature request, pull request that fullfill a new feature. 🧰 typescript Pull requests that update Typescript code labels Apr 23, 2026
@Magicbook1108 Magicbook1108 added the ci Continue Integration label Apr 23, 2026

@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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
rag/flow/chunker/title_chunker/common.py (1)

243-267: ⚠️ Potential issue | 🟡 Minor

Keep the simple-input branch from falling through.

Line 244 builds plain {text} chunks for markdown/text/html, but Line 250 immediately overwrites them with the PDF-style chunk shape. Use an else so simple upstream formats preserve the intended output schema before the shared root-heading post-processing.

Proposed fix
         if self.from_upstream.output_format in ["markdown", "text", "html"]:
             chunks = [
                 {"text": "".join(record["text"] + "\n" for record in records)}
                 for records in record_groups
                 if records
             ]
-
-        chunks = [
-            (
-                {
-                    "text": RAGFlowPdfParser.remove_tag("".join(record["text"] + "\n" for record in records)),
-                    "doc_type_kwd": "text",
-                    PDF_POSITIONS_KEY: merge_pdf_positions(records),
-                }
-                if records[0]["doc_type_kwd"] == "text"
-                else {
-                    "text": records[0]["text"],
-                    "doc_type_kwd": records[0]["doc_type_kwd"],
-                    "img_id": records[0]["img_id"],
-                    PDF_POSITIONS_KEY: records[0][PDF_POSITIONS_KEY],
-                }
-            )
-            for records in record_groups
-            if records
-        ]
+        else:
+            chunks = [
+                (
+                    {
+                        "text": RAGFlowPdfParser.remove_tag("".join(record["text"] + "\n" for record in records)),
+                        "doc_type_kwd": "text",
+                        PDF_POSITIONS_KEY: merge_pdf_positions(records),
+                    }
+                    if records[0]["doc_type_kwd"] == "text"
+                    else {
+                        "text": records[0]["text"],
+                        "doc_type_kwd": records[0]["doc_type_kwd"],
+                        "img_id": records[0]["img_id"],
+                        PDF_POSITIONS_KEY: records[0][PDF_POSITIONS_KEY],
+                    }
+                )
+                for records in record_groups
+                if records
+            ]
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rag/flow/chunker/title_chunker/common.py` around lines 243 - 267, The first
comprehension that builds simple "{text}" chunks for
self.from_upstream.output_format in ["markdown","text","html"] is being
overwritten by the subsequent PDF-style comprehension; change the second
comprehension into an else branch (or use elif) so that when
self.from_upstream.output_format is one of the simple formats you keep the
initial chunks and only run the PDF-style construction (using
RAGFlowPdfParser.remove_tag, merge_pdf_positions, PDF_POSITIONS_KEY,
records[0]["doc_type_kwd"], img_id) for the other formats/paths; in short,
ensure the PDF-style list comprehension is executed only when the simple-input
branch did not run.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@agent/templates/ingestion_pipeline_Resume.json`:
- Line 552: The template currently persists the editor selection by setting the
Title Chunker node's "selected": true; remove this property or set it to false
on the Title Chunker node object in the ingestion pipeline template so new
pipelines don't open with a preselected node (look for the node entry containing
"Title Chunker" and the "selected" key and delete or change it to false).

---

Outside diff comments:
In `@rag/flow/chunker/title_chunker/common.py`:
- Around line 243-267: The first comprehension that builds simple "{text}"
chunks for self.from_upstream.output_format in ["markdown","text","html"] is
being overwritten by the subsequent PDF-style comprehension; change the second
comprehension into an else branch (or use elif) so that when
self.from_upstream.output_format is one of the simple formats you keep the
initial chunks and only run the PDF-style construction (using
RAGFlowPdfParser.remove_tag, merge_pdf_positions, PDF_POSITIONS_KEY,
records[0]["doc_type_kwd"], img_id) for the other formats/paths; in short,
ensure the PDF-style list comprehension is executed only when the simple-input
branch did not run.
🪄 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: 44c3b7ad-d982-41d2-a51f-234fc09c5032

📥 Commits

Reviewing files that changed from the base of the PR and between 7817b0d and 13be9a7.

📒 Files selected for processing (7)
  • agent/templates/ingestion_pipeline_Resume.json
  • rag/flow/chunker/title_chunker/common.py
  • web/src/locales/en.ts
  • web/src/pages/agent/constant/pipeline.tsx
  • web/src/pages/agent/form/title-chunker-form/hook.ts
  • web/src/pages/agent/form/title-chunker-form/index.tsx
  • web/src/pages/agent/utils.ts

"width": 200
},
"position": {
"x": 572.7908769627791,
"y": 141.55515313482098
},
"selected": false,
"selected": true,

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.

⚠️ Potential issue | 🟡 Minor

Do not persist editor selection in the template.

Line 552 stores the Title Chunker node as selected, so new pipelines created from this template may open with an unintended preselected/highlighted node.

Proposed fix
-                        "selected": true,
+                        "selected": false,
📝 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
"selected": true,
"selected": false,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@agent/templates/ingestion_pipeline_Resume.json` at line 552, The template
currently persists the editor selection by setting the Title Chunker node's
"selected": true; remove this property or set it to false on the Title Chunker
node object in the ingestion pipeline template so new pipelines don't open with
a preselected node (look for the node entry containing "Title Chunker" and the
"selected" key and delete or change it to false).

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@agent/templates/ingestion_pipeline_resume.json`:
- Line 552: The template JSON currently leaves a transient selection flag set
(e.g., "selected": true on the résumé pipeline template entry such as the
TitleChunker:FlatMiceFix template), causing every new pipeline to start with
that step preselected; update the template by resetting that transient state to
neutral — either remove the "selected" property or set it to false on the
TitleChunker:FlatMiceFix entry (and any other pipeline-step objects that include
"selected": true) so new instances do not inherit a preselected step before user
choice.
🪄 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: 7d493793-9b35-4923-ba14-ae23449f51f7

📥 Commits

Reviewing files that changed from the base of the PR and between 13be9a7 and e30397b.

📒 Files selected for processing (7)
  • agent/templates/ingestion_pipeline_book.json
  • agent/templates/ingestion_pipeline_general.json
  • agent/templates/ingestion_pipeline_laws.json
  • agent/templates/ingestion_pipeline_manual.json
  • agent/templates/ingestion_pipeline_one.json
  • agent/templates/ingestion_pipeline_paper.json
  • agent/templates/ingestion_pipeline_resume.json

"y": 141.55515313482098
},
"selected": false,
"selected": true,

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.

⚠️ Potential issue | 🟡 Minor

Reset transient selection state before committing the template.

Leaving selected: true makes every new résumé pipeline instantiate with TitleChunker:FlatMiceFix preselected. Template state should usually be neutral.

Proposed fix
-                        "selected": true,
+                        "selected": false,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@agent/templates/ingestion_pipeline_resume.json` at line 552, The template
JSON currently leaves a transient selection flag set (e.g., "selected": true on
the résumé pipeline template entry such as the TitleChunker:FlatMiceFix
template), causing every new pipeline to start with that step preselected;
update the template by resetting that transient state to neutral — either remove
the "selected" property or set it to false on the TitleChunker:FlatMiceFix entry
(and any other pipeline-step objects that include "selected": true) so new
instances do not inherit a preselected step before user choice.

@codecov

codecov Bot commented Apr 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.97%. Comparing base (ba47c13) to head (69b984b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14325      +/-   ##
==========================================
+ Coverage   95.10%   95.97%   +0.86%     
==========================================
  Files          10       10              
  Lines         695      695              
  Branches      111      111              
==========================================
+ Hits          661      667       +6     
+ Misses         17       11       -6     
  Partials       17       17              

☔ View full report in Codecov by Sentry.
📢 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.

@yingfeng
yingfeng merged commit 75a5548 into infiniflow:main Apr 23, 2026
1 check passed
Oldcircle added a commit to Oldcircle/ragflow that referenced this pull request Apr 24, 2026
同步 infiniflow/ragflow main(v0.25.0 tag + 后续 commits)。

上游主要变更:
- REST API 大重构:user/tenant/stats/plugin/chunk/document/file2document/
  connector/langfuse/mcp/system/chat/search 全部迁到 api/apps/restful_apis/
- feat: Agent API (infiniflow#14157) / deepseek v4 (infiniflow#14346) / docling native chunking
  (infiniflow#14218) / Astraflow provider (infiniflow#14270) / title chunk 优化 (infiniflow#14325)
- refactor: doc metadata update / agent webhook → REST / 移除 legacy MCP web API
- Go 侧:retrieval_test in GO / stream think chat / zhipu thinking /
  minimax provider / balance command
- 若干 fix:think tags normalization / upload truncation / audio-video pipeline
- 7 个 ingestion_pipeline templates 重命名(Book→book 等)

冲突解决(2 处):
- CLAUDE.md:保留 fork 专属整块(Fork 信息/端口/macOS 本地/活跃文档/首次运行
  记录/Task Executor),追加上游新增的 Working Style 8 条作为独立段
- web/src/pages/dataset/testing/testing-result.tsx:保留 HEAD 版本
  (P1.7-C4 设计对齐版已内含 upstream 要加的 RAGFlowPagination + isRuned 空态
  文案,upstream 版被 HEAD 超集)

验证:
- `pytest test/agent_v2/` → 301 passed / 8 skipped(RAGFLOW_TEST_DB gate)
- 其它冲突文件 auto-merge 成功:dialog_service.py / docker/.env /
  pyproject.toml / uv.lock / locales/en.ts / dataset-table.tsx / testing-form.tsx

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai coderabbitai Bot mentioned this pull request Apr 24, 2026
1 task done
@Magicbook1108
Magicbook1108 deleted the resume branch April 28, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. 🌈 python Pull requests that update Python code size:M This PR changes 30-99 lines, ignoring generated files. 🧰 typescript Pull requests that update Typescript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants