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

Function norm

test/demo/embeddings-proof.demo.mjs:89–89  ·  view source on GitHub ↗
(v)

Source from the content-addressed store, hash-verified

87 const dot02 = vectors[0].reduce((s, x, i) => s + x * vectors[2][i], 0);
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

Callers 1

cosineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected