{"uid":"cap_7CcYx0ZYy2972ISZaTGgB","slug":"text-similarity-cosine-word-count-vectors-4e66d4c7","name":"Text Similarity – Cosine (Word-Count Vectors)","description":"Cosine similarity of the word-count vectors of two texts, with shared terms and vector norms.","url":"https://text-similarity.x402tookit.com/cosine-tokens?utm_source=zero.xyz","method":"GET","headers":{},"bodySchema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","required":["input"],"properties":{"input":{"type":"object","required":["type","method"],"properties":{"type":{"type":"string","const":"http"},"method":{"enum":["GET"],"type":"string"},"queryParams":{"type":"object","required":["a","b"],"properties":{"a":{"type":"string","description":"First text, up to 2000 characters"},"b":{"type":"string","description":"Second text, up to 2000 characters"},"ignoreCase":{"type":"boolean","description":"true (default) lowercases both texts first"}}}},"additionalProperties":false},"output":{"type":"object","required":["type"],"properties":{"type":{"type":"string"},"example":{"type":"object","properties":{"dot":{"type":["null","number"]},"asOf":{"type":["null","string"]},"normA":{"type":["null","number"]},"normB":{"type":["null","number"]},"cosine":{"type":["null","number"]},"source":{"type":["null","string"]},"reasons":{"type":["array","null"],"items":{"type":"string"}},"summary":{"type":["null","string"]},"tokensA":{"type":["null","number"]},"tokensB":{"type":["null","number"]},"verdict":{"type":["null","string"]},"degraded":{"type":["boolean","null"]},"distinctA":{"type":["null","number"]},"distinctB":{"type":["null","number"]},"disclaimer":{"type":["null","string"]},"ignoreCase":{"type":["boolean","null"]},"notChecked":{"type":["array","null"],"items":{"type":"string"}},"sharedTerms":{"type":["null","number"]}}}}}}},"responseSchema":null,"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.02","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.02/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.02","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.02","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_eRNYb0Rvs_ZIYNPH_Gsp2","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.02","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Computes cosine similarity between two texts using word-count (bag-of-words) vectors, returning the similarity score, dot product, vector norms, and shared term count.","exampleAgentPrompt":"Can you compute the cosine similarity between these two texts using word-count vectors? Text A: 'The quick brown fox jumps over the lazy dog' and Text B: 'A fast brown fox leaped over a sleepy dog' — treat them as case-insensitive.","exampleUseCases":[{"title":"Duplicate support ticket detection","prompt":"Check if these two support tickets are essentially saying the same thing — Text A: 'My app keeps crashing every time I open it on iOS 17' and Text B: 'The application crashes on launch on my iPhone running iOS 17' — give me a cosine similarity score so I can decide if they should be merged."},{"title":"Plagiarism check on student submissions","prompt":"I need to compare two student essay excerpts for similarity. Text A is 'Climate change is driven by greenhouse gas emissions from human activities such as burning fossil fuels.' and Text B is 'Human activities, particularly the burning of fossil fuels, are the primary cause of greenhouse gas emissions and climate change.' Can you get the cosine similarity between them?"},{"title":"Product description deduplication","prompt":"Tell me how similar these two product descriptions are so I can decide if they're duplicates: Text A is 'Wireless Bluetooth headphones with 30-hour battery life and active noise cancellation' and Text B is 'Noise-cancelling Bluetooth headphones offering 30 hours of wireless battery life' — use case-insensitive comparison."}],"resultDescription":"Returns a JSON object containing the cosine similarity score (0–1), dot product of the two word-count vectors, L2 norms of each vector (normA, normB), number of shared terms, distinct token counts for each text, token counts, a human-readable summary and verdict, the ignoreCase setting used, and optional degraded/disclaimer flags.","failureModes":["Missing required query parameters 'a' or 'b' returns an error","Texts exceeding 2000 characters may be rejected or truncated","Empty strings produce a zero-norm vector making cosine undefined (likely returns null or 0)","Payment failure (x402) prevents the call from completing","Very short single-word inputs may yield low-signal results"],"whenToPreferThis":"Choose this endpoint when you need a lightweight, interpretable word-frequency-based similarity score — especially for duplicate detection, near-match filtering, or any task where term overlap matters more than semantic meaning. It is faster and cheaper than embedding-based similarity and produces transparent intermediate values (norms, dot product, shared terms) useful for debugging or ranking. Prefer it over Dice/Jaccard endpoints when you want a continuous similarity metric that accounts for term frequency rather than just presence/absence.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-10-21T12:35:19.416Z","isFirstParty":false,"canonicalSlug":"text-similarity-cosine-word-count-vectors-4e66d4c7"}