Command Palette

Search for a command to run...

Hectal
Phase 12Advanced13 of 14 in RAG and Vector Search

Advanced Patterns

Parent-child retrieval, summaries, multi-vector, graphs, SQL, images and search as a tool: when plain chunks and top-k are not enough, and what each costs.

A plain RAG pipeline cuts documents into chunks, searches them, and pastes the best few into a prompt. It carries you a long way. This phase is about the questions it cannot answer well: the answer needs the paragraph around the match, the question is about a whole document, the facts sit in a table or a database, the answer needs two or three searches in a row, or the corpus is small enough that you should not be searching at all.

Each pattern here is a fix for a measured symptom, never an upgrade to apply by default. You will build each one by hand at small scale (parents and children with ids, a summary index, several vectors per passage including late interaction scored by hand, a graph of facts you extract and walk, a validator for model-written SQL, a loop that searches again and stops itself) and count what it costs in storage, calls and ways to fail. Named techniques (ColBERT, GraphRAG, RAPTOR, HyDE, CLIP) are introduced by what they do, with the papers that introduced them, and never as a recipe to copy blindly.

The phase ends with the AskDocs build: small-to-big retrieval added behind the same retrieve interface and compared with whole-section search, and a playbook that maps symptoms to patterns. Agents that plan, use many tools and keep memory belong to the coming AI Agents course. This phase covers only the part where the tool is search.

0/10 · 0%
10 topics ~3 h 17 code blocks & diagrams
Start with the first topic
1
12.1

Small Chunks to Find, Big Chunks to Read

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.

23 min 2 code practice

2
12.2

Summaries and Hierarchies

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.

21 min 2 code practice

3
12.3

More Than One Vector per Passage

One vector per passage is a compromise. A passage can have several: one per sentence, one per question it answers, or one per token with late interaction. Each helps a different failure and costs more storage.

23 min 3 code practice

4
12.4

Retrieval over a Graph

Some questions need facts that sit in different passages and are connected by who or what they mention. Extract entities and relations into a graph, then follow the links hop by hop to collect the passages a chain of facts needs.

20 min 2 code practice

5
12.5

Tables and Databases

Questions such as "how many rentals did each shop have?" are answered by a query, not by a passage. A model can write the SQL, but its output is untrusted: run it only through a read-only role, an allow-list of tables and a validator.

20 min 1 code practice

6
12.6

Images and Other Media

Images can be searched by embedding them next to text, or, as a plain baseline, by indexing their captions and the text found inside them. The baseline is cheap, explainable and often enough.

18 min 1 code practice

7
12.7

Retrieval as a Tool

Instead of searching once, let the model decide when to search and what to search for, look at the results, and search again. A step limit and a repeat check keep the loop from running away.

20 min 1 code practice

8
12.8

Long Context Windows vs RAG

When the whole corpus fits in the model's context window, you can paste it instead of searching. That is simpler, but costs input tokens on every question. Work out the numbers, and consider using both.

17 min 1 code practice

9
12.9

Build: Parent-Child Retrieval for AskDocs

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.

21 min 1 code practice

10
12.10

Playbook: Choosing an Advanced Pattern

A table that maps a measured symptom to a pattern, with recipes to copy for parent expansion within a budget, a stuck-loop guard, and where a real tool-calling search loop plugs in.

19 min 3 code practice

Practise this phase

Hands-on exercises: write the code, run it, and press Check to have it tested automatically.