AI Glossary / Causal inference and experimentation / Beginner

Similarity measure

Definition

A similarity measure is a rule that assigns a numerical score to how alike two objects are in a chosen representation. It can compare feature vectors, sets, documents, images or other data. Its meaning depends on the features and comparison rule, not only on the resulting number.

What it means

A search engine may compare a query with document embeddings, while a product system may compare item attributes. Both calculate similarity, but they can mean different things by “alike”: shared vocabulary, related meaning, matching specifications or similar user behavior.

Similarity scores usually increase with resemblance, whereas distance or dissimilarity values usually decrease. Some resources use “similarity measure” broadly to include either direction, so always check the convention.

The score is not automatically a probability of relevance or proof that two items are interchangeable. Two documents may discuss the same topic while making opposite claims, and two visually similar parts may have incompatible dimensions.

How it works

Choose a representation that preserves the distinctions needed for the task. Then select a rule compatible with that representation. Cosine similarity compares vector directions, dot product combines direction and magnitude, and Euclidean distance measures separation between vector endpoints. Set-based measures such as Jaccard compare overlap relative to the union.

Preprocessing changes the comparison. Rescaling one numerical feature can change Euclidean neighbors; normalizing vectors removes magnitude information from a dot-product comparison. Missing values and zero vectors require defined handling.

A retrieval or clustering system then uses the resulting scores to rank candidates, connect neighbors or assign groups. Validate that those choices match the intended notion of relevance. The mathematically convenient measure is not necessarily the operationally useful one.

Three practical examples

  • A document-search prototype ranks passages by embedding similarity, then checks whether they actually answer the query.
  • A duplicate-detection tool compares sets of identifying attributes while preserving differences that distinguish separate products.
  • A clustering experiment groups usage profiles, choosing whether total activity or the relative pattern of activity should dominate resemblance.

Think of it this way

Think of choosing a ruler for comparison. A ruler measuring physical length answers a different question from one measuring color difference. Neither can declare two objects universally similar.

The analogy highlights measurement choice. In machine learning, representations may be learned and high-dimensional, so their behavior can be harder to inspect than a physical ruler. The team still needs examples showing what the resulting comparison treats as close or far apart.

Worked example

The same vectors can produce different rankings

Consider an invented query vector q = (1,0) and two candidate vectors A = (2,0) and B = (1,1).

Their dot products with q are 2 and 1, so dot product ranks A higher. Cosine similarity gives A a value of 1 and B approximately 0.707, again favoring A because it points exactly in the query direction.

Euclidean distances tell another part of the story: both candidates are distance 1 from q, so they tie. Candidate C = (0.9,0.1) is only about 0.141 away and would be preferred by Euclidean distance, although its cosine is slightly below A's perfect directional match.

These calculations are not conflicting answers to one universal question. They encode different priorities concerning direction and magnitude. Which ranking is useful depends on what the vector components represent and what the retrieval task needs.

Illustrative case study

Fictional Alder Parts builds a recommendation tool from product descriptions. It returns a highly similar item when a customer searches for a replacement component, but the suggested part has the wrong connector size.

The team realizes that broad semantic resemblance is insufficient for compatibility. It keeps similarity ranking for discovering candidates and adds explicit checks for required specifications. Evaluation examples now include near-matches that must be rejected.

The project also records the embedding version and preprocessing rules, because changing the representation changes the meaning of previous scores. The lesson is that similarity can support a decision while remaining only one piece of the evidence required to make it.

Common misconceptions and mistakes

Do not read a cosine score of 0.9 as a 90% probability of correctness. Score scales are specific to the representation and method.

A similarity function is not necessarily a mathematical distance metric. A true metric has properties such as symmetry and the triangle inequality; arbitrary relevance scores may not. An algorithm that relies on metric properties needs a compatible input.

Normalization is a choice, not a universal improvement. Removing magnitude can help when only pattern matters, but it can discard useful information when vector length represents something meaningful. A threshold copied from another embedding model may also behave very differently.

Business use

Before selecting a measure, write down what a useful match must preserve and what differences can be ignored. Build evaluation pairs containing obvious matches, obvious mismatches and difficult near-matches.

Assess ranking quality or decision errors against the intended task, rather than comparing raw scores from incompatible systems. Record representation versions, scaling, missing-data treatment and thresholds. For large collections, distinguish the similarity rule from an approximate search method: the rule defines the target ranking, while the index may return only an approximation to it.

People also ask

Is cosine similarity always between zero and one?

No. For general nonzero real vectors it ranges from −1 to 1. Non-negative representations restrict it to a smaller range, and zero-vector handling depends on the implementation.

Are cosine and dot product identical?

They are equal for unit-normalized vectors. Otherwise dot product also depends on vector lengths.

Can two items be similar but unsuitable substitutes?

Yes. Similarity reflects the chosen features, while substitution may require additional factual or functional constraints.

Check your understanding

Two document embeddings have a high similarity score. Does that establish that both documents support the same conclusion?

Answer: No. They may share subject matter, wording or other represented features while disagreeing. The system must inspect the actual claims and supporting evidence if agreement is the question.

Related terms

  • Cosine similarity
  • Dot product
  • Euclidean distance
  • Embedding
  • Nearest neighbor
  • Metric Learning
  • Relevance
  • Jaccard similarity
  • feature scaling

Learn next

Learn vector length, direction and distance with small numerical examples. Then compare rankings under two measures on the same candidate set. Inspect difficult near-matches and decide whether the representation, measure or decision rules need to change to capture the task's requirements.

  • Vector length

More in Causal inference and experimentation

  • Sequential exchangeability - Sequential exchangeability is a causal assumption that, at each treatment decision, treatment is independent of the relevant future potential outcomes...
  • Side-by-side evaluation - Side-by-side evaluation compares two systems by judging their outputs for the same input.
  • Silhouette Coefficient - The Silhouette Coefficient measures how well an observation fits its assigned cluster compared with the nearest competing cluster.
  • Squared hinge loss - Squared hinge loss is a classification loss that squares the positive shortfall from a target margin.
  • Structural causal model - A structural causal model, or SCM, represents how variables are generated by causal mechanisms.
  • Super learner - Super learner is an ensemble-learning approach that uses cross-validation to select or combine predictions from a library of candidate algorithms according...

Sources

Sources: Google Machine Learning Glossary, similarity measure: https://developers.google.com/machine-learning/glossary#similarity-measure Google, Measuring similarity from embeddings: https://developers.google.com/machine-learning/clustering/dnn-clustering/supervised-similarity Scikit-learn, Pairwise metrics, affinities and kernels: https://scikit-learn.org/stable/modules/metrics.html SciPy, Jaccard dissimilarity: https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.jaccard.html

Previous: Similarity learning Next: Similarity networks

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer