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

Function cosine

src/core/memory-graph.ts:66–77  ·  view source on GitHub ↗
(a: number[], b: number[])

Source from the content-addressed store, hash-verified

64}
65
66function cosine(a: number[], b: number[]): number {
67 const len = Math.min(a.length, b.length);
68 if (len === 0) return 0;
69 let dot = 0, normA = 0, normB = 0;
70 for (let i = 0; i < len; i++) {
71 dot += a[i] * b[i];
72 normA += a[i] * a[i];
73 normB += b[i] * b[i];
74 }
75 const denom = Math.sqrt(normA) * Math.sqrt(normB);
76 return denom === 0 ? 0 : dot / denom;
77}
78
79function decayWeight(edge: MemoryEdge): number {
80 const daysSinceCreation = (Date.now() - edge.createdAt) / 86_400_000;

Callers 3

searchGraphFunction · 0.70
traverseNeighborsFunction · 0.70
addInterlinkedContextFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected