Skip to content
tezvyn:
Menu

Vector embeddings and vector databases

Source: interviewMediumHow cards are made

Summary

grasp of embeddings and ANN search.

Key points

an embedding is a learned dense vector capturing semantic meaning, and vector DBs use ANN indexes like HNSW for fast similarity search that relational B-trees cannot provide.

What's really being asked

This checks whether you understand what embeddings represent and how similarity search can benefit from purpose-built indexing as a collection grows.

The full answer

A vector embedding is a dense, fixed-length array of floating-point numbers produced by a machine learning model, mapping an item, such as text, an image, or audio, into a high-dimensional space where geometric closeness reflects semantic similarity. Two sentences with similar meaning land near each other even if they share no words. Similarity search means finding the vectors nearest to a query vector under a distance like cosine or Euclidean.

Why a specialized database

You can store vectors in a relational database and scan distances directly for a small collection. For larger collections, an ANN index such as HNSW or IVF can speed up nearest-neighbour search; the specialised index is useful for scale, not mandatory for every search. So a naive SQL query computing distance to every row and sorting is a full O(n) scan, which collapses at millions of vectors. Vector databases, and vector extensions, implement approximate nearest neighbor indexes such as HNSW, IVF, or product quantization that trade a little recall for sublinear query time, plus features like metadata filtering, sharding, and efficient bulk ingestion tuned for embeddings.

Nuance

Modern relational systems with extensions like pgvector can do ANN too, blurring the line; the real distinction is having an ANN index and embedding-centric tooling, not the relational versus non-relational label.

What usually comes next

What is HNSW. Cosine versus Euclidean distance. How do you filter by metadata and vector together. What is recall in ANN.

A concrete example

A semantic document search embeds each document with a model into 768-dimensional vectors stored in a vector database with an HNSW index. A user query is embedded the same way, and the database returns the ten nearest documents in milliseconds, something a relational distance scan over millions of rows could not do.

Interview question

Why is a plain relational table with a vector column poor at similarity search over millions of rows?

  • a.Vectors must be normalized, which relational engines cannot do
  • b.Relational databases cannot store arrays of floating-point numbers
  • c.Cosine distance is impossible to compute in SQL
  • d.B-tree indexes can't accelerate high-dimensional nearest-neighbor queries, forcing a full scanCorrect
Why?

Standard indexes only speed equality and range queries, so nearest-neighbor search degrades to an O(n) distance scan; vector databases add ANN indexes like HNSW for sublinear search. Storing arrays and computing distance in SQL are both possible.

Just read this? Test yourself on what you have been reading.

Read the original → en.wikipedia.org

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.

See open roles