TECHNOLOGIESTieInn Technologies

Splitting documents into chunks

RAG & Vector Search · 10 questions

Short notes

Key idea

Documents are split into chunks before embedding, because one vector can't represent a whole manual and prompts have limited room. Good chunks are small enough to be specific and big enough to make sense alone.

Syntax

  • Fixed size with overlap: e.g. 500 tokens, 50 overlapping, so a sentence cut at the edge appears in both chunks.
  • By structure: split on headings, paragraphs or sections first; fall back to size.
  • Metadata on each chunk: source file, page, section title, date.
  • Add context: prefix the chunk with its document and heading ("Returns policy > Electronics: …").

Example

A 40-page HR handbook split every 500 characters cuts "Leave: 12 days of casual leave per year" from its heading. Splitting by section keeps each policy whole, and the heading travels with the text, so "how many casual leaves?" finds it.

Traps

  • Chunks too big: several topics in one vector, so matching is fuzzy, and prompts fill up fast.
  • Chunks too small: a line without its context ("This applies to all staff") means nothing.
  • Splitting tables row by row loses the header; keep headers with rows.
  • Test chunk sizes on real questions; there's no universal best number.

Want the full lesson with step-by-step examples, a project and a certificate? RAG & Vector Search course, ₹180 →

Questions

Open in Code Lab5 free questions
5 questions

    Splitting documents into chunks

  1. Question 1easy

    Why split long documents into chunks before embedding them?

  2. Splitting documents into chunks

  3. Question 2medium

    What does this print?

    words = list(range(25))
    size, overlap = 10, 2
    starts = list(range(0, len(words), size - overlap))
    print(len(starts))
  4. Splitting documents into chunks

  5. Question 3hard

    Build a DataFrame of paragraph chunks with columns chunk_id ("<article_id>-<paragraph number from 1>"), article_id, category and text, in article order. Store it in result.

    The tables are ready as DataFrames with the same names. Store your answer in result.

    Tables
  6. Splitting documents into chunks

  7. Question 4easy

    What does this print?

    title = "Cancelling an order"
    text = "It can no longer be cancelled once shipped."
    print(title + ": " + text)
  8. Splitting documents into chunks

  9. Question 5medium

    A chunk reads "Tell us within 48 hours of delivery." Why might retrieval miss it for "What if my item arrived broken?"

5 more questions on this topic, with hints, and tests

Sign up free for 21 days of every question and test.