AI in Motion

Semantic Search with Embeddings

Natural Language ProcessingIntermediate1:105 chapters

Search by meaning, not matching words. Embed documents and queries, then find the nearest neighbours.

📄 Illustrated notes · every chapter as a picture · printable

Shortcuts: Space play/pause · ←/→ 5 s · N/P chapter · M voice · C subtitles · F fullscreen

Quick quiz

3 questions to check your understanding.

Q1 Why did “Reset your password” match “I can’t sign in”?
Q2 What must be true of the query and document embeddings?
Q3 When is keyword search still better?

Go deeper

University-level written lectures in The AI Lecture Hall:

Transcript

Introduction. Keyword search fails when people use different words for the same thing. Semantic search matches meaning instead.

Nearest neighbours. Every help article is embedded as a vector, a point in meaning space. The query, I can’t sign in, shares no words with reset your password or forgot login details. But its embedding lands right next to them, so they are returned as the top results.

The recipe. Split documents into passages, embed them, and store the vectors in a vector database. At query time, embed the question with the same model and return the passages with the highest cosine similarity.

Hybrid search. Keyword search is still great for exact names and codes. Semantic search handles paraphrases. Many real systems combine both, a hybrid search, and add a re-ranking model on top.

Recap. To recap. Embed documents and queries, find the nearest neighbours, use a vector database for speed, and combine with keyword search for the best results. This is also the first half of retrieval augmented generation.