Next cohort starts January 9.Apply ›

Similarity

Python Similarity Interview Questions

Similarity is putting a number on how close two things are. For text it is almost always cosine similarity between two embedding vectors: the dot product divided by both of their lengths, which leaves only the angle between them. Retrieval is this one calculation repeated across a corpus and then sorted.

What similarity questions ask you to do

Across the questions here, these are the shapes that come up:

  • Rank documents against a query by cosine similarity
  • Return the closest few rather than everything above a threshold
  • Measure the overlap between two sets of words
  • Break ties so the same input always gives the same order
  • Handle a vector of all zeros without dividing by zero

Common mistakes with similarity

Ranking by the dot product alone, which rewards long vectors rather than close ones, so the document with the most text wins whatever it says. Dividing by both lengths is what removes the magnitude. That division also needs a guard: a vector of all zeros has no direction and no length to divide by.

Questions to practice

Questions last reviewed 19 October 2026.

Roles this comes up in

Companies these come from

Other topics