npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@smcgann/node-red-cosine-similarity-plus

v0.0.2

Published

Calculates cosine similarity of two vector values in Node-RED

Readme

platform npm version Min Node Version GitHub license

@smcgann/node-red-cosine-similarity-plus

A Node-RED node that calculates the cosine similarity, between a set of stored vectors and provided vector values.

This node is a significantly modified version of 🔗 @good-i-deer/node-red-contrib-cosine-similarity and doesn't maintain compatibility with that node.


Key Changes

input data - accepts payload direct from 🔗 @smcgann/node-red-face-vectorization-plus.
✔ Supports multiple stored vector locations: file, flow context, or global context.
✔ Stored vectors now also include names and image file data, for meaningful results.
✔ Returns sorted results, filtered by a configurable similarity threshold.
✔ Generates an error message if no results meet threshold.
✔ More robust error handling with validation for missing and invalid data structures.
✔ Supports runtime configuration through msg.cosineOptions for dynamic settings.
✔ Includes metadata in msg.cosineConfig (threshold used, file type, file path).
Easier integration into Node-RED flows.


Description

This node calculates cosine similarity between two sets of vectors. One passed in by msg.payload and one stored in a file or context variable. It returns the results in msg.payloadas an array of objects, where the similarity is above set threshold.

input = array[2] // (2 faces)

0: array[0.12, 0.34, 0.56, "..."] // 512 vectors for each face.
1: array[0.11, 0.22, 0.33, "..."]

// Stored as a nested object, with each key representing an individual person.
storedVectors = 
{
  "Adam": {
    "/full-path/Adam/Adam-01.jpg": [0.12, 0.34, 0.56, "..."], // 512 vectors for each face.
    "/full-path/Adam/Adam-03.jpg": [0.23, 0.45, 0.67, "..."],
    "/full-path/Adam/Adam-02.jpg": [0.34, 0.56, 0.78, "..."]
  },
  "Alison": {
    "/full-path/Alison/Alison-01.jpg": [0.11, 0.22, 0.33, "..."],
    "/full-path/Alison/Alison-02.jpg": [0.44, 0.55, 0.66, "..."]
  }
  // repeated for x number of people

}

output = array[2] // (2 matches above threshold)
[
    { "Alison": { "/full-path/Alison/8.jpg": 0.7265643591861766 } },
    { "Peter": { "/full-path/people/Peter/9.jpg": 0.6443388973714721 } }
]

Installation

Either use the Edit Menu - Manage Palette option to install, or run the following command in your Node-RED user directory - typically ~/.node-red

cd ~/.node-red
npm install @smcgann/node-red-cosine-similarity-plus

Restart your Node-RED instance


Input Properties

📌 msg.payloadArray

  • The input is an array of vector arrays. (created by the vectorize node)

⚙️ msg.cosineOptionsObject (Optional)

  • Allows overriding node config settings dynamically.
  • Example:
{  
  "threshold": 0.4,  
  "fileType":"path",
  "file":"/home/pi/vectortest.txt" 
}  

Node Properties

🏷️ Name

  • The name of the node displayed on the screen.

🎚️ Threshold

  • Results with a value equal to or above the specified threshold will be returned. Set the threshold to 0 to include all matches.

📂 Vectors

  • File or context path of file or variable, that will be compared with the input vector array. Cannot be empty.

Output

📌 msg.payloadArray

  • The output is an array of name objects. Each containing the orginal source image file and percentage similarity to the input vectors.

⚙️ msg.cosineConfigObject

  • The configuration used for the calculations.

✍️ Authors

S.McGann → Modified Version.

GOOD-I-DEER in SSAFY(Samsung Software Academy for Youth) 9th


📜 Copyright and license

S.McGann → Modified Version
Copyright Samsung Automation Studio Team under the Apache 2.0 license


Reference