MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / cosineSim

Function cosineSim

implementations/browser/embedding-bench.mjs:108–116  ·  view source on GitHub ↗
(a, b)

Source from the content-addressed store, hash-verified

106}
107
108function cosineSim(a, b) {
109 let dot = 0, normA = 0, normB = 0;
110 for (let i = 0; i < a.length; i++) {
111 dot += a[i] * b[i];
112 normA += a[i] * a[i];
113 normB += b[i] * b[i];
114 }
115 return dot / (Math.sqrt(normA) * Math.sqrt(normB) + 1e-10);
116}
117
118function quantizeInt8(embedding) {
119 const maxVal = Math.max(...embedding.map(Math.abs));

Callers 1

benchmarkModelFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected