Skip to content
Ask Sera Search
Ask SeraAnswers from our guides, research and news Search
Learn
Guides
Research
Sectors
Platforms
News
Tools
About

What is cosine similarity?

Cosine similarity measures how close two vectors are by the angle between them. Semantic search uses it to compare a query embedding with document embeddings.

In short. Cosine similarity is a measure of how close two vectors are, based on the angle between them. Semantic search uses it to compare the embedding of a query with the embeddings of documents, and ranks the closest documents first. Two vectors that point the same way score 1, whatever their length. OpenAI recommends cosine similarity for its embeddings.

On this page 7 sections

The evidence

  • Confirmed:

    OpenAI recommends cosine similarity. Its embeddings are normalized to length 1, so cosine similarity and Euclidean distance give identical rankings.2OpenAI API documentation. Checked Dec 1, 2026

  • Confirmed:

    Introduction to Information Retrieval defines cosine similarity as the dot product of two vectors divided by the product of their lengths. The division compensates for differences in document length.1Introduction to Information Retrieval, Cambridge University Press

    Cambridge University Press textbook, online edition. Checked Dec 1, 2026.

  • Confirmed:

    Azure AI Search supports cosine, dot product and Euclidean metrics for vector search, and says to use cosine with Azure OpenAI embedding models.3Microsoft Learn. Checked Dec 1, 2026

  • Confirmed:

    Azure AI Search does not report the raw cosine as its vector score. It reports 1 / (1 + cosine distance), where cosine distance is 1 minus cosine similarity.3Microsoft Learn. Checked Dec 1, 2026

Confirmed by the platform

Cosine similarity is the score that most semantic search systems use to decide which passage is closest in meaning to a query. It compares the direction of two vectors and ignores their length.

#How is cosine similarity calculated?

Cosine similarity divides the dot product of two vectors by the product of their lengths. The section on dot products in Introduction to Information Retrieval, a Cambridge University Press textbook, gives the formula. The dot product multiplies the vectors position by position and adds the results. The length of a vector is the square root of the sum of its squared values. The result is the cosine of the angle between the two vectors.1

Take three short vectors: a = (1, 2), b = (2, 4) and c = (2, -1). The vector b points the same way as a and is twice as long. Its dot product with a is 10, and the product of the lengths is also 10, so the cosine similarity is 1. The dot product of a and c is 0, so their cosine similarity is 0.

#Why do search systems use cosine similarity?

Cosine similarity ignores length. The textbook explains that the distance between two document vectors can be large because one document is much longer than the other, even when the content is similar. Dividing by the two lengths turns both vectors into unit vectors, so only their direction counts.1

For embeddings, the choice of measure often makes little difference. OpenAI's embeddings guide recommends cosine similarity and says the choice of distance function typically does not matter much. OpenAI embeddings are normalized to length 1. For that reason, a plain dot product gives the same value slightly faster, and Euclidean distance gives identical rankings.2

A semantic search system embeds the query and compares it with the stored embeddings of documents or passages. OpenAI's retrieval guide shows the effect for the query "When did we go to the moon?". The passage "The first lunar landing occurred in July of 1969." scored 65% semantic similarity, measured with cosine similarity, and 0% keyword similarity.4

A vector database uses the measure to find nearest neighbors quickly. Microsoft's page on relevance in Azure AI Search vector search says its HNSW algorithm moves through a graph toward vectors that are closer to the query by the configured metric, such as cosine similarity.3 This search is the core of dense retrieval.

#What is the difference between cosine similarity and cosine distance?

Cosine distance is 1 minus cosine similarity, so a smaller distance means a closer match. Microsoft defines both terms. Azure AI Search turns the distance into a score of 1 / (1 + cosine distance), which falls between 0.333 and 1.00 and always decreases as similarity gets worse.3

What are vector embeddings? explains how embeddings are made and how retrieval systems compare them.

Read next

Related terms

Questions

What is a good cosine similarity score?

There is no fixed threshold, because scores depend on the embedding model. OpenAI's file search lets developers set their own score threshold between 0 and 1. In OpenAI's moon example, the best match for the query scored 65% semantic similarity.

What is the difference between cosine similarity and dot product?

The dot product also grows with the length of the vectors, and cosine similarity divides that length out. For vectors normalized to length 1, the two give the same result. Microsoft says dot product is then slightly faster.

Can cosine similarity be negative?

Yes. It is the cosine of an angle, so it ranges from -1 for vectors that point in opposite directions to 1 for vectors that point the same way. A score of 0 means the vectors are at a right angle.

About this page

Researched and reviewed by Promptly Found. Reviewed Dec 1, 2026. Next review due Mar 2027.

Notes

  1. 1
    Dot productsIntroduction to Information Retrieval, Cambridge University Press · Checked Dec 1, 2026 · Secondary source
  2. 2
    Vector embeddingsOpenAI API documentation · Checked Dec 1, 2026 · Primary source
  3. 3
    Relevance in vector searchMicrosoft Learn · Checked Dec 1, 2026 · Primary source
  4. 4
    RetrievalOpenAI API documentation · Checked Dec 1, 2026 · Primary source
Cite this page
Citation style

Promptly Found. (2026, December 1). What is cosine similarity? https://promptlyfound.com/glossary/cosine-similarity

Revisions 1
First published.