What are the most effective document chunking strategies for RAG?
Document chunking strategies significantly impact RAG retrieval quality. Fixed-size chunking splits text at regular intervals with optional overlap, simple but can break semantic boundaries. Recursive character splitting uses hierarchy of separators like paragraphs, sentences, and words to find natural break points. Semantic chunking uses embedding similarity to group semantically related sentences into chunks. Document-structure-aware chunking respects headings, sections, and document hierarchy. For code, AST-based chunking splits at function and class boundaries. Sliding window with overlap typically 10-20% ensures context is not lost at boundaries. Chunk size varies by use case, with 256-512 tokens for precise factual retrieval and 512-1024 tokens for broader context needs. Parent-child chunking stores both small chunks for precise retrieval and their parent sections for richer context in generation.