Embeddings and RAG practice problems
17 problems · 0 solved
Retrieval-augmented generation, or RAG, gives an LLM fresh facts by first searching a document store and then passing the best passages into the prompt. Documents are cut into chunks and turned into embedding vectors, so similar meaning ends up close in vector space. It is like an open-book exam where the skill is finding the right page fast. These problems cover each piece of a retrieval pipeline. You will split documents into overlapping chunks and chunk by sentences under a token budget, retrieve the top-k chunks for a query, rank documents with BM25, combine keyword and vector scores, merge rankings with reciprocal rank fusion, re-rank for diversity with maximal marginal relevance, truncate Matryoshka embeddings, search binary embeddings by Hamming distance, search an IVF index, score vectors with product quantization, and measure recall at k. Start with the Easy problems on top-k retrieval and rank fusion. Then do chunking and hybrid scoring, and finish with BM25, MMR and the compressed indexes. RAG is one of the most common LLM features built at companies today, and interviews for applied AI roles often ask you to design or debug one.
Easy 6
- Retrieve the top-k chunks for a query embedding
- Merge several retrievers' rankings with reciprocal rank fusion
- Truncate Matryoshka embeddings and renormalise
- Measure recall at k of an approximate index
- Rerank retrieved chunks in two stages with a score threshold
- Reorder retrieved chunks so the best sit at the edges of the prompt
Medium 7
- Split a document into overlapping chunks
- Combine keyword and vector scores with min-max normalization
- Search binary-quantised embeddings by Hamming distance
- Chunk text by sentences under a token budget
- Chunk a document at semantic breakpoints between sentences
- Pack retrieved chunks into a token budget for the prompt
- Remove near-duplicate chunks with word shingles and Jaccard similarity