---
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://mixpeek.com/.well-known/search?q={query}"
  method: GET
  documentation: "https://mixpeek.com/llms.txt"
---

1.  [](/)
2.  [Glossary](/glossary)
3.  Cosine Similarity

[Back to Glossary](/glossary)

# What is Cosine Similarity

## Cosine Similarity - Similarity measure

Cosine similarity measures how closely two vectors point in the same direction: their dot product divided by the product of their lengths, from -1 to 1. It is the most common way to compare embeddings in vector search, alongside dot product and Euclidean (L2) distance.

### How It Works

Cosine similarity measures the cosine of the angle between two vectors, providing a metric for similarity based on direction rather than magnitude. It's commonly used in vector space models to compare document similarity.

### Technical Details

Calculated as the dot product of two vectors divided by the product of their magnitudes. Values range from -1 (completely dissimilar) to 1 (completely similar), with 0 indicating orthogonality.

### Cosine vs Dot Product vs Euclidean (L2) vs Manhattan (L1)

*   Cosine similarity: dot(a, b) / (|a| × |b|); compares direction only, from -1 to 1
*   Dot product: Σ a\_i × b\_i; direction and length together, so longer vectors score higher
*   Euclidean (L2) distance: √Σ (a\_i - b\_i)²; straight-line distance, lower is closer
*   Manhattan (L1) distance: Σ |a\_i - b\_i|; sum of per-dimension differences, less sensitive to one large difference
*   Example with a = (1, 0, 1) and b = (0, 1, 1): dot = 1, cosine = 1 / (1.414 × 1.414) = 0.5, L2 = 1.414, L1 = 2
*   For vectors normalized to length 1, cosine, dot product and L2 rank results in the same order, since L2² = 2 - 2 × cosine
*   Use the metric the embedding model was trained with; most text and image embedding models specify cosine or dot product

### Distance Metrics in Mixpeek

Each vector index in a Mixpeek collection has one distance metric. Built-in extractors set it for you; a [custom extractor](https://mixpeek.com/docs/processing/custom-extractors) declares it as \`distance\_metric\` in its manifest, with \`"cosine"\`, \`"euclid"\` or \`"dot"\`. Manhattan (L1) is not one of the options.

### Best Practices

*   Normalize vectors before computing similarity
*   Use for high-dimensional data comparisons
*   Combine with other metrics for comprehensive analysis
*   Optimize vector storage for performance
*   Regularly assess similarity thresholds

### Common Pitfalls

*   Ignoring vector normalization
*   Over-relying on cosine similarity alone
*   Inadequate threshold tuning
*   Poor vector storage optimization
*   Lack of comprehensive similarity analysis

### Advanced Tips

*   Implement hybrid similarity measures
*   Use dimensionality reduction for efficiency
*   Consider domain-specific similarity adjustments
*   Optimize for specific use cases
*   Regularly review similarity performance

[One-click templatesStart from a templateEach template deploys a working search app on your own files.Browse templates](/templates)

[Put it to work: search your own files](https://studio.mixpeek.com/namespaces/create?mode=managed&utm_source=homepage&utm_medium=glossary_onramp&utm_campaign=mvs_onramp)

### Related Terms

[ACID](/glossary/acid)[API](/glossary/api)[Blob Storage](/glossary/blob-storage)[CLIP](/glossary/clip)[Embedding](/glossary/embedding)