liveBook · Manning

Cosine similarity

As explained in Enterprise RAG

Cosine similarity measures the angular similarity between two vectors by computing the cosine of the angle between them.

Cosine similarity measures how closely two embedding vectors point in the same direction by calculating the cosine of the angle between them. Because it emphasizes direction rather than magnitude, it supports semantic comparison across texts of different lengths. section 3.1

Use cosine similarity when configuring vector retrieval:

  • Select cosine similarity for an Azure AI Search vector search profile. section 3.1
  • Pair it with Exhaustive KNN for a small dataset when HNSW's additional in-memory structures are unnecessary. section 3.1
  • Match the vector field's 1,536 dimensions to the generated OpenAI embeddings. section 3.1
Figure 3.2 A correctly set-up Azure AI Search Index. Make sure to set the Retrievable, Filterable, Sortable, Facetable, and Searchable columns exactly as shown in this image.

Use the correctly configured Azure AI Search index as a setup checklist for vector retrieval settings. section 3.1

How Enterprise RAG covers it

How deep it goes
Defines angular similarity and applies it to index configuration, stopping short of mathematical derivations or implementation code.
Examples
Uses a 1,536-dimensional Azure AI Search vector field and compares Exhaustive KNN with HNSW.
What it assumes
Assumes embedding vectors and Azure AI Search, while explaining the similarity rationale from the concept level.
What you can do after
Operate/configure Azure AI Search vector retrieval with cosine similarity and an appropriate nearest-neighbor strategy.
How it connects
Connects embeddings, vector search, Exhaustive KNN, HNSW, and semantic similarity.

Also explained in

Compare how 25 books explain cosine similarity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Enterprise RAG. The section links point to the parts of the book it draws on.