When does cosine similarity mislead you? Discuss embedding-space pathologies relevant to retrieval systems.
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Cosine similarity is only as meaningful as the geometry of the space it's computed in, and several pathologies corrupt that geometry:
Anisotropy. Raw hidden states from language models occupy a narrow cone rather than spreading over the hypersphere - average pairwise cosine between random sentences can be very high (this is why early "BERT embeddings via mean pooling" underperformed plain averaged GloVe vectors on similarity tasks, as the Sentence-BERT paper showed). Consequence: absolute cosine values are uninterpretable; a 0.8 might be noise floor. Contrastive fine-tuning (the SimCSE lineage, and all modern embedders) explicitly spreads the space - the InfoNCE loss has a uniformity term pushing points apart and an alignment term pulling positives together. Practical rule: never ship nearest-neighbour search on base-LLM activations; use a contrastively trained embedder.
Full worked answer
Cosine similarity is only as meaningful as the geometry of the space it's computed in, and several pathologies corrupt that geometry:
Anisotropy. Raw hidden states from language models occupy a narrow cone rather than spreading over the hypersphere - average pairwise cosine between random sentences can be very high (this is why early "BERT embeddings via mean pooling" underperformed plain averaged GloVe vectors on similarity tasks, as the Sentence-BERT paper showed). Consequence: absolute cosine values are uninterpretable; a 0.8 might be noise floor. Contrastive fine-tuning (the SimCSE lineage, and all modern embedders) explicitly spreads the space - the InfoNCE loss has a uniformity term pushing points apart and an alignment term pulling positives together. Practical rule: never ship nearest-neighbour search on base-LLM activations; use a contrastively trained embedder.
Hubness. In high dimensions, some points become "hubs" that appear in the k-NN lists of a disproportionate share of queries - an artefact of concentration of distances. Symptom: the same handful of chunks retrieved for everything. Mitigations: better embedders, score normalization per candidate, reranking with a cross-encoder.
Training/serving metric mismatch. A model trained with cosine (normalized) but indexed with raw inner product lets vector norms - which the training objective never disciplined - dominate rankings. Normalize at index time and query time, and configure the ANN index metric (IP vs L2 vs cosine) to match.
Isotropic-but-meaningless directions. Cosine weights all dimensions equally; if a few dimensions carry high-variance nuisance information (length, language, formatting), similarity reflects those. Whitening transforms and task-specific fine-tuning of the embedder partially address this.
Task mismatch - the subtlest one for RAG: "similar" is task-relative. Question-to-answer relevance is asymmetric; a question is often most cosine-similar to other questions, not to passages answering it. Hence instruction-prefixed asymmetric embedders (separate query/passage prompts, E5/BGE-style) and cross-encoder rerankers on the top-k.
What a good answer covers
- Raw hidden states from language models occupy a narrow cone rather than spreading over the hypersphere -…
- Consequence: absolute cosine values are uninterpretable; a 0.8 might be noise floor
- Contrastive fine-tuning (the SimCSE lineage, and all modern embedders) explicitly spreads the space -…
- Practical rule: never ship nearest-neighbour search on base-LLM activations; use a contrastively trained…
- In high dimensions, some points become "hubs" that appear in the k-NN lists of a disproportionate share…
Key terms: Anisotropy · uniformity · alignment · Hubness · Training/serving metric mismatch · Isotropic-but-meaningless directions · Task mismatch
In the glossary: Cosine similarity · InfoNCE · Alignment · Reranking · Cross-encoder · ANN
Interviewer follow-ups to expect
How would you detect hubness in a production RAG system?
Hubness. In high dimensions, some points become "hubs" that appear in the k-NN lists of a disproportionate share of queries - an artefact of concentration of distances. Symptom: the same handful of chunks retrieved for everything. Mitigations: better embedders, score normalization per candidate, reranking with a cross-encoder.
Why does a cross-encoder beat bi-encoder cosine, and why not use it for first-stage retrieval?
What do alignment and uniformity mean in the Wang & Isola framing of contrastive learning?
Anisotropy. Raw hidden states from language models occupy a narrow cone rather than spreading over the hypersphere - average pairwise cosine between random sentences can be very high (this is why early "BERT embeddings via mean pooling" underperformed plain averaged GloVe vectors on similarity tasks, as the Sentence-BERT paper showed). Consequence: absolute cosine values are uninterpretable; a 0.8 might be noise floor. Contrastive fine-tuning (the SimCSE lineage, and all modern embedders) explicitly spreads the space - the InfoNCE loss has a uniformity term pushing points apart and an alignment term pulling positives together. Practical rule: never ship nearest-neighbour search on base-LLM activations; use a contrastively trained embedder.
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep