Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 12.9 — Build: Parent-Child Retrieval for AskDocs
RAG and Vector Search · Example 1 of 1

AskDocs with small-to-big retrieval, compared with whole sections

Self-contained: it re-declares the three new guides and the helpers it needs. The scoring is a toy stand-in for the real retriever.

AskDocs gains small-to-big retrieval behind the same retrieve interface. Three new handbook guides are cut into sentence children, the best child decides the parent, and a small test shows whole-section search missing questions it now gets right.

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 hit_rate(find, golden) where golden is a list of (question, expected_id) pairs and find(question) returns an id or None. Return the share of questions where find returned the expected id. Print it with 2 decimals for a fake find.

02

Write margin(scores) that returns the best score minus the second best (or the best score alone if there is only one). Print it with 3 decimals for [0.429, 0.143, 0.095] and for [0.083, 0.082].

Explain it without notes

01

What changed in AskDocs and what stayed the same?

02

Why did whole-section search fail on most questions?

03

How is a hit turned into a citation?

04

What would you add before shipping this?

AskDocs with small-to-big retrieval, compared with whole sections
Sign in to run this example in your browser.

Expected output

whole sections: right source 1/4 | refused 2/2
small to big:   right source 4/4 | refused 2/2
Q: Do I stop at red lights in a group?
   found: D52.4 (0.429)
   read:  Groups of up to 6 riders can share one booking. Everyone in the group needs their own helmet. The group leader pays at the shop before the ride. Keep the group together and stop at every red light.
   reply: Keep the group together and stop at every red light. [D52]