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
- Filtering7
- Logical operators4
- Calculations11
- Conditional logic12
- NULL handling9
- Dates16
- Joins15
- Aggregations14
- Subqueries5
- Window functions32
- Reshaping15
- Arrays6
- Strings11
- Hashing8
- Two pointers4
- Sliding window1
- Binary search4
- Sorting1
- Math3
- Lists5
- Tuples3
- Dictionaries3
- Ranking16
- Running totals10
- Deduplication2
- Chunking1
- Token budget2
- Parsing4
- Backoff3
- Agent loop1
- Cost1