Mรณdulo 17 ยท RAG from Scratch โ Lecciรณn 4 de 4 ยท ~11 min
Retrieve & generate
Putting it together: retrieve the top-k
You now have every piece. Retrieval is: embed the question, score it against every chunk with cosine, sort by score, and keep the best few โ the top-k (k is usually 3โ5). Those are the passages most likely to hold the answer.
sorted(..., key=..., reverse=True)[:k] does the sort-and-slice in one line โ the same sorted you'd use on any list, with a key that pulls out each chunk's score.