Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to Generative AI Notes
Topic #1106

Chunking Strategies

Beyond naive fixed-size splitting, several chunking strategies exist, each better suited to different content structures — choosing the right one is a real, measurable lever on retrieval quality.

Fixed-Size Chunking

Split text every N characters/tokens, with some overlap.
Simple, predictable, but ignores document structure entirely —
can split mid-sentence or mid-thought.

Sentence/Paragraph-Based Chunking

Split at natural sentence or paragraph boundaries, grouping
them until reaching roughly the target chunk size.
→ Respects natural language structure, avoiding awkward
  mid-sentence splits.

Recursive/Hierarchical Chunking

Try splitting by larger structural units first (sections,
then paragraphs, then sentences), falling back to smaller
units only if a piece is still too large.
→ Better preserves document structure (headings, sections)
  than naive fixed-size splitting.

Semantic Chunking

Use embeddings to detect where the TOPIC actually shifts
within the text, and split there — rather than at a fixed
size or a purely structural boundary.
→ Chunks align with actual topic boundaries, but this
  approach is more computationally expensive (requires
  embedding calls during chunking itself) and adds complexity.

Document-Structure-Aware Chunking

Use the document's own structure — headings, sections, table
boundaries, code blocks — as natural chunk boundaries.
→ Particularly effective for structured content like technical
  documentation, Markdown files, or well-formatted reports.

Choosing a Strategy

Content TypeReasonable Starting Point
Well-structured docs (Markdown, technical docs)Structure-aware chunking
Prose-heavy content (articles, reports)Sentence/paragraph-based or recursive chunking
Highly variable, mixed contentSemantic chunking, if the added complexity/cost is justified by measured quality gains
Quick prototype / unclear requirements yetFixed-size with reasonable overlap — simple, works as a baseline

Practical Use Case

Technical documentation with headings and code examples benefits significantly from structure-aware chunking (keeping a code example with its explanation, not splitting them apart) — a chunking strategy mismatched to content type is a common, fixable source of mediocre RAG performance.

Common Mistakes

  • Defaulting to fixed-size chunking for structured content where a structure-aware approach would clearly perform better
  • Adopting semantic chunking's added complexity and cost without first measuring whether simpler approaches are actually insufficient
  • Never comparing chunking strategies empirically against real queries — assuming one approach is "obviously" better without testing

Interview Relevance

"How would you chunk a technical documentation site with headings, code blocks, and prose?" — structure-aware chunking that respects headings and keeps code examples intact with their explanations is the expected strong answer.

Practice Question

Recommend a chunking strategy for a knowledge base of legal contracts with numbered clauses, and justify the choice.

Related Notes

Want to go beyond the notes?

Join CodingNow's Generative AI course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →