FixTheRobot Explore Robotics / LLM / LM11 / LM11-L1

This lab works on phones, but writing code is much easier on a laptop.

LLM · Building LLM Applications · LM11-L1 · Intermediate

Chunking and Retrieval

A retrieval system answers a question by finding the passages that probably contain the answer and handing only those to a language model. The model can then be right only if retrieval found the right passage.

You will see how chunk size, overlap and the number of retrieved chunks trade recall against context length, then write the chunker and a TF-IDF ranker yourself.

Your task

    Simulation
    solution.pyLoading Python…
    Ctrl+Enter runs
    What Python can I use?

    Plain Python with math (and slamkit for small matrix helpers: matmul, transpose, solve, inverse, identity). Images, point clouds and detections arrive as lists inside the dictionary D; an image is a list of rows, each row a list of pixels. There is no NumPy or OpenCV: you write the algorithm yourself, which is the point of the lab. Print with print().

    Hints

    What this lab teaches

    Stage 1 explores the retrieval design space on eight synthetic robot manuals. Stage 2 writes a word chunker with overlap. Stage 3 writes TF-IDF retrieval with cosine similarity. Only retrieval is simulated: no language model reads the passages and nothing is generated. Your code is graded on hidden documents and questions.

    Theory for this lab

    Building LLM Applications labs

    1. LM11-L1: Chunking and Retrieval: this lab.
    2. LM11-L2: Validate Structured Outputs and Tool Calls
    3. LM11-L3: Build a Retrieval Question-Answering Prototype

    Educational simplification: synthetic one-sentence facts in template language, exact word matching without stemming, a single retrieval method (TF-IDF), a recall measure that checks whether the sentence with the answer lies completely inside a retrieved chunk. Real documents are messier and real retrievers often use learned embeddings.

    Get the next lab

    Get notified when new robotics labs are released. One email per new lab, nothing else.