Skip to content

Feature/advanced markdown split - #761

Open
Naraku215 wants to merge 10 commits into
ConardLi:mainfrom
Naraku215:feature/advanced-markdown-split
Open

Feature/advanced markdown split#761
Naraku215 wants to merge 10 commits into
ConardLi:mainfrom
Naraku215:feature/advanced-markdown-split

Conversation

@Naraku215

@Naraku215 Naraku215 commented Jul 3, 2026

Copy link
Copy Markdown

变更类型

  • 新功能(feat)

Related Issues

Closes #758

变更描述

新增 Advanced Markdown Split 分块模块,解决现有 Markdown 结构分块在处理复杂学术文献时表格被切断、公式被破坏、标题上下文丢失、产生空块等问题,并配套一套完善的质量评估和分块信息统计体系和更完善的可视化自主分块编辑操作,另外,统计信息导航重评分功能支持用户在原有的分块效果上不断优化分块质量。

做了什么:

  1. 原子块保护机制 — 自动识别表格、代码块、数学公式、列表等不可分割结构,用占位符保护,分块完成后精确还原,确保这些结构永远不会被切断
  2. 大纲感知分块 — 基于标题层级提取文档大纲,贪心合并段落为分块,每个分块携带 headingPath 记录其所属章节路径
  3. 语义亲合度合并 — 短块合并时通过标题路径的共同前缀、交集标题、兄弟关系计算亲合度,选择最优合并方向
  4. 质量评分体系 — 5 维度(长度适当性 / 标题存在性 / 句子完整性 / 原子块完整性 / 内容多样性)0-100 分,支持统计导航
  5. 智能句子分割 — 正确处理中英文混合文档中的缩写(Dr. et al.)、小数(3.14)、省略号等边界情况
  6. 前端交互界面 — 分块预览、大纲树导航、分块编辑/删除/上下合并/拆分//拆分后自动添加标题上下文/重评分与统计、统计项点击跳转到对应 chunk

变更规模: 26 files changed, +3141 / -6 lines

前端图示

image image

关于测试

注意到项目目前尚未配置测试框架(package.json 中无 test script、无测试依赖、仓库中无现有测试文件)。本 PR 暂未添加测试用例,以避免在未与项目维护者协商的情况下引入测试框架选型(vitest / jest 等)和包管理器冲突(npm vs pnpm)。

本新增模块的所有主要测试已在本地验证通过,再如需添加测试,我可以在后续单独提交中配合项目统一配置测试基础设施。

后续建议

本模块可以看做是原markdown文档结构分块方法和自定义分块模式的组合优化,为了项目精简,建议取代这两个模块。

文档更新

  • README.md
  • README.zh-CN.md

English Version

Change Type

  • New Feature (feat)

Related Issues

Closes #758

Description

Introduces the Advanced Markdown Split module to address issues with the existing Markdown structure splitting when processing complex academic documents — tables being cut, formulas broken, heading context lost, and empty chunks generated.

What this PR does:

  1. Atomic block protection — Automatically detects indivisible structures (tables, code blocks, math formulas, lists), replaces them with placeholders during splitting, and restores them exactly afterward
  2. Outline-aware chunking — Extracts document outline from heading hierarchy, greedily merges sections into chunks, each carrying a headingPath recording its section path
  3. Semantic affinity merging — Short chunks are merged based on heading path analysis (common prefix, intersecting headings, sibling relationships) to select the optimal merge direction
  4. Quality scoring system — 5 dimensions (length adequacy / heading presence / sentence completeness / atomic integrity / content diversity) scored 0-100, with statistics-based navigation
  5. Smart sentence splitting — Correctly handles abbreviations (Dr., et al.), decimals (3.14), ellipsis, and mixed CJK/Latin text
  6. Interactive UI — Chunk preview, outline tree navigation, chunk edit/delete/merge operations, click-to-navigate from statistics to specific chunks

Change stats: 26 files changed, +3141 / -6 lines

About Tests

The project currently has no test framework configured (no test script in package.json, no test dependencies, no existing test files in the repository). This PR does not include test cases to avoid introducing a testing framework choice (vitest / jest, etc.) and package manager conflicts (npm vs pnpm) without consulting the project maintainer first.

If tests are needed, I'm happy to contribute them in a follow-up PR aligned with the project's unified test infrastructure setup.

Documentation Updates

  • README.md
  • README.zh-CN.md

Naraku215 added 7 commits July 1, 2026 14:17
- Add atomics module for detecting and protecting tables, code blocks, math formulas, and lists during splitting

- Add chunker engine with sentence-level splitting and semantic affinity based short chunk merging with continuation title cleanup

- Add quality scoring module with multi-dimensional assessment

- Add outline extraction and heading path tracking
- Register advanced-markdown split type in text-splitter

- Add API route for split preview with chunk quality scores

- Add API route for saving split results to database

- Add API route for retrieving saved chunks
- Add AdvancedChunkDialog with outline tree and chunk preview

- Add ChunkPreviewList with quality score display

- Add OutlineTreePanel for document structure navigation

- Integrate advanced split options into TaskSettings

- Add split type constants and settings hook
- Add headingPath field to Chunks model in Prisma schema

- Add chunk query methods in db/chunks module

- Add i18n translations for advanced split features (en, zh-CN, it, pt-BR, tr)
…g in atomics

- Extract beforeStart variable to avoid redundant Math.max calls and fix
  offset calculation in expandTableContext
- Escape $ characters in atom content during restore to prevent special
  replacement patterns ($&, $1, etc.) from corrupting output
@Naraku215
Naraku215 force-pushed the feature/advanced-markdown-split branch from 4e303bc to 85856ab Compare July 6, 2026 01:20
@Naraku215
Naraku215 changed the base branch from dev to main July 6, 2026 02:06
@Naraku215 Naraku215 closed this Jul 6, 2026
@Naraku215 Naraku215 reopened this Jul 6, 2026
@Naraku215 Naraku215 closed this Jul 6, 2026
@Naraku215 Naraku215 reopened this Jul 6, 2026
@netlify

netlify Bot commented Jul 6, 2026

Copy link
Copy Markdown

Deploy Preview for gleeful-palmier-13a6af ready!

Name Link
🔨 Latest commit e740900
🔍 Latest deploy log https://app.netlify.com/projects/gleeful-palmier-13a6af/deploys/6a4c734e76746f00083ed676
😎 Deploy Preview https://deploy-preview-761--gleeful-palmier-13a6af.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Naraku215 added 2 commits July 6, 2026 17:29
…error logging and complete i18n

- Delete 7 duplicate scoring functions from AdvancedChunkDialog.js, import from scoring.js instead

- Convert scoring.js from CommonJS to ES Module exports

- Replace hardcoded Chinese '所属章节:' with English 'Section:' in content generation

- Add backward-compatible regex matching for both 'Section:' and '所属章节:'

- Replace hardcoded Chinese '文本块' with 'Chunk' in fallback strings

- Add console.error logging in catch block for summary generation failures

- Add 33 missing i18n keys to it, 31 to pt-BR and tr translation files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]We need a more powerful Markdown document chunking feature for handling complex scientific papers

1 participant