MCPcopy Index your code
hub / github.com/forloopcodes/contextplus / cosine

Function cosine

src/tools/semantic-identifiers.ts:84–95  ·  view source on GitHub ↗
(a: number[], b: number[])

Source from the content-addressed store, hash-verified

82}
83
84function cosine(a: number[], b: number[]): number {
85 let dot = 0;
86 let normA = 0;
87 let normB = 0;
88 for (let i = 0; i < a.length; i++) {
89 dot += a[i] * b[i];
90 normA += a[i] * a[i];
91 normB += b[i] * b[i];
92 }
93 const denom = Math.sqrt(normA) * Math.sqrt(normB);
94 return denom === 0 ? 0 : dot / denom;
95}
96
97function clamp01(value: number): number {
98 if (value <= 0) return 0;

Callers 2

rankCallSitesFunction · 0.70
semanticIdentifierSearchFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected