Vector DB & ANN · core
Vector Similarity
Cosine, dot product, and L2 distance — how to score vector closeness.
Mental model
Cosine measures angle (direction), dot product measures angle and magnitude, L2 measures straight-line distance. On normalized vectors cosine and dot product rank identically, and L2 becomes a monotonic function of them.
How to study Vector Similarity
Begin by restating the mental model in your own words, then connect it to a concrete system you have built or operated. Name the mechanism, the constraint it addresses, and the trade-off it introduces. Use Pinecone — Vector similarity explained to check details, but close the source before writing your explanation. Retrieval is the learning step; rereading is only preparation.
Next, compare Vector Similarity with Top-k Vector Search, Brute-Force Vector DB. Ask what changes in correctness, latency, resource use, operability, and failure recovery. Complete Implement similarity metrics and preserve the command, input, output, and one failed attempt as evidence. Finish by explaining the idea without jargon to someone who has not studied the track.
Proof of understanding
- Explain the mechanism from first principles and identify the state it reads or changes.
- Give one situation where the concept is the right choice and one where it is not.
- Predict a realistic failure mode before running the drill, then compare the prediction with evidence.
- Connect the result to a roadmap or build artifact instead of treating the concept as isolated trivia.
Where it matters
Every vector index exposes a metric choice; it must match the embedding model.
Common mistakes
- Mixing distance metrics between indexing and querying
- Using dot product on un-normalized vectors and being surprised by magnitude bias
- Assuming the metric does not matter for the chosen index
Learn from primary sources
- Pinecone — Vector similarity explained (article)
Practice and explain it back
Implement similarity metrics
Implement cosine similarity, dot product, and L2 distance. Show that on normalized vectors, cosine and dot product produce the same ranking.
Expected evidence: Three functions; a demonstration that normalized cosine == dot ranking.
Open the interactive drill →Review prompts
- When do cosine similarity and dot product give the same ranking?
Build evidence
Hybrid search v0 in HighSignal
Combine BM25 and vector retrieval with reciprocal rank fusion.
- Run BM25 and vector retrieval over the same corpus
- Fuse results with reciprocal rank fusion
- Beat both single retrievers on the search eval set
Brute-force vector index
An exact nearest-neighbour index — the recall=1.0 baseline.
- Insert and search vectors with a chosen metric
- Return correct top-k via a k-sized heap
- Benchmark query latency vs vector count