Chapter 93
Chunking for Longer Texts
Chunking for Longer Texts
Our FAQ data is well-structured: each document is a question-answer pair. But what if your data is articles, transcripts, or slide decks? You need to chunk it into pieces that are the right size for embedding and retrieval.
Multiple articles
If you have multiple articles (blog posts, wiki pages, etc.
):
- Assign each article a document ID
- Split each article into chunks
- Give each chunk a unique chunk ID (e.g.,
doc_id_1,doc_id_2) - Evaluate retrieval with separate Hit Rate for both document ID and chunk ID
- Tune chunk size using RAG evaluation metrics
{
"doc_id": "abc123",
"chunk_id": "abc123_1",
"text": "first paragraph of the article..."
}Single article or transcript
If you have one long piece of content (a YouTube transcript, a PDF, etc.
):
- Split it into chunks
- Evaluate the same way as multiple articles
- You can use
youtube-transcript-apito get transcripts programmatically
Book or very long content
For books and other long-form content, apply this strategy:
- Treat each chapter or section as a separate document
- Experiment with different chunking strategies
- Use LLM-as-a-Judge to compare approaches
Images and slides
Visual content can be processed as follows:
- Describe images using an LLM like GPT-4o-mini
- Each image is a separate document
- For slide decks: deck = document, slide = chunk
- You can also use CLIP embeddings for direct image search
Smart chunking with LLMs
Instead of splitting by character count or paragraph breaks, you can use an LLM to find logical boundaries:
- Give the LLM the full text and ask it to split into logical blocks
- Then ask it to name each block
- Each block becomes a chunk you can index and search
This approach, sometimes called "semantic chunking" or "logical chunking," often produces better chunks than fixed-size splitting because the chunks map to meaningful topics.
You can see a detailed summary of content processing approaches in content-processing-summary.md.
