Similarity metric
A similarity metric is a function that quantifies how alike two objects or representations are according to specified properties.
Grokking Machine Learning
A numerical measure of the closeness between two data points.
- How it is used
- Defines similarity as a function used in the RBF kernel method to classify nonlinear datasets with SVMs.
- How deep it goes
- Defines closeness through distance, gives an exponential formula, and defers the full theory of kernels and feature maps.
- Examples
- Uses one- and two-dimensional labeled datasets, distance-based similarity values, and added similarity columns.
- What you can do after
- Apply similarity values as added features to classify nonlinear data with an SVM.
Read how Grokking Machine Learning explains similarity metric →
AI-Powered Search
A similarity metric is a numerical measure that quantifies how closely two representations or objects correspond.
- How it is used
- Ranks search candidates by measuring correspondence between queries, documents, phrases, or their vector representations.
- How deep it goes
- Explains vector construction, embedding comparison, cross-encoder scoring, reranking, and quadratic all-pairs cost without deriving metric mathematics.
- Examples
- Uses apple-juice document vectors, weather and vehicle phrases, and mountain-hike cross-encoder reranking.
- What you can do after
- Apply it via sentence-transformers to compare embeddings, sort similarity scores, and rerank search results.
Math and Architectures of Deep Learning
A measure of how alike two represented items are, especially when computed from their vector representations.
- How it is used
- Estimates similarity between vector representations for tasks such as document retrieval and ranked search.
- How deep it goes
- Explains dot-product geometry, angle dependence, document-vector construction, sparse storage, and worked comparisons.
- Examples
- Uses document descriptors, query ranking, word-frequency vectors, and d5–d6 versus d3–d4 dot-product comparisons.
- What you can do after
- Evaluate document relatedness and rank retrieval results by computing dot products between their feature vectors.
Read how Math and Architectures of Deep Learning explains similarity metric →
MongoDB 8.0 in Action, Third Edition
A similarity score is a numeric measure of how closely a query vector matches a document vector embedding.
- How it is used
- Configures vector indexes so semantic searches can rank documents by closeness to a query embedding.
- How deep it goes
- Defines cosine, Euclidean, and dot product behavior with application guidance, but does not develop mathematical derivations.
- Examples
- Uses movie-plot embeddings with cosine scoring and a local knnVector index using Euclidean similarity.
- What you can do after
- Apply it via Atlas CLI and vector search pipelines by selecting a metric, defining an index, and inspecting returned similarity scores.
Read how MongoDB 8.0 in Action, Third Edition explains similarity metric →
Build an Advanced RAG Application (From Scratch)
A similarity score is a numerical value indicating the degree of relatedness between two items or representations.
- How it is used
- Ranks semantically related search items when exact keyword matching is insufficient.
- How deep it goes
- Explains vector proximity, contrasts cosine and Euclidean distance, and implements cosine top-k retrieval.
- Examples
- Uses dog-related terms, country-capital vectors, and hotel reviews to illustrate semantic proximity and ranked retrieval.
- What you can do after
- Apply it via NumPy to encode a query, compare embeddings, and retrieve top-k results.
Read how Build an Advanced RAG Application (From Scratch) explains similarity metric →
Get Programming: Learn to code with Python
Similarity is the degree to which two texts or other objects share comparable characteristics.
- How it is used
- Measures similarity between text files for document comparison, version checking, or essay-submission review.
- How deep it goes
- Explains a word-frequency formula, sanity checks, and modular implementation, while deferring more advanced language modeling to bigrams.
- Examples
- Uses identical files, an empty file, Shakespeare’s sonnets, and a three-word document modification as tests.
- What you can do after
- Apply via Python functions to read two files, count their words, and calculate a normalized similarity score.
Read how Get Programming: Learn to code with Python explains similarity metric →
Natural Language Processing in Action, Second Edition
Similarity is a numerical or qualitative measure of how closely two patterns or signals resemble each other.
- How it is used
- Ranks semantic-search results and checks whether compressed vector spaces preserve meaningful document relationships.
- How deep it goes
- Defines multiple distance families and applies cosine similarity, while noting that LSA preserves large but not always fine-grained distances.
- Examples
- Uses word-vector comparisons, semantic-search rankings, LSA-versus-TF-IDF checks, and scikit-learn’s catalog of pairwise metrics.
- What you can do after
- Apply it via gensim or vector-search tooling to compare terms, evaluate representations, and rank documents by relevance.
Read how Natural Language Processing in Action, Second Edition explains similarity metric →
Data Without Labels
A similarity measure is a quantitative function that assesses how alike two data points, objects, or representations are.
- How it is used
- Measures likeness for clustering assignments and for preserving neighborhood relationships during dimensionality reduction.
- How deep it goes
- Defines distance-based similarity and several formulas, but defers centroid, norm, and probability-proof details.
- Examples
- Uses centroids, two-dimensional point coordinates, four distance paths, and Gaussian neighborhoods in t-SNE.
- What you can do after
- Evaluate/understand how distance choices alter similarity scores and clustering or embedding behavior.
AI Recommender Systems
Similarity is a quantitative or qualitative measure of how alike two items, user histories, or related representations are according to selected features or behavior.
- How it is used
- Uses similarity to retrieve related items, personalize candidates, and support more-like-this recommendations.
- How deep it goes
- Progresses from metadata comparisons to hybrid ranking and embedding search, while deferring richer learned representations and production deduplication details.
- Examples
- Demonstrates genre overlap, Toy Story hybrid rankings, and cosine-nearest movies such as Toy Story 2 and Toy Story 3.
- What you can do after
- Apply via scikit-learn cosine similarity and a multi-stage recommender pipeline to retrieve, filter, and rank related items.
Read how AI Recommender Systems explains similarity metric →
Machine Learning System Design
Vector similarity is a measure of how closely two numerical vectors correspond in direction, distance, or another defined geometric relationship.
- How it is used
- Drives photo search by matching user queries against searchable-item vectors.
- How deep it goes
- Separates vector generation and index querying, then specifies serving constraints without detailing the similarity calculation.
- Examples
- Uses daily index updates, on-demand reindexing, and peak query loads of roughly 100 requests per second.
- What you can do after
- Operate vector search by separating index updates from real-time queries and sizing each path for its workload.
Read how Machine Learning System Design explains similarity metric →
Designing AI Systems
A similarity score is a numerical value representing how closely two items or vector representations match, with larger values indicating greater similarity.
- How it is used
- Ranks vector-search results and filters weak matches before supplying retrieved chunks to a model.
- How deep it goes
- Defines score semantics and shows cosine-distance conversion, while leaving backend indexing details behind the interface.
- Examples
- Uses legal-department filtering, support-bot top-three retrieval, research-tool top-ten retrieval, and pgvector cosine scoring.
- What you can do after
- Apply it via VectorStore or pgvector search by combining ranking, metadata filters, top-k limits, and score thresholds.
Build AI Drug Discovery Pipelines
A similarity coefficient is a numerical measure that quantifies the resemblance between two sets or binary representations.
- How it is used
- Ranks screening-library molecules against active reference compounds for experimental validation.
- How deep it goes
- Defines feature-space similarity and gives Tanimoto and Dice formulas, but defers broader representation and search-strategy choices.
- Examples
- Uses an apple–orange feature-space analogy, binary molecular fingerprints, coefficient calculations, and antimalarial compound-library searching.
- What you can do after
- Evaluate molecular resemblance with Tanimoto or Dice coefficients and interpret its limits as a proxy for biological function.
Read how Build AI Drug Discovery Pipelines explains similarity metric →
Transformers in Action
A similarity score is a numerical value indicating how closely two represented items align according to a specified similarity measure.
- How it is used
- Supports semantic search, retrieval-augmented generation, chatbot context resolution, and answer-quality estimation.
- How deep it goes
- Explains cosine scores, pairwise tensor shape, and directional interpretation, but defers the metric’s mathematical derivation.
- Examples
- Uses transformer-generated sentence embeddings, query-document pairs, cosine-similarity matrices, and a printed score tensor.
- What you can do after
- Apply cosine similarity through SentenceTransformer to rank documents against encoded queries.
Read how Transformers in Action explains similarity metric →
Bayesian Optimization in Action
A similarity metric is a numerical rule for quantifying how similar two data points are.
- How it is used
- Uses numerical similarity to define covariance and guide Gaussian-process predictions.
- How deep it goes
- Defines similarity through kernels, explains RBF behavior, and stops short of developing neural-network representations.
- Examples
- Uses house prices, door colors, living area, MNIST image tensors, heat maps, and an RBF length-scale implementation.
- What you can do after
- Evaluate whether a kernel's similarity notion matches the predictive features and structure of the data.
Read how Bayesian Optimization in Action explains similarity metric →
Also covered in
- Evolutionary Deep Learning: Genetic algorithms and neural networks
- Generative AI in Action
- Graph Neural Networks in Action
- Machine Learning Algorithms in Depth
- Machines that ThinkIn early access (MEAP)
- The Well-Grounded Data Analyst
- Learn Go with Pocket-Sized Projects
- Geometry for Programmers
- Grokking Algorithms, Second Edition
What to know first
- embeddingAn embedding is a numerical vector representation of an item in a feature space, encoding selected properties or relationships for computational tasks such as comparison or retrieval.
- language modelA language model is a computational model that represents patterns in linguistic sequences to assign probabilities, predict, generate, or evaluate language.
- similarity searchSimilarity search is a retrieval technique that finds or ranks items by their similarity to a query, often by comparing feature or vector representations under a similarity or distance measure.
- vector spaceA vector space is a set equipped with vector addition and scalar multiplication over a field that satisfy the vector-space axioms.
Related concepts
- kernel functionincludes · A kernel function is a mathematical function that measures similarity between inputs, often by representing an inner product in an implicit feature space.
- semantic similarity metricincludes · A metric that evaluates similarity between texts based on meaning and context rather than exact word overlap.
- similarity searchused by · Similarity search is a retrieval technique that finds or ranks items by their similarity to a query, often by comparing feature or vector representations under a similarity or distance measure.
- recommender systemused by · A recommender system is a computational system that predicts, selects, or ranks items, content, or actions for users based on available information.
- embeddinguses · An embedding is a numerical vector representation of an item in a feature space, encoding selected properties or relationships for computational tasks such as comparison or retrieval.
- distancemeasured by · A distance function assigns a numerical measure of separation or dissimilarity to pairs of points or objects in a defined space.
Questions about similarity metric
What is similarity metric?
A similarity metric is a function that quantifies how alike two objects or representations are according to specified properties.
Which Manning books explain similarity metric?
Grokking Machine Learning, AI-Powered Search, Math and Architectures of Deep Learning, MongoDB 8.0 in Action, Third Edition, Build an Advanced RAG Application (From Scratch), Get Programming: Learn to code with Python, Natural Language Processing in Action, Second Edition, Data Without Labels and 6 more.
What should I know before learning similarity metric?
Manning books that teach similarity metric usually introduce embedding, language model, similarity search and vector space first.
What kinds of similarity metric are there?
Kinds of similarity metric include kernel function and semantic similarity metric.
What is similarity metric also called?
Similarity metric is also called similarity measure.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.













