What Is Vector Similarity? Cosine, Dot Product, and L2 Distance

    Vector similarity is the mathematical measure that determines how closely two pieces of content are related in an AI retrieval system, with cosine similarity, dot product, and L2 distance being the three dominant approaches. Each has different strengths depending on whether the retrieval system normalises its vectors, making the choice of similarity metric a critical architectural decision in any AI search pipeline.

    Tharindu Gunawardana
    Tharindu Gunawardana
    April 10, 2026
    8 min read
    AI SEO
    What Is Vector Similarity? Cosine, Dot Product, and L2 Distance

    What Is Vector Similarity?

    Vector similarity is the numerical measure of how close or related two vectors are in high-dimensional space. In AI retrieval, every piece of text is converted into a vector by an embedding model, and retrieval means finding the vectors most similar to a query vector. The specific formula used to define "similar" is the similarity measure, and the choice of measure affects both the ranking of results and the architecture of the search index.

    Three measures dominate practical AI retrieval: cosine similarity, dot product, and L2 (Euclidean) distance. Each captures a different geometric property. Cosine measures angle, dot product measures aligned magnitude, and L2 measures straight-line distance. Understanding the differences helps in choosing the right measure for the retrieval task and understanding why embedding models specify a required measure.

    Three Vector Similarity MeasuresCosine SimilarityθMeasures the angle betweenvectors. Scale-invariant.Range: -1 to 1Dot Productlong vecshort vecMagnitude AND angle matter.Sensitive to vector length.Range: unboundedL2 (Euclidean) DistancedGeometric straight-linedistance in vector space.Range: 0 to infinityEach measure captures a different geometric property of the same vector space.

    How Vector Similarity Affects AI Search Retrieval

    The similarity measure used by an AI search system determines which content is retrieved and ranked. For SEO practitioners, the practical implications are consistent across all three measures.

    Example: Focused vs Mixed-Topic Content Cosine Scores

    Query: "how does cosine similarity measure semantic relatedness?"

    Mixed-topic chunk (low cosine similarity)

    "Cosine similarity measures angle between vectors. HNSW graphs enable fast ANN search. BM25 uses term frequency and inverse document frequency for ranking."

    Cosine similarity to query: ~0.52. The chunk vector is pulled in three semantic directions. Weak match against a focused query.

    Focused chunk (high cosine similarity)

    "Cosine similarity measures the angle between two embedding vectors. A score of 1.0 means the vectors point in the same direction, indicating maximum semantic relatedness. A score of 0 indicates no semantic relationship."

    Cosine similarity to query: ~0.91. The chunk vector points squarely at "cosine similarity" and "semantic relatedness". Retrieved and cited.

    • Semantic proximity, not keyword overlap: Vector similarity measures the directional relationship between meaning representations, not the presence of specific words. Two documents can be highly similar without sharing a single keyword, provided their vector embeddings point in the same direction.
    • Content coherence raises cosine similarity: A chunk of content that covers a single, well-defined topic produces a vector that points clearly in one semantic direction. Mixed-topic content produces diffuse vectors with low similarity to any specific query direction.
    • Chunking affects similarity scores: The similarity measure operates on individual chunks, not full pages. Semantic chunking ensures each chunk has a clear semantic centre, producing high-quality vectors.
    • Optimising for AI retrieval requires understanding the retrieval layer: Our AI SEO services focus on how content performs when embedded and compared using these similarity measures, not just on traditional ranking signals.

    Cosine Similarity

    Cosine similarity measures the angle between two vectors, ignoring their magnitude. Two vectors pointing in the same direction have a cosine similarity of 1, regardless of whether one is ten times longer than the other. Two orthogonal vectors have a cosine similarity of 0. Two vectors pointing in opposite directions score -1.

    The formula is the dot product of the two vectors divided by the product of their lengths. This normalisation step is what makes cosine invariant to magnitude. In text retrieval, a short sentence and a long paragraph discussing the same topic will have similar vectors, and the different lengths of those vectors should not penalise either. Cosine similarity handles this correctly; dot product does not.

    Cosine similarity is the default measure for most NLP retrieval tasks, sentence transformer models, and vector databases used in RAG pipelines. Models such as all-MiniLM-L6-v2, BGE, and E5 are trained with cosine as the target measure.

    Dot Product

    The dot product of two vectors is computed by multiplying corresponding dimensions and summing the results. It is sensitive to vector magnitude: a longer vector will produce a higher dot product score against a query than a geometrically similar but shorter vector. This makes dot product appropriate when magnitude encodes a meaningful signal.

    In recommendation systems, for example, a user vector might be scaled to reflect engagement level: an active user has a larger magnitude than an inactive user. Dot product retrieval naturally returns items likely to be relevant to highly active users with strong preference signals. In text retrieval without such magnitude semantics, dot product risks biasing retrieval toward high-norm documents.

    Dot product is the native measure for Maximum Inner Product Search (MIPS), which underpins many recommendation and personalisation systems. OpenAI's text-embedding-ada-002 model was designed for use with dot product on normalised vectors, which makes it equivalent to cosine similarity in practice. Matryoshka embedding models often prefer dot product because the nested dimension structure relies on inner product geometry.

    L2 (Euclidean) Distance

    L2 distance is the straight-line geometric distance between two points in high-dimensional space. A distance of 0 means the vectors are identical. As distance increases, the vectors are more different. Unlike cosine similarity, which produces a score (higher is better), L2 distance is a cost (lower is better). Most retrieval libraries handle this inversion transparently.

    L2 is the natural choice when the geometry of the embedding space corresponds to actual magnitude relationships. Image embeddings, audio embeddings, and many multi-modal models are trained with L2 as the objective. It is also the default distance for k-means clustering and is used in HNSW graph construction.

    For text embeddings specifically, L2 and cosine similarity give identical rankings when vectors are normalised to unit length. Many embedding models output normalised vectors precisely to make the choice irrelevant in practice. When vectors are not normalised, L2 and cosine produce different rankings.

    Normalisation and When Measures Agree

    Cosine vs Dot Product on Normalised VectorsWithout normalisationCosine: accounts for length, measures angle onlyDot product: longer vectors score higher regardlessDifferent results — use cosine for textWith L2 normalisation (unit vectors)Cosine similarity = dot productBoth measures are equivalent when allvectors have length 1Most modern embedding models output unit vectorsWhen vectors are L2-normalised, cosine and dot product give identical rankings. Many vector databases normalise automatically.

    When all vectors have unit length (L2 norm of 1), cosine similarity and dot product give identical rankings. This is because the normalisation in cosine similarity's formula is always 1 when both vectors have unit norm, leaving only the dot product. Most modern text embedding models output unit-norm vectors explicitly for this reason, so the choice between cosine and dot product is often irrelevant in practice.

    When vectors are unit-norm, L2 distance is also equivalent to cosine similarity up to a monotonic transformation: L2 distance = sqrt(2 - 2 * cosine_similarity). Since the transformation preserves ranking order, all three measures rank results identically for normalised text embeddings. The practical difference appears only when embedding models produce unnormalised outputs.

    Which Vector Similarity Measure to Use

    The correct similarity measure is specified by the embedding model's documentation. Using the wrong measure degrades retrieval quality significantly. The general rules are:

    When to Use Each Similarity MeasureCosine SimilarityNLP text retrievalSemantic search enginesSentence transformersRAG pipelinesLength normalised vectorsencode meaning, not scaleDot ProductRecommendation systemsRetrieval with MIPSMatryoshka embeddingsOpenAI ADA embeddingsWhen vector magnitudeencodes importanceL2 DistanceImage embeddingsHNSW graph constructionK-means clusteringAnomaly detectionWhen actual geometricdistance has meaningFor NLP retrieval, cosine similarity is the default. For image and multi-modal embeddings, L2 is often preferred.
    • Use cosine for text retrieval with sentence transformers, BGE, E5, and similar models. Also use cosine when vectors may have variable magnitudes that do not encode a meaningful signal.
    • Use dot product when the embedding model was trained with dot product loss, or when vectors are explicitly normalised to unit length. Also use dot product for MIPS-based recommendation retrieval.
    • Use L2 for image embeddings, multi-modal embeddings, and clustering tasks. Also use L2 when the vector database library defaults to it and vectors are normalised (the results will be equivalent to cosine).

    In practice, most vector database configurations allow specifying the metric at index creation. Pinecone, Weaviate, Qdrant, and Chroma all support cosine, dot product, and L2 as configuration options. Changing the metric after index creation typically requires re-indexing.

    Frequently Asked Questions

    Is cosine similarity always better than dot product for text?

    Not always. For unit-norm vectors, they are identical. For unnormalised vectors, cosine is generally better for text retrieval because it ignores irrelevant magnitude differences. However, if the embedding model was specifically trained with dot product loss on unnormalised vectors, using dot product will produce better results than cosine.

    What is the cosine similarity range and what does a score of 0.8 mean?

    Cosine similarity ranges from -1 to 1. A score of 1 means identical direction; 0 means orthogonal (unrelated); -1 means opposite meaning. For text embeddings, scores above 0.85 are typically considered highly similar. A score of 0.8 suggests meaningful semantic overlap but not identical meaning. The interpretation depends on the embedding model's specific space geometry.

    Does Google use cosine similarity for search?

    Google has not publicly disclosed its specific similarity measures for production retrieval. However, cosine similarity is the standard measure in semantic search research and is almost certainly used in some form within Google's embedding-based retrieval systems. The underlying principle — comparing query and document vectors directionally — is confirmed by extensive published research from Google.

    Can a similarity score be negative?

    Cosine similarity can theoretically be negative (-1 to 1), but in practice text embeddings rarely produce negative cosine similarities because all texts occupy a portion of the positive semantic space. Dot product can be negative without normalisation. L2 distance is always non-negative.

    Does the similarity measure matter for HNSW indexing?

    Yes. HNSW graph construction uses a distance measure to connect nearby nodes. If the index is built with L2 distance but queried with cosine similarity, the graph structure will not reflect the retrieval measure, reducing recall. Always build the HNSW index with the same measure you will use at query time.

    Optimise Content for Semantic Retrieval

    AI Overviews and generative search engines retrieve content by vector similarity. We help brands produce content that scores high in the retrieval layer, not just in traditional rankings.

    Tharindu Gunawardana

    Tharindu Gunawardana

    Founder and Director of SearchMinistry

    Tharindu Gunawardana is the Founder of SearchMinistry Media and a search strategist with 17 years of experience across Sri Lanka, Singapore, and Australia. A former Agency SEO Director, he specialises in helping brands transition from traditional SEO to AI-driven discovery.

    Leave a Reply