Progress

Level 04 · Retrieval

RAG

RAG means your documents are not inside the model, so you search them and paste the useful bits into the prompt. This level shows how to pull words out of files, cut them into pieces, and find the pieces that match a question. An AI engineer needs that skill because handbooks and wikis change, and the model only knows what you put in front of it. You will also learn when one search is enough and when you should search again.

Assumes You can already write a prompt that keeps instructions separate from the text you want the model to read. · 27 study sessions · 13 modules

0 of 61 lessons0%

Ship it

Capstone: Build a Hybrid Search Engine

Build a small search over notes you already have, such as help pages you save as plain text files. Your documents are not inside the model, so the search must find the useful paragraphs with both meaning and exact words, then show those paragraphs.

You do not need a paid key. Plain Python and files on your computer are enough. A friend should type a question and see the paragraph that helps, plus the file it came from.

  1. 1. Ingest, chunk, embed & index a real corpus

    1. Make a folder named corpus and save at least eight plain-text notes in it. Public help pages you copy yourself are fine. Do not use a paid source.
    2. Open ingest.py. Read every file, drop a repeated header if you added one, and keep filename and paragraph number on each block.

    3. Split on blank lines so each chunk is one paragraph. Give every chunk an id.

    4. Build a toy vector per chunk by counting a few words you care about, and store the chunks in a list of dicts. One scoring method is enough at this step.

    5. Done when running python ingest.py prints at least eight chunks, and each line shows an id, a filename, and the first six words.

  2. 2. Dense + BM25 + hybrid retrieval

    1. Open search.py and load the chunks from the previous step.
    2. Write keyword_search that ranks by shared words, with a bonus when a rare exact token matches.

    3. Write dense_search using your toy vectors, and fuse the two ranked lists with 1 / (60 + rank).

    4. Add a filter, such as filename contains handbook, and show one query whose fused top hit differs from both single lists.

    5. Done when one printed query shows three rankings, the filter removes at least one file, and you can point to a fused winner that was not rank 1 in both lists.

  3. 3. Deploying a search API or UI

    1. Open serve.py and write a function answer(query) that returns the top chunk text, the filename, and the score. A function is enough. You do not need a web server or a key.
    2. If you want a page, write a single HTML file with a box that is optional. The Python function is the required piece.

    3. Put one sample query in a comment and in the printed banner so the demo is not a blank prompt.

    4. Run python serve.py and type the sample query when it asks, or pass the query as a variable at the bottom of the file.

    5. Done when the terminal shows the paragraph, the filename, and a score for that sample, and a second query you type returns a different filename or a clear no-hit line.