Files
nexus/wiki/concepts/文档分块.md
2026-04-16 13:01:42 +08:00

43 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
id: document-chunking
title: 文档分块
type: concept
tags: [RAG, 数据预处理]
sources: ["RAG从入门到精通系列1基础RAG.md"]
last_updated: 2026-04-16
---
## Definition
文档分块Chunking / Splitting是将长文档切分为适合 LLM [[Context Window]] 大小的小块的过程,是 [[RAG]] Indexing 阶段的关键步骤。
## Problem
LLM 的 Context Window 有限512~8192 token无法一次处理整本手册或长文章必须分块喂入。
## Chunking Strategies
| 策略 | 描述 | 适用场景 |
|------|------|---------|
| 固定长度 | 按 token 数切分512/1024 | 通用,均匀 |
| 段落切分 | 按自然段落边界切分 | 保留语义完整性 |
| 递归切分 | 按层级递归切分(标题→段落→句子) | 结构化文档 |
| 语义切分 | 按主题/意图边界切分 | 高质量检索 |
| Overlap | 块间重叠(如 128 token 重叠) | 防止块边界信息丢失 |
## Key Parameters
- **chunk_size**:每个块的最大 token 数512~1024 常见)
- **chunk_overlap**:块间重叠 token 数(通常 64~128
## Tool Examples
- LangChain`RecursiveCharacterTextSplitter``RecursiveJsonSplitter``MarkdownHeaderTextSplitter`
## Connections
- [[RAG]] ← 必经阶段Indexing 流程的第一步)
- [[向量检索]] ← 下游(分块后向量化,再检索)
- [[Embedding]] ← 依赖(每个块独立 Embedding
- [[Context Window]] ← 约束来源(分块大小上限由 Context Window 决定)
## Quality Impact
分块质量直接影响 [[RAG]] 检索效果:
- 块太大Context 稀释有效信息,检索精度下降
- 块太小:丢失上下文,同一主题信息被割裂
- 重叠太小:块边界处的重要信息被截断