The interview question

“What is an embedding, and how would you use it for retrieval?”

An embedding represents an object as a vector whose geometry is useful for a task. The object might be a word, document, user, product, or image. What “nearby” means depends on the training objective and the similarity function.

01. Connect representation to the objective

A one-hot product ID identifies a product but does not express similarity between IDs. A learned embedding can place products with related behavior or content near one another. That geometry is learned from data; it is not a universal map of meaning.

For query–document retrieval, train or choose an encoder suited to matching queries with relevant documents. A representation trained for a different language, domain, or similarity task may perform poorly even if its vectors have the expected dimension.

Google's embeddings module introduces dense representations. In system design, the next question is whether the representation helps retrieve relevant candidates under your constraints.

02. Compare similarity functions

Dot product = a · b
Cosine similarity = (a · b) / (‖a‖ × ‖b‖)

Let the query vector be (1,0). Candidate A is (2,0), and candidate B is (100,100). Dot product ranks B above A: 100 versus 2. Cosine ranks A above B: 1 versus about 0.707.

Vector magnitude changed the result. Normalize only when that matches the model's intended similarity. If both vectors have unit norm, cosine and dot product coincide, and squared Euclidean distance is 2 − 2 × dot product.

Zero vectors require explicit handling because their cosine denominator is zero. An embedding service failure should not silently create apparently valid but meaningless vectors.

03. Build and evaluate the index

For a small catalog, exact scoring may be sufficient. At larger scale, approximate nearest-neighbor search trades recall for latency and memory. Measure approximation recall against exact retrieval on a sample, and distinguish it from relevance recall against labeled useful items.

As an illustrative storage estimate, one million 256-dimensional float32 vectors require about 1.024 GB for the raw values alone. Index structures, IDs, metadata, replicas, and runtime overhead add to that total.

Store the encoder version with the index. Switching the query encoder without rebuilding compatible item vectors can break retrieval. Prefer a staged index build, quality validation, and atomic traffic switch with rollback.

04. Explain the limitations

“Do similar vectors mean the answer is correct?”

No. Similarity retrieves candidates; it does not establish truth, authorization, availability, or compatibility. Those checks belong elsewhere in the system.

“Why not use embeddings for every query?”

Exact identifiers and rare terms can favor lexical matching. A hybrid retrieval design can preserve those strengths while adding semantic coverage.

Self-review

Explain the training objective, similarity measure, index approximation, and versioning strategy. “Convert text to vectors” is only the start of the answer.

Sources & further reading

Google Developers: embeddings. Vector and memory calculations here are illustrative.

Apply the idea

Design a document question-answering system ↗

Use retrieval while preserving permissions and source evidence.

Continue your preparation

Choose a connected learning path or browse more ML fundamentals questions. Read our editorial method and attribution policy.