LLM fundamentals · Concept
Embeddings and similarity search
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voiceThe interviewer asks
What is an embedding? How does a vector search find 'refund not received' when the document says 'money not credited back to your account'?
Then
Follow-ups the interviewer asks next
- Cosine similarity, dot product or Euclidean distance: when does the choice matter?
- Can you compare an embedding from one model with an embedding from another?
- What is approximate nearest neighbour search, and what do you give up for the speed?
- Where do embeddings do badly?
- What changes when vectors have 3,072 dimensions instead of 768?
The answer
What a strong answer covers
- An embedding model turns a text (or an image) into a fixed-length list of numbers, so that texts with similar meaning land close together. The query and the documents are embedded with the same model, and search returns the nearest vectors.
- Cosine similarity compares direction. For normalised vectors, cosine and dot product give the same ranking. Use the metric the model was trained for (its model card says).
- Vectors from different models, or different versions of one model, live in different spaces. Never mix them in one index; changing the model means embedding everything again.
- Exact search compares the query with every vector. ANN indexes (HNSW, IVF) are much faster but can miss some true neighbours (recall below 100%), traded off with settings such as
ef_searchorprobes. - Weak spots: exact identifiers (policy numbers, error codes, SKUs), negation ("not covered"), numbers, very short queries, and languages or domains the model wasn't trained on. That's why hybrid search with keywords exists.
- More dimensions mean more storage and memory and slower search, sometimes better quality. Many models allow shorter vectors (Matryoshka-style) or half-precision storage; measure recall before and after.
The red pen
Common traps
Avoid:"the vector database understands meaning" (the embedding model does that); mixing two models' vectors; reading cosine 0.8 as "80% relevant".
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voicePractise questions like this out loud
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.