Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cos-similarity

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cos-similarity - npm Package Compare versions

Comparing version 1.1.1 to 2.0.0

index.d.ts

6

index.js

@@ -1,7 +0,1 @@

/**
* Returns the cosine similarity between the given `vectorA` and `vectorB`.
* Returns `0` when given a zero vector, `[]`, `undefined` or nothing.
*
* https://en.wikipedia.org/wiki/Cosine_similarity
*/
export default function (vectorA = [], vectorB = []) {

@@ -8,0 +2,0 @@ const dimensionality = Math.min(vectorA.length, vectorB.length);

36

package.json
{
"name": "cos-similarity",
"version": "1.1.1",
"version": "2.0.0",
"description": "Computes the cosine similarity between two vectors",

@@ -22,36 +22,30 @@ "keywords": [

"files": [
"dist",
"index.js"
"index.js",
"index.d.ts"
],
"main": "dist/index.cjs",
"repository": {
"type": "git",
"url": "https://github.com/rtomrud/cos-similarity.git"
"url": "git+https://github.com/rtomrud/cos-similarity.git"
},
"scripts": {
"bench": "node bench.js",
"build": "rollup -i index.js -o dist/index.cjs -f cjs --exports auto",
"format": "prettier --check .",
"lint": "eslint .",
"prepare": "npm run build",
"test": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js",
"posttest": "npm run lint"
"test": "node --test --experimental-test-coverage",
"posttest": "npm run lint && npm run format"
},
"devDependencies": {
"benchmark": "2.1.4",
"compute-cosine-similarity": "1.0.0",
"@eslint/js": "9.1.1",
"compute-cosine-similarity": "1.1.0",
"cosine-similarity": "1.0.1",
"eslint": "8.20.0",
"eslint-config-pretty-strict": "8.1.1",
"eslint-plugin-jest": "26.6.0",
"eslint-plugin-prettier": "4.2.1",
"jest": "28.1.3",
"prettier": "2.7.1",
"rollup": "2.77.0",
"tiny-tfidf": "0.9.1"
"cosine-similarity-threshold": "1.0.1",
"eslint": "8.57.0",
"mitata": "0.1.11",
"prettier": "3.2.5"
},
"type": "module",
"exports": {
"import": "./index.js",
"default": "./dist/index.cjs"
"types": "./index.d.ts",
"default": "./index.js"
}
}
# cos-similarity
[![build status](https://github.com/rtomrud/cos-similarity/workflows/ci/badge.svg)](https://github.com/rtomrud/cos-similarity/actions?query=branch%3Amaster+workflow%3Aci)
[![npm version](https://badgen.net/npm/v/cos-similarity)](https://www.npmjs.com/package/cos-similarity)
[![bundle size](https://badgen.net/bundlephobia/minzip/cos-similarity)](https://bundlephobia.com/result?p=cos-similarity)
Computes the [cosine similarity](https://en.wikipedia.org/wiki/Cosine_similarity) between two vectors

@@ -29,1 +25,26 @@

```
## Benchmark
To run the benchmark, clone the repositry and run the bench script:
```bash
npm run bench
```
```
benchmark time (avg) (min … max)
-------------------------------------------------------------------
• cosine similarity modules
-------------------------------------------------------------------
cos-similarity 249 ns/iter (247 ns … 319 ns)
compute-cosine-similarity 854 ns/iter (829 ns … 428 µs)
cosine-similarity 14'251 ns/iter (13'680 ns … 229 µs)
cosine-similarity-threshold 879 ns/iter (802 ns … 310 µs)
summary for cosine similarity modules
cos-similarity
3.43x faster than compute-cosine-similarity
3.53x faster than cosine-similarity-threshold
57.25x faster than cosine-similarity
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc