Cosine similarity is a way to measure how alike two pieces of text are by comparing the direction of the number lists that represent them. Once words or sentences are turned into embeddings, each one becomes a long list of numbers. Cosine similarity looks at the angle between those two lists: a small angle means similar meaning, a wide angle means unrelated.
Picture two arrows drawn from the same starting point. If they point almost the same way, the texts are close in meaning. If one points north and the other east, they are unrelated. The clever part is that length does not matter, only direction, so a one-line note and a long paragraph about the same topic can still score as a near-perfect match. This is exactly what powers semantic search, where results are ranked by meaning rather than shared keywords.
You will rarely calculate this by hand. A vector database stores the embeddings and runs the comparison for you, returning the top matches in milliseconds. The score, usually between 0 and 1, becomes the relevance ranking your users see.
Why pick the angle over plain distance? Two answers cover the same idea but one is three times longer. Measured by straight-line distance, the longer one looks far away just because it has more words. Cosine ignores that. It asks only which way each text leans, so length stops skewing the result. That is the property that makes it the default scoring method for chatbots, support search and recommendation features. Pick a sloppy formula and a customer asking to ‘cancel my plan’ gets sent a page about cancelling a meeting. Pick the right one and the genuinely matching article rises to the top.
At TopDevs we use cosine similarity inside the search and AI features we build, so a question gets answered with the genuinely relevant content instead of whatever happens to share a word.