HomeChallengesRepsProblemsLeaderboardTake a challenge

Rank by Similarity

Cosine similarity, top-k, and a score floor — the retrieval half of RAG, written out by hand so you know what the vector database is doing for you.

Beginner15 min on the clock5 graded checks · 100 pointsRAG and Model APIs
Graded by running your code against real cases.

What you build

  • dot(a, b) and magnitude(v)
  • cosineSimilarity(a, b) — and it must not return NaN for a zero vector
  • rank(queryVec, docs) — every doc, scored, best first
  • retrieve(queryVec, docs, { k, minScore }) — the top k that clear the floor

Done means

Identical vectors score 1, orthogonal score 0, a zero vector scores 0 rather than NaN.

How it is graded

Published in full, before you start — every point is one of these and there is nothing else. Each one runs your code; it is not a search for keywords.

  1. dot and magnitude are right+20Similarity search
  2. cosineSimilarity normalises by both magnitudes+25Similarity search
  3. A zero vector scores 0, not NaN+15Similarity search
  4. rank scores every document, best first+20Similarity search
  5. retrieve honours both k and the score floor+20Similarity search

What it teaches

The rest of RAG and Model APIs