Modern AI Engineering

Lesson 10.3 · 23 min · video lesson

Semantic Search: Finding Meaning, Not Just Keywords

A customer types "I forgot my login" and the perfect help article is called "How to reset your password". They share zero words. How can search still find it?

In short: Keyword search matches the exact words of a query, so it misses synonyms and paraphrases. Semantic search turns the query and every document into embeddings (vectors that capture meaning), stores them in a vector database, and returns the documents whose vectors are closest to the query vector, usually by cosine similarity. Approximate nearest neighbour indexes keep this fast for millions of documents.

What you will learn

  • What is keyword search
  • Where keyword search fails
  • What is Semantic Search
  • What is an embedding
  • How similar meanings sit close together
  • How we measure closeness with cosine similarity
  • What is a vector database
  • The full Semantic Search flow
  • Approximate nearest neighbor for speed at scale
  • Semantic Search in the real world

In this lesson

  1. What is keyword search, and where does it fail?
  2. What is semantic search?
  3. What is an embedding, and why similar meanings sit close together
  4. Measuring closeness with cosine similarity
  5. The vector database and the full semantic search flow
  6. Code you can run: keyword vs semantic
  7. Approximate nearest neighbour for speed at scale
  8. Keyword vs semantic search, and semantic search in the real world
  9. Worked example, step by step
  10. Practice: try it yourself

Key terms in this lesson

Keyword search
Search that matches the exact words of the query, usually ranked with BM25.
Inverted index
A map from each word to the documents that contain it.
Semantic search
Search that ranks results by similarity of meaning using embeddings.
Embedding
A fixed-length vector a model produces so similar meanings get nearby vectors.
Cosine similarity
The cosine of the angle between two vectors; 1 means the same direction.
Vector database
A store for vectors and metadata that answers nearest-neighbour queries fast.

This lesson is part of the Generative AI Engineering and Complete AI Engineer tracks. See plans and pricing to open the full lesson, its video, labs and quiz, or try the free lesson first (free account needed).

← 10.2 ANN Search: Finding Similar Vectors Without Brute Force · 10.4 Hybrid Search: Combining Sparse and Dense Retrieval →