# Document Chunker

> ドキュメントを RAG パイプラインや LLM コンテキストウィンドウ向けにオーバーラップするトークンチャンクへ分割。依存関係ゼロ。

- Skill: `ellmos-ai/document-chunker-4` (Agent Skill)
- Install (CLI): `npx skillmds@latest add ellmos-ai/document-chunker-4`
- Raw SKILL.md: https://api.skillmd.com/api/skills/ellmos-ai/document-chunker-4/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: ellmos-ai (https://skillmd.com/u/ellmos-ai)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/ellmos-ai/document-chunker-4

---


<img src="banner.png" width="100%" alt="document-chunker banner">

> **日本語** — `document-chunker` の公式日本語版。


# Document Chunker (日本語)

ドキュメントをオーバーラップするトークンチャンクに分割します。RAG パイプラインや
LLM コンテキストウィンドウに最適化されています。依存関係ゼロ — Python 標準ライブラリ + re のみ。

## 使い方

### ライブラリとして使用
```python
from document_chunker import DocumentChunker

chunker = DocumentChunker(chunk_size=400, overlap=80)
chunks = chunker.chunk_text("Long text...")

for chunk in chunks:
    print(f"Chunk {chunk['chunk_id']}: {chunk['tokens']} tokens")
```

### ファイルの分割
```python
chunks = chunker.chunk_document("document.md", source="My Project")
```

### ディレクトリ全体の分割
```python
from document_chunker import chunk_corpus

chunks = chunk_corpus(["doc1.md", "doc2.txt"], source="Corpus")
```

### CLI
```bash
python document_chunker.py document.md    # Single file
python document_chunker.py ./docs/        # Entire directory
```

## パラメータ

| パラメータ | デフォルト値 | 説明 |
|-----------|-------------|-------------|
| chunk_size | 400 | チャンクごとの最大トークン数 |
| overlap | 80 | チャンク間のオーバーラップトークン数 |

## サポートされているファイル形式

`.txt`, `.md`, `.py`, `.sh`

## 変更履歴

### 1.0.0 (2026-03-12)
- BACH system/tools/document_chunker.py から移植

