Embeddings and vector search interview questions
Turning text into vectors and finding nearest neighbours fast. Ten practice questions with answers, for AI Engineer interviews.
Semantic search
Show answer
Finding documents by meaning rather than exact keyword matches, typically using embeddings.
'car' can match 'automobile'.
What is a text embedding?
- A vector of numbers representing the meaning of text, so similar meanings are close together
- A compressed copy of the text
- The text's token IDs
- A summary written by an LLM
Show answer
A vector of numbers representing the meaning of text, so similar meanings are close together
Distance in embedding space approximates semantic similarity.
Which similarity measure is most common for comparing text embeddings?
- Cosine similarity
- Edit distance
- Jaccard index on characters
- Manhattan distance on token IDs
Show answer
Cosine similarity
It compares direction regardless of length; for normalised vectors it equals the dot product.
Why might pure vector search fail on a query like 'error code E-4021'?
Show answer
Embeddings capture general meaning and may not preserve exact rare tokens like specific codes, so semantically similar but wrong documents can rank higher. Keyword or hybrid search matches the exact string reliably.
A common reason to add BM25 alongside vectors.
Hybrid search
Show answer
Combining keyword search (like BM25) with vector search and merging the results, to get both exact-term matching and semantic matching.
Helps with names, codes, and rare terms embeddings handle poorly.
Why do vector databases use approximate nearest neighbour (ANN) indexes like HNSW?
- Exact search over millions of vectors is too slow; ANN trades a little recall for big speed gains
- ANN is always more accurate
- Exact search is impossible
- ANN reduces embedding size
Show answer
Exact search over millions of vectors is too slow; ANN trades a little recall for big speed gains
Brute force is fine for thousands of vectors; ANN matters at scale.
pgvector
Show answer
A Postgres extension that adds a vector column type and similarity search, including ANN indexes.
Lets you keep vectors next to your relational data.
How would you choose an embedding model for a new product?
Show answer
Build a small labelled retrieval eval from real queries and relevant documents, then compare candidate models on retrieval metrics like recall@k. Also weigh cost per token, latency, vector dimension (storage and speed), max input length, language support, and whether you can host it or depend on an API.
Public leaderboards are a starting point, not a decision.
Explain the trade-off of embedding dimension size.
Show answer
Higher-dimensional embeddings can capture more nuance and sometimes improve retrieval quality, but they cost more storage and memory and make similarity search and indexing slower. Lower dimensions are cheaper and faster but may lose accuracy. Some models support truncating dimensions, so you can measure the quality loss on your eval.
It's a quality vs cost/speed decision you should measure.
You switch to a new embedding model. What must you do with your existing index?
- Re-embed all documents with the new model
- Nothing; vectors are compatible
- Only re-embed new documents
- Normalise old vectors
Show answer
Re-embed all documents with the new model
Different models produce incompatible vector spaces; queries and documents must use the same model.
Practise these with spaced repetition and AI grading, then try a mock interview.
Start Learning Free