MCPcopy Create free account
hub / github.com/forloopcodes/contextplus / cosine

Function cosine

test/demo/embeddings-proof.demo.mjs:90–91  ·  view source on GitHub ↗
(a, b)

Source from the content-addressed store, hash-verified

88 const dot12 = vectors[1].reduce((s, x, i) => s + x * vectors[2][i], 0);
89 const norm = (v) => Math.sqrt(v.reduce((s, x) => s + x * x, 0));
90 const cosine = (a, b) =>
91 a.reduce((s, x, i) => s + x * b[i], 0) / (norm(a) * norm(b));
92
93 console.log("\n Cosine similarities:");
94 console.log(

Callers 1

Calls 1

normFunction · 0.85

Tested by

no test coverage detected