Similarity measures
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
pick the distance measure that matches the embedding model.
Planned topics
- Cosine distance: compares direction, ignores length. The common default for text embeddings.
- Inner product: fast; ranks like cosine when vectors are normalized to length 1.
- Euclidean (L2): straight-line distance; use it when the model was trained for it.
- Rule: use the measure the model documents. A wrong measure still returns results, just worse ones.
- The index must use the same measure as the query.
Draft outline details
Demonstration
| Measure | pgvector operator | Use when |
|---|---|---|
| Cosine distance | <=> | model recommends cosine |
| Inner product (negated) | <#> | vectors normalized |
| Euclidean | <-> | model trained for L2 |
Check your understanding
What happens if you use a measure the model was not trained for?
Show answer
Queries run, but ranking quality drops silently.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.