yoklainterview sim

AI Engineer Rag Embeddings Similarity Interview Questions

75 verified AI Engineer Rag Embeddings Similarity interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

Rag Embeddings SimilarityDifficulty 2
You compute the cosine similarity between the vectors a=[1,0,1] and b=[1,1,0] using cos(a,b) = dot(a,b) / (||a|| * ||b||). dot(a,b) = 1, ||a|| = sqrt(2), ||b|| = sqrt(2). What is cos(a,b)?
  • a0.0
  • b0.5
  • c0.707
  • d1.0
Explanation:cos(a,b) = 1 / (sqrt(2) * sqrt(2)) = 1 / 2 = 0.5. The dot product counts the shared dimension (index 0, where both are 1), and dividing by the product of magnitudes normalizes for vector length.
Rag Embeddings SimilarityDifficulty 2
A vector database stores document vectors as the rows of a matrix D, all L2-normalized, and normalizes the query q to unit length as well. To score every document at once it computes the matrix-vector product D @ q. With rows [1,0], [0.6,0.8], [0,1] and q=[1,0], the result is [1.0, 0.6, 0.0]. What does each entry of D @ q represent?
  • aThe euclidean distance from the query to each document
  • bThe raw word-overlap count between query and each document
  • cThe cosine similarity of the query to each document, all at once
  • dThe number of nonzero dimensions each document shares with the query
Explanation:Because every row of D and the query q are unit-length, each dot product row·q already equals the cosine similarity. Stacking those dot products as the single product D @ q therefore yields the full vector of cosine scores in one operation — the standard way a vector index scores a whole batch of candidates efficiently.
Rag Embeddings SimilarityDifficulty 3
Vectors a=[1,2,2] and b=[2,2,1] both have magnitude 3. You L2-normalize each: a_n = [1/3, 2/3, 2/3], b_n = [2/3, 2/3, 1/3]. What is dot(a_n, b_n), rounded to 3 decimals?
  • a0.889
  • b0.750
  • c0.667
  • d1.000
Explanation:dot(a_n, b_n) = (1/3)(2/3) + (2/3)(2/3) + (2/3)(1/3) = 2/9 + 4/9 + 2/9 = 8/9 ≈ 0.889. Since both a and b already had magnitude 3, this equals cos(a,b) computed directly on the raw vectors too — normalizing first doesn't change the cosine value, only makes dot product usable in its place.
Rag Embeddings SimilarityDifficulty 1
A vector v = [3, 4] has magnitude ||v|| = sqrt(3^2 + 4^2) = 5. What is the L2-normalized vector v / ||v||?
  • a[3, 4]
  • b[1.5, 2.0]
  • c[0.5, 0.5]
  • d[0.6, 0.8]
Explanation:v / ||v|| = [3/5, 4/5] = [0.6, 0.8]. Each component is divided by the magnitude, so the resulting vector has length exactly 1 while pointing in the same direction as the original.
Rag Embeddings SimilarityDifficulty 2
A junior engineer ranks documents by raw dot product (no normalization). For query q=[1,0]: dot(q, d1=[2,0]) = 2, and dot(q, d2=[10,0]) = 10, so d2 is ranked first. But cos(q,d1) = 1.0 and cos(q,d2) = 1.0 — both are perfectly aligned with the query direction. What is the most accurate description of what went wrong?
  • aNothing went wrong; d2 genuinely has higher semantic similarity to the query
  • bBoth point the same direction, so cosine rates them equal; dot only favored d2 due to magnitude
  • cThe dot product formula is mathematically incorrect and should never be used in retrieval
  • dd2 must contain more words than d1, which is why its vector magnitude is larger
Explanation:Dot product is sensitive to vector magnitude, not just direction — a longer vector inflates the score even with identical direction. Cosine divides out the magnitudes, so it correctly reports both documents as equally aligned with the query (cos=1.0 for each). Ranking by raw dot product can silently favor documents whose embeddings happen to have larger norms, unrelated to actual semantic relevance.
Rag Embeddings SimilarityDifficulty 1
A retrieval system converts cosine similarity into a 'cosine distance' using distance = 1 - similarity. If cos(query, doc) = 0.8, what is the cosine distance?
  • a0.2
  • b0.8
  • c1.8
  • d-0.2
Explanation:distance = 1 - 0.8 = 0.2. This conversion is common because many nearest-neighbor libraries are built around minimizing a distance metric; a lower cosine distance means higher similarity, letting the same 'find smallest distance' search logic work for both similarity- and distance-based indexes.

Test yourself against the 2025-question AI Engineer bank.

Start interview