Skip to main content

LLM engineering

Requests, streaming, JSON, retrieval, evaluation, quantisation and sampling.

0 of 17 solved · 0 of 320 XPStart: Cosine similarity
  1. 1Cosine similaritySemantic search compares embeddings with cosine similarity. Implement it and cover the edge cases: different lengths and zero vectors.Easy · 8 min · 10 XP
  2. 2Chunk text with overlapBefore indexing a document for RAG you split it into chunks. A small overlap avoids cutting an idea right in half.Easy · 10 min · 10 XP
  3. 3Read Ollama's streamOllama answers line by line in JSON. Join the text and compute tokens per second from its own counters.Easy · 10 min · 10 XP
  4. 4An OpenAI-compatible chat requestOllama, vLLM and LiteLLM accept the same format as the OpenAI API. Build the right URL and body and validate the input before sending anything.Easy · 10 min · 10 XP
  5. 5Prompt templates without surprisesFill {{variables}} in a prompt, fail when one is missing, and keep user text from opening or closing template markers.Easy · 10 min · 10 XP
  6. 6Softmax with temperatureAn LLM's temperature parameter divides the logits before the softmax. Implement it in a numerically stable way and see its effect.Medium · 10 min · 20 XP
  7. 7Read an SSE chat streamWith stream: true, the OpenAI-compatible chat API answers with Server-Sent Events. Join the text fragments and stop at [DONE].Medium · 12 min · 20 XP
  8. 8Retrieve the k most similar documentsThe retrieval step of RAG: rank documents by similarity to the query and keep the top k, with stable tie-breaking.Medium · 12 min · 20 XP
  9. 9Does the model fit in memory?The sum behind our VRAM explorer: weights, KV cache per slot and an allowance for buffers, against usable memory.Easy · 12 min · 10 XP
  10. 10BM25 by hand: the keyword search that still winsEmbeddings miss part numbers and proper names. BM25 does not: it scores by the rare words shared with the query. Write its two formulas.Medium · 15 min · 20 XP
  11. 11Fit the context windowA local model with an 8K context cannot take the whole history. Keep the system message and the most recent messages that fit.Medium · 15 min · 20 XP
  12. 12Pull the JSON out of an LLM replyYou ask for JSON and the model answers with a sentence, a json block and sometimes stray braces. Extract the first valid object or return null.Medium · 15 min · 20 XP
  13. 13Quantisation by hand: float32 to int8 and backA Q8 file stores each weight in fewer bits. Quantise eight weights to int8, restore them and measure the error, outlier included.Medium · 15 min · 20 XP
  14. 14Top-p (nucleus) samplingOllama's top_p parameter drops unlikely tokens before picking one. Implement that filter.Medium · 15 min · 20 XP
  15. 15Hybrid search: fuse two rankings with RRFBM25 and embeddings give scores that cannot be compared. Reciprocal rank fusion ignores them and uses only the positions.Medium · 18 min · 20 XP
  16. 16An eval harness: exact match, F1 and a second judgeSix questions with known answers are enough to stop judging by eye: exact match, token F1 and two judges that have to agree.Medium · 20 min · 20 XP
  17. 17Capstone: ask Ollama for JSON without it breakingCapstonePuts the track together: a streaming POST to Ollama, retries with growing waits, reading the NDJSON chunk by chunk and extracting the JSON safely.Hard · 40 min · 60 XP