Skip to content
ML Academy

Neural networks, deep learning, NLP · insight-0462

Score embeddings with the similarity function the model was trained for

Evidence type
documented fact
Difficulty
easy
Roles
Applied AI, ML engineer
Industries
aviation

Summary: situation, action, reason, boundary

  1. Situation

    You build semantic search over fare-rule documents and pick cosine similarity by habit for an embedding model you have not read about.

  2. Action

    Read the model card for its intended score function. Use dot product for dot-tuned models; for models that output normalized vectors, cosine and dot product are equivalent, so normalize once and use the faster dot product.

  3. Reason

    Sentence Transformers documents some models as tuned for dot-product similarity and others as producing length-1 vectors usable with dot product, cosine or Euclidean distance.

  4. Boundary

    Semantic search, deduplication, clustering and retrieval-augmented generation.

Symptom or risk

Models trained for dot-product scoring encode useful information in vector length; cosine discards it and ranking quality can drop without any error.

Exceptions

If no guidance exists, compare both functions on labelled queries.

Trade-offs

Dot-product scores reward vector length, so check whether length tracks something unwanted, such as document length, in your data.

Pitfalls

Changing the index's distance metric without re-evaluating retrieval quality.

Lessons and concepts

Claims and their sources