We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Semantic Chunking

Word-based chunking with overlap helps preserve context, but it still splits text at arbitrary word boundaries. For example:

  • "Ted explores themes of friendship"
  • "of friendship and growing up"
  • "growing up while John must"
  • "John must choose between his"

Notice how "Ted explores themes" gets separated from "of friendship and growing up"? The chunks don't follow the author's intended meaning.

Semantic chunking respects natural language structure like sentences and paragraphs. Each chunk contains complete thoughts as the author organized them. Instead of splitting at random words, we split at natural breaks like sentences or paragraphs.

  • "Ted is a 2012 comedy film directed by Seth MacFarlane."
  • "The story follows John Bennett and his magical teddy bear."
  • "The film explores themes of friendship and growing up."

You can still use overlap with semantic chunking. This preserves both meaning and context continuity.

Assignment

Implement semantic chunking that splits text on sentence boundaries to preserve meaning.

  1. Semantically chunking 85 characters
    1. First sentence here. Second sentence here.
    2. Second sentence here. Third sentence here.
    3. Third sentence here. Fourth sentence here.
    

Run and submit the CLI tests.