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
Related terms
Retrieval-Augmented Generation (RAG)
Fetch relevant docs at inference time and stuff them into the prompt so the model can answer from real data.
Embeddings
Dense numeric vectors that capture meaning; close vectors = similar text.
Vector Database
A database tuned for fast approximate nearest-neighbor search over millions of high-dimensional vectors.
HNSW (Hierarchical Navigable Small World)
A graph-based ANN index with log-time approximate search, excellent recall/latency trade-off.
Embedding Model
The model that produces embeddings, typically a smaller encoder-only transformer.
Hybrid Search
Combine BM25 (keywords) + dense embeddings (meaning); better recall than either alone.