Vector DBs & RAG (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
Chunking Strategies: Fixed-size, Recursive Character Splitting, Semantic Chunking, and Document-aware chunking.
senior Levelvector-databasesAdvanced Internals
In Simple Words: How you chop source documents directly dictates RAG quality:
- Fixed-Size Chunking (e.g. 500 tokens with 50 token overlap): Fast and simple, but often splits mid-sentence or cuts a crucial paragraph in half.
- Recursive Character Splitting: Attempts to split by double newlines (
\n\n), then single newlines (\n), then spaces, preserving natural paragraph and sentence boundaries. - Semantic Chunking: Computes embeddings for individual consecutive sentences. When the cosine distance between sentence $N$ and $N+1$ exceeds a statistical threshold (e.g. 95th percentile delta), a new chunk is started because the topic has shifted!
- Document-Aware Chunking: Parses Markdown headings (
#,##), HTML tags, or PDF sections so headers are prepended to every chunk as contextual metadata.