Cosine similarity is a score that shows how alike 2 pieces of content are by measuring the angle between their number lists, called vectors or embeddings. A score near 1 means they point the same way and so mean much the same thing. A score near 0 means they are unrelated. AI search tools use it to decide which passages best match a question.
What is cosine similarity? #
Computers cannot compare meaning directly, so AI systems turn text into long lists of numbers. These lists are embeddings. Each list is a point, or an arrow, in a space with hundreds or thousands of directions. OpenAI’s embeddings guide says its text-embedding-3-small model makes vectors 1,536 numbers long, and text-embedding-3-large makes 3,072.
Cosine similarity asks one question about 2 arrows: do they point the same way? It ignores how long the arrows are and looks only at the angle between them. Same direction gives 1. A right angle gives 0. Opposite directions give minus 1.
How is it worked out? #
The formula is short. You multiply the 2 lists number by number and add the results. That sum is the dot product. Then you divide it by the length of each list multiplied together. The scikit-learn documentation writes it as the normalised dot product of X and Y:
cosine(X, Y) = (X · Y) / (|X| × |Y|)
A tiny example with 3 numbers each. Take X = (1, 1, 0) and Y = (1, 0, 0).
- Dot product: 1×1 + 1×0 + 0×0 = 1.
- Length of X: the square root of 2, about 1.414. Length of Y: 1.
- Cosine: 1 ÷ 1.414 = about 0.707.
The scikit-learn page shows the same kind of sum in its own example, where (1, 1, 1) against (1, 1, 0) gives 0.816.
How is it different from dot product and distance? #
| Measure | What it looks at | Higher or lower when more alike? |
|---|---|---|
| Cosine similarity | The angle only | Higher |
| Dot product | The angle and both lengths | Higher |
| Euclidean distance | The gap between the 2 arrow tips | Lower |
Google’s machine learning course on similarity measures sets out these 3 and notes that, unlike the cosine, the dot product grows with vector length. It also says that once every vector is scaled to length 1, all 3 measures move in step with the cosine. That is why many systems normalise vectors first and then use the cheaper dot product. OpenAI’s guide shows the same step: if you cut an embedding to fewer numbers, you must normalise it again.
Why does it matter for search? #
Older search matched words. TF-IDF and keyword density belong to that world. Modern semantic search and vector search match meaning. A page about “battery lifespan” can score highly for “how many years will my car battery last” with few shared words, because the embeddings point the same way. This is why search intent and plain answers matter more than repeating a phrase. Keyword stuffing does not move the angle much.
Why does it matter for AI answers? #
Retrieval-augmented generation, or RAG, is how many AI assistants find facts before they answer. The system splits pages into chunks, makes an embedding for each, and stores them. When someone asks a question, it makes an embedding of the question and pulls the chunks with the highest cosine scores. Those chunks go to the large language model, which writes the answer. OpenAI’s guide says its search examples rank documents by the cosine similarity between the query vector and each document vector.
So the shape of your text matters. A chunk that mixes 3 topics ends up pointing somewhere in the middle and matches none of them well. A chunk that answers one question clearly points straight at that question. That is the case for content chunking, clear heading tags and answer-first formatting.
Common mistakes #
- Treating the score as a percentage. 0.82 does not mean “82% the same”. Scores only make sense compared with other scores from the same model.
- Mixing models. Vectors from 2 different embedding models live in different spaces. Comparing them gives nonsense.
- Using one fixed cut-off everywhere. A good match in one model may score 0.5, in another 0.8. Test on your own content.
- Thinking high similarity means correct. A wrong answer phrased like the question can score well. Similarity finds related text, not true text. That gap is one cause of AI hallucinations.
A worked example #
A UK online shop sells kitchen knives. Its returns page is one long block mixing delivery times, returns, sharpening and warranty. A customer asks an assistant “Can I return a knife after 30 days?”. The retriever compares the question with every chunk. The long mixed chunk scores lower than a short forum post that answers that exact question, so the forum post is quoted.
The shop splits the page into short sections, each under a question heading, with the answer in the first sentence. Now the returns chunk points almost the same way as the question and is the closest match. Nothing about the policy changed. Only the shape of the text did.
How to check it #
- Paste a page into the RAG chunk previewer to see how it might be split.
- See which questions each section answers: try the heading answer gap finder, then the question coverage mapper.
- Group related phrases with our keyword clusters tool and test plain wording with the readability checker.
- Run the AI readiness checker and the markdown version checker for the wider picture. Our answer-first checker (Pro) is being built.
Questions #
What is a good cosine similarity score? #
There is no single number. It depends on the model and the task. Compare scores within one model and look at which chunks win.
Can I see the scores an AI assistant used? #
Usually not. The public assistants do not show them. You can only shape your content so the right passage is the clearest match.
Is cosine similarity only for text? #
No. It works on any vectors, including image and product embeddings used in visual search.
Related words #
Sources #
- OpenAI API docs: Vector embeddings, checked 25 November 2026
- scikit-learn: cosine_similarity, checked 25 November 2026
- Google for Developers: Supervised similarity measure (Machine Learning course), checked 25 November 2026
Updated 25 November 2026 by URSY.
Cite this page: Cosine similarity. URSY. Updated 25 November 2026. https://ursy.com/wiki/cosine-similarity/ · Section links
Tools for this
- LiveAI Readiness Checkeris your site ready for ChatGPT, Gemini, Claude? Score + fixesRun the check →
- LiveAI Bot Checkerwhich AI bots your robots.txt lets inRun the check →
- LiveRobots.txt Checker + Generatortest any address against your rules, or write new onesRun the check →
- LiveSchema Markup CheckerRun the check →