Cosine Text Similarity Calculator
Score how closely two passages use the same words, from 0 when they share none to 1 when their word patterns match. «The quick brown fox jumps over the dog» and its reshuffled twin share 7 terms. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Text a
- The quick brown fox jumps over the dog.
- Text b
- A quick brown dog jumps over the fox.
- Cosine similarity
- 0.894427191
- Dot product
- 8
- Magnitude a
- 3.1622776602
- Magnitude b
- 2.8284271247
This cosine text similarity calculator turns each passage into a word-frequency vector and measures the angle between those vectors. The resulting score runs from 0, when the texts share no counted words, to 1, when their word-frequency patterns point in the same direction. Alongside the score, it reports token counts, vocabulary size, vector magnitudes, the dot product, and shared terms. It is a deterministic, inspectable way to compare lexical content without a language model or an external service.
Turn two passages into comparable vectors
Paste one passage into each text field. The calculator converts both inputs to lowercase, extracts Unicode sequences made from letters or numbers, and keeps internal apostrophes in words such as “don’t.” Punctuation and spacing do not become vector dimensions.
Every distinct token across both passages forms one dimension of a shared vocabulary, while the number of appearances of that token becomes the coordinate for each text. For example, a word used three times contributes a frequency of three rather than merely recording that the word exists. This makes repeated subject vocabulary matter to the comparison.
The output includes the token count for each passage, the combined vocabulary size, and an alphabetically sorted list of terms found in both. Those details let you inspect what contributed to the result instead of accepting an unexplained score. Letter case alone never changes the score, but spelling, inflection, and different word choices can.
No stemming, synonym expansion, stop-word removal, or semantic interpretation is applied.
Read the cosine similarity score correctly
Cosine similarity divides the vectors’ dot product by the product of their magnitudes. The dot product increases when the same words occur in both passages, especially when their frequencies are high. Normalizing by both magnitudes makes the result less dependent on raw passage length than a simple shared-word count.
A score of 1 means the two frequency vectors have the same direction: their relative word-use patterns match, even if one passage repeats every word more times. A score of 0 means there are no shared counted terms. Establish a threshold with representative examples from your own documents, then use it consistently.
The returned dot product and magnitudes are included so students, analysts, and developers can verify the calculation or reproduce it elsewhere. Cosine similarity measures word-frequency structure; it does not prove authorship, copying, factual agreement, or equivalent meaning.
Choose this metric for transparent lexical comparison
Use this calculator when you need a fast, explainable baseline for content overlap. It works well for classroom demonstrations of vector space models, comparing drafts that are expected to reuse terminology, checking whether short descriptions cover similar vocabulary, or building a deterministic feature for a larger analysis pipeline. It differs from edit distance, which focuses on character-level changes and order, and from shingle comparison, which looks for matching sequences of neighboring words.
It also differs from embedding-based semantic similarity: embeddings may recognize related ideas expressed with different vocabulary, whereas this tool only rewards actual token overlap and frequency patterns. That limitation is often useful because every contribution can be traced to a shared term. Review the shared-terms list when a score seems surprising; common function words can raise similarity even when subject matter differs.
If those words should not count, remove them from both inputs before comparing.
What you can do with it
Teach vector space similarity
Show how token frequencies, a dot product, and vector magnitudes combine into a reproducible cosine score.
Compare document drafts
Measure whether two revisions retain similar vocabulary and inspect the exact terms they continue to share.
Build a lexical baseline
Create a transparent reference score before evaluating more complex semantic or sequence-based comparison methods.
FAQ
What does the cosine similarity score mean?
It ranges from 0 for no shared counted terms to 1 for frequency vectors with identical direction. Intermediate values indicate partial lexical overlap.
Does capitalization or punctuation affect the result?
Capitalization does not, because tokens are lowercased. Punctuation separates tokens except for apostrophes inside words.
Does this detect synonyms or similar meaning?
No. It compares exact lowercased word tokens and their frequencies, so different words with related meanings do not match automatically.
Is word order considered?
No. A frequency vector records how often each token occurs, not where it appears. Use a sequence-based method when order matters.
What score counts as similar enough?
There is no universal threshold. Values between 0 and 1 show partial word overlap, so set your own cut-off with representative documents and apply it consistently. A high score never proves copying, authorship or the same meaning.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/edu/cosine-text-similarity \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"text_a":"The quick brown fox jumps over the dog.","text_b":"A quick brown dog jumps over the fox."}'const res = await fetch("https://api.kit.forhosting.com/edu/cosine-text-similarity", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"text_a": "The quick brown fox jumps over the dog.",
"text_b": "A quick brown dog jumps over the fox."
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/edu/cosine-text-similarity",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"text_a": "The quick brown fox jumps over the dog.",
"text_b": "A quick brown dog jumps over the fox."
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/edu/cosine-text-similarity", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"text_a":"The quick brown fox jumps over the dog.","text_b":"A quick brown dog jumps over the fox."}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"text_a":"The quick brown fox jumps over the dog.","text_b":"A quick brown dog jumps over the fox."}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/edu/cosine-text-similarity", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"text_a": "The quick brown fox jumps over the dog.",
"text_b": "A quick brown dog jumps over the fox."
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "edu.cosine_text_similarity",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
max_chars_per_text | 100000 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
Read the cosine similarity score correctly
Values between those endpoints indicate partial lexical overlap, but there is no universal threshold for “similar enough.”
Choose this metric for transparent lexical comparison
API requests cost $0.002, while the pure calculation uses no network, randomness, stored state, or model inference.
Technical questions
What does an API request cost?
Each API request costs $0.002. The calculation is deterministic and requires no external model or network service.