Cosine Similarity
Also known as: Cosine distance
Compare two vectors by the cosine of their angle; the default similarity metric for embedding search.
A measure of similarity between two vectors equal to the cosine of the angle between them: dot product divided by the product of magnitudes. Normalized to [-1, 1]; the default distance metric for embedding retrieval.
In practice
Underlies almost all retrieval ranking. Interviews probe when dot product is better (already-normalized embeddings) and why Euclidean is rarer.
Related topics
Questions that mention this term
- Match each contrastive loss to its defining mechanism
- What does the dot product q . k actually measure inside an attention layer?
- Match each similarity metric to its formal definition
- What happens when you…
- Explain how the InfoNCE loss shapes embedding geometry during training
- Explain BERTScore's mechanism, its improvement over BLEU, and the specific failure mode that limits its use for factual LLM eval
Related terms
Embedding Model
The model that produces embeddings, typically a smaller encoder-only transformer.
Embeddings
Dense numeric vectors that capture meaning; close vectors = similar text.
HNSW (Hierarchical Navigable Small World)
A graph-based ANN index with log-time approximate search, excellent recall/latency trade-off.
Hybrid Search
Combine BM25 (keywords) + dense embeddings (meaning); better recall than either alone.
Retrieval-Augmented Generation (RAG)
Fetch relevant docs at inference time and stuff them into the prompt so the model can answer from real data.
Retriever
The fast first-stage search in RAG: bi-encoder or BM25 fetching a shortlist for the reranker or LLM.