Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 12.2 — Summaries and Hierarchies
RAG and Vector Search · Example 1 of 1

Choose the document by its summary, then the sentence

The summaries are hand-written stand-ins for model-written ones. The coarse line shows every document's score; the overview question skips the sentences entirely.

A short summary of each document or section can be its own searchable layer. Searching summaries first picks the right document, then searching inside it finds the right sentence, and a whole-document question can be answered from the summary itself.

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 route(question) that returns "overview" when the question contains the word about, summary or overview, and "detail" otherwise. Print the route for three questions of your choice.

02

Write best_doc(question, summaries) where summaries maps a document id to its summary. Return the id whose summary shares the most different words with the question (the first wins a tie), or None when no summary shares a word. Print the result for one question that matches and one that does not.

Explain it without notes

01

Why can't sentence-level search answer "what is this document about?"

02

Describe coarse-to-fine retrieval and the problem it removes in a big collection.

03

What new costs and risks do summaries introduce?

04

How would you decide which level a question should be sent to?

Choose the document by its summary, then the sentence
Sign in to run this example in your browser.

Expected output

Q: Are lights needed at night?
  coarse: D50=3  D51=0
  answer from D50 (sentence): Switch on the bike lights from sunset to sunrise.
Q: What is the trip guide about?
  coarse: D50=0  D51=2
  answer from D51 (overview): Planning a trip: routes, bike lanes, hills, returning the bike before closing.