RAGのチャンク分割戦略
Embeddingに適した効果的なチャンクへドキュメントを分割し、RAGシステムが正確で関連性の高いコンテキストを取得できるようにする方法を学びます。
「RAGのチャンク分割戦略」はCoddyKit上の無料Vector Databases: Pinecone, Weaviate & pgvectorレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはVector Databases: Pinecone, Weaviate & pgvector学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Vector Databases: Pinecone, Weaviate & pgvectorコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Why Chunking Matters
Before embedding, documents are split into chunks. Chunk quality directly determines retrieval quality — too large dilutes relevance, too small loses context.
Fixed-Size Chunking
The simplest method splits text every N characters or tokens. Fast but can cut sentences mid-thought.
def fixed_chunks(text, size=500):
return [text[i:i+size] for i in range(0, len(text), size)]Overlapping Windows
Add overlap between chunks so context spanning a boundary is not lost. A 10-20% overlap is common.
def overlap_chunks(text, size=500, overlap=100):
step = size - overlap
return [text[i:i+size] for i in range(0, len(text), step)]Sentence-Aware Splitting
Split on sentence boundaries so each chunk stays grammatically whole. This usually improves embedding quality over raw character splits.
import re
sentences = re.split(r'(?<=[.!?])\s+', document_text)Recursive Chunking
Recursive splitting tries large separators first (paragraphs), then smaller ones (sentences, words) until chunks fit the size limit. It respects natural structure.
Semantic Chunking
Semantic chunking groups sentences by meaning similarity, starting a new chunk when topic shifts. More expensive but very precise.
Chunk Size vs Model
Match chunk size to your embedding model's context window and your LLM's prompt budget.
- Small chunks: precise but fragmented
- Large chunks: rich but noisy
Keeping Metadata
Store source, page, and position metadata with each chunk so you can cite sources and reconstruct context later.
chunk = {
'text': part,
'source': 'guide.pdf',
'page': 4,
'position': idx
}Parent-Child Chunks
Embed small child chunks for precise matching, but return their larger parent chunk to the LLM for full context. Best of both worlds.
Evaluating Chunking
Test different chunking configs with the same queries and measure retrieval hit rate. There is no universal best — measure for your data.
Practical Defaults
A solid starting point:
- Recursive splitting
- ~500 tokens per chunk
- ~50-100 token overlap
- Attach source metadata
Quick Check
Test your chunking knowledge.
Recap
You learned fixed, overlapping, sentence-aware, recursive, and semantic chunking, plus parent-child retrieval and metadata. Good chunking is the foundation of accurate RAG retrieval.
よくある質問
「RAGのチャンク分割戦略」レッスンは無料ですか?
はい。「RAGのチャンク分割戦略」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Vector Databases: Pinecone, Weaviate & pgvectorコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Vector Databases: Pinecone, Weaviate & pgvectorコースには全4レッスンが含まれています。
「RAGのチャンク分割戦略」で何を学びますか?
Embeddingに適した効果的なチャンクへドキュメントを分割し、RAGシステムが正確で関連性の高いコンテキストを取得できるようにする方法を学びます。 ブラウザで直接実行するハンズオンコードでVector Databases: Pinecone, Weaviate & pgvectorを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Vector Databases: Pinecone, Weaviate & pgvectorを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのVector Databases: Pinecone, Weaviate & pgvectorは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「RAGのチャンク分割戦略」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このVector Databases: Pinecone, Weaviate & pgvectorレッスンでコードを書いて実行できますか?
はい。すべてのVector Databases: Pinecone, Weaviate & pgvectorレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- RAGシステムのアーキテクチャ概要
- LLMフレームワークとの統合
- コンテキスト情報の検索
- RAGのチャンク分割戦略