AI GLOSSARY · AI CONCEPTS
Cosine similarity
Definition
Cosine similarity is a measure of how closely two vectors point in the same direction, scored from -1 to 1. In AI search it commonly compares embeddings, which are lists of numbers standing for meaning.
Also called: cosine similarity embeddings, cosine similarity formula, cosine similarity search.
In plain language
Imagine each piece of text turned into an arrow in space, where texts with similar meaning point in similar directions. Cosine similarity measures the angle between two arrows: close to 1 means they point almost the same way, 0 means the nonzero vectors are orthogonal, and negative values point apart. Search systems use it to rank which stored passages best match a question. It tells you about direction, not about truth, so a passage that sounds like the question can score high even when it does not answer it.
Technical definition
For two nonzero vectors, cosine similarity is their dot product divided by the product of their lengths (the standard definition), which equals the cosine of the angle between them. Pinecone's guide describes it as a measure of the angle between two vectors, ranging from -1 to 1, and not affected by vector size. OpenAI's embeddings guide says its text search example uses the cosine similarity between the embedding vectors of the query and each document. The angle formula is undefined for zero vectors; software APIs may define their own convention, such as scikit-learn returning zero similarity for a zero-vector input.
Worked examples in this catalogue
Catalogue examples point at a skill, guide or coding tool listed on this site, with what to run and what you see. An example marked illustrative describes the item from its own documentation; it was not executed for this page. Platform Scores are our assessment under a published method, not a safety guarantee.
Guide · Illustrative, not executed
What Is RAG? Retrieval-Augmented Generation Explained
- What you see
- The guide explains that a question is embedded and the closest chunks are retrieved and placed in the prompt.
- Why it exercises the concept
- Closeness between the question vector and chunk vectors is the step a metric such as cosine similarity scores.
Skill by Skill Almanac · Illustrative, not executed
rag-chunking-planner 56/100 · Provisional, not yet measuredScored · Method v0.2 · How we score
- What you see
- Your documents chunked by three strategies, with defects and offline recall measured for each, so chunk settings are chosen with numbers.
- Why it exercises the concept
- Offline recall asks whether the right chunk comes back for a question. A similarity score is one part of how a retriever decides what comes back.
Skill by Skill Almanac · Illustrative, not executed
duplicate-passage-finder 41/100 · Provisional, not yet measuredScored · Method v0.2 · How we score
- What you see
- Exact and near-duplicate paragraphs found across a folder of text and Markdown files, reported by group with file and line number.
- Why it exercises the concept
- Finding near-duplicates is a similarity problem. Read the skill to see how it decides two passages are alike, which may differ from an embedding comparison.
How it shows up when you use agents
Cosine similarity is a common comparison in embedding-based search, but other similarity measures and retrieval methods are also used. When a vector database returns the "closest" passages for a question, it is comparing the question's embedding with stored ones using a metric, and cosine is a common choice. That is the retrieval step in RAG and in semantic search.
What breaks when it is misunderstood: a high score is read as a correct answer. It only says two texts sit in a similar direction, so a passage that repeats the question's wording can outrank the one that answers it.
Next action: when a retrieval looks wrong, print the scores next to the chunks and read them. Use one embedding model for both the question and the documents. If the right chunk is there but ranked low, consider reranking. Test any threshold on your own questions.
Common confusions
- Cosine similarity versus cosine distance. Similarity is higher for closer vectors. Distance is a related quantity where smaller means closer.
- Cosine versus Euclidean distance. Cosine compares direction and ignores vector length, as Pinecone's guide states. Euclidean distance compares position in space.
- Cosine similarity versus an embedding. An embedding is the vector. Cosine similarity is a way to compare two of them.
- Myth. A score of 1 means two texts mean the same thing. It means their vectors point the same way, which is evidence of similarity in the model's view, not proof.
Related terms
Show all 16 related terms
Terms that mention Cosine similarity
6 terms mention this one
More in AI concepts
Sources
- Vector Similarity Explained, Pinecone (accessed 2026-11-24)
- Vector embeddings, OpenAI (accessed 2026-11-24)
- cosine_similarity: normalized dot product and zero-input example, scikit-learn (accessed 2026-11-25)
Definitions are written by Skill Almanac from these sources and were checked against them on 2026-11-25. Wikipedia is never the only source.
Review record
Last verified
Drafted by Claude (original draft) and Codex (targeted revisions); sources and example targets checked by Independent automated source review (OpenAI Codex); not human peer review on 2026-11-25. Last verified .
Change log (5)
- : Independent automated factual/example review completed. Cached US query estimate aligned to receipt; no traffic promise. Final technical gate recorded separately; publication disabled.
- : First version.
- : Verifier pass: applied verifier corrections to unsourced or over-stated claims.
- : Applied bounded batch06 source-scope repairs; independent affected-claim recheck pending.
- : Automated review completed; approved for the staged public release. Search indexing is controlled by the release configuration.