๐งชTDD Challengeยทbeginnerยทโฑ๏ธ 15โ30mยทโญ 100 XP
M-026Build Your First Similarity Search
Description
Nebula Corp has a knowledge base of product descriptions stored as embedding vectors, but no way to search them. Build a similarity search function that takes a query vector, compares it against all stored document vectors using cosine similarity, and returns the top-K most relevant results ranked by score.
Test Cases (3)
Cosine similarity of identical vectors
Identical vectors should have similarity of 1.0
Input:cosineSimilarity([1, 0, 0], [1, 0, 0])
Expected:STARTS_WITH:1
Returns top results for pricing query
A pricing-related query should return pricing and billing docs
Input:similaritySearch([0.95, 0.05, 0.1], 2)
Expected:CONTAINS_ALL:Pricing Plans,Billing FAQ
Respects topK limit
Should return exactly topK results
Input:similaritySearch([0.5, 0.5, 0.5], 3)
Expected:CONTAINS:doc-
Related Lessons
Click Run / Check to validate your solution