Modern AI Engineering

Lesson 10.1 · 27 min · video lesson

Vector Databases: Storing and Searching Embeddings at Scale

How does a database find "I forgot my password" when the help article is titled "Reset your login credentials" and the two share no words at all?

In short: A vector database stores embeddings (lists of numbers that capture meaning) next to the original data and answers one question very fast: which stored vectors are closest to this query vector? It measures closeness with cosine similarity, dot product or Euclidean distance, and uses approximate indexes such as HNSW, IVF and PQ so it does not have to compare the query with every vector.

What you will learn

  • What is a Vector Database?
  • A quick recap of embeddings
  • Why normal databases fall short
  • What a Vector Database actually stores
  • How do we measure similarity?
  • Cosine similarity
  • Dot product
  • Euclidean distance
  • The nearest neighbour problem
  • Why brute force is too slow
  • Approximate Nearest Neighbour (ANN) and indexing
  • HNSW explained simply
  • IVF explained simply
  • PQ explained simply
  • A small code example
  • Real-world applications of Vector Databases

In this lesson

  1. What is a vector database?
  2. A quick recap of embeddings
  3. Why normal databases fall short
  4. What a vector database actually stores
  5. How do we measure similarity?
  6. The nearest neighbour problem and why brute force is too slow
  7. Approximate Nearest Neighbour (ANN) and indexing
  8. HNSW, IVF and PQ explained simply
  9. A small code example
  10. Real-world applications and common mistakes
  11. Worked example, step by step
  12. Practice: try it yourself

Key terms in this lesson

Vector database
A database that stores vectors with metadata and answers nearest-neighbour queries quickly.
Embedding
A list of numbers produced by a model so that similar inputs get nearby vectors.
Cosine similarity
The cosine of the angle between two vectors; 1 means same direction, length is ignored.
k-NN search
Finding the k stored vectors closest to a query vector.
ANN
Approximate nearest neighbour search: very fast search that returns almost always the true nearest neighbours.
Recall@k
The fraction of the true top-k neighbours that the search actually returned.
HNSW
A layered graph index that finds neighbours by greedy hops from coarse to fine layers.
Product Quantization
A compression method that replaces sub-vectors with short codebook IDs to save memory.

This lesson is free. Sign in or create a free account to open it with its video and quiz.

← 9.5 Context Compaction: Fitting More Into a Finite Window · 10.2 ANN Search: Finding Similar Vectors Without Brute Force →