Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 12.1 — Small Chunks to Find, Big Chunks to Read
RAG and Vector Search · Example 1 of 1

Small chunks find, parents are read

Word overlap stands in for a real search so the example is exact. Children carry their parent's id, repeated parents are removed, and the last line of each question is the cost of what would be sent.

Search small pieces because their meaning is sharp, then hand the model the larger section each piece came from. Stable ids linking a child to its parent make this a few lines of code.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write parent_of(chunk_id) that returns the part of a chunk id before the first dot, and unique_parents(chunk_ids) that returns the parent ids without repeats, in the order they first appear. Print unique_parents for D50.2, D51.1, D50.4.

02

A parent section has 34 words and the matching chunk has 9. Write context_words(parent_ids, sizes) that adds up the words sent when each parent is sent once. Print the total for ["D50", "D50"] sent naively (a list with a repeat) and for the same list after removing repeats, with sizes = {"D50": 34}.

Explain it without notes

01

What problem does parent-child retrieval solve, and why can't a single chunk size solve it?

02

Describe the data you store and the steps at query time.

03

Two of the top three children share a parent. What do you do, and why?

04

Name two risks of small-to-big retrieval and how you reduce each.

Small chunks find, parents are read
Sign in to run this example in your browser.

Expected output

Q: When should I turn on the bike lights?
  hit D50.2 score 4
  hit D50.4 score 2
  parents sent: D50 (34 words)
Q: Where do I return the bike?
  hit D51.4 score 3
  hit D50.2 score 2
  parents sent: D51, D50 (72 words)