Free lab · runs in your browser · no sign-up
Build a tiny semantic search with cosine similarity
Every RAG system and vector database does one thing at its core: turn text into vectors and find the closest ones. Here you build that with NumPy, using small hand-made vectors so you can see every number.
Step 1: cosine similarity
Cosine similarity compares directions: 1 means the same direction, 0 unrelated, −1 opposite.
Step 2: rank documents for a query
Each document gets a vector (made by hand here; an embedding model makes them in real systems). Score them all and keep the top k.