liveBook · Manning

Euclidean distance

As explained in MongoDB 8.0 in Action, Third Edition

Euclidean distance is the straight-line distance between two points or vectors in Euclidean space.

Euclidean distance measures the straight-line distance between two points in vector space. In vector databases, it helps rank stored embeddings by how close they are to a query embedding, supporting semantically similar results. section 12.1.2 section 12.2.3

Use Euclidean distance when spatial separation between vectors is meaningful:

  • Apply it to image-recognition and clustering tasks, where the distance between points carries practical significance. section 12.2.3
  • Compare it with cosine similarity and dot product when choosing a vector-search similarity metric. section 12.2.3
  • Use it as the distance metric guiding nearest-neighbor navigation in HNSW indexes. section 12.2

Embedding search workflow

An embedding model converts stored content and a user query into vectors. The vector database compares the query vector with stored vectors using a similarity measure such as Euclidean distance, then returns the closest results. section 12.1.2

Figure 12.2 Vector database operations. Data is processed by an embedding model, transforming it into vector embeddings such as [1.45, ..., 1.01, 0.89, 0.06]. These embeddings are stored in a vector database. Queries from the application are also transformed into embeddings before the database is searched. The most relevant results based on these query embeddings are then retrieved and returned as query results. (Image © MongoDB 2024 CC BY-NC-SA 3.0)
A diagram of embedding model

Description automatically generated

Trace how source data becomes embeddings, enters a vector database, and produces retrieved results for an embedded query. section 12.1.2

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Defines straight-line distance and connects it to HNSW navigation, but does not present a calculation formula.
Examples
Uses image recognition, clustering, embedding retrieval, and nearest-neighbor graph navigation as applications.
What it assumes
Assumes familiarity with vectors and embeddings while relating them to vector-database similarity search.
What you can do after
Evaluate similarity metrics for vector search and understand how distance guides approximate or exact nearest-neighbor retrieval.
How it connects
Connects Euclidean distance with embeddings, vector databases, cosine similarity, dot product, HNSW, and exact nearest-neighbor search.

Also explained in

Compare how 8 books explain Euclidean distance →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.