(a: number[], b: number[])
| 165 | } |
| 166 | |
| 167 | export function cosineSim(a: number[], b: number[]): number { |
| 168 | let dot = 0, na = 0, nb = 0; |
| 169 | const len = Math.min(a.length, b.length); |
| 170 | for (let i = 0; i < len; i++) { |
| 171 | dot += a[i]! * b[i]!; |
| 172 | na += a[i]! * a[i]!; |
| 173 | nb += b[i]! * b[i]!; |
| 174 | } |
| 175 | if (na === 0 || nb === 0) return 0; |
| 176 | return dot / (Math.sqrt(na) * Math.sqrt(nb)); |
| 177 | } |
| 178 | |
| 179 | export function indexPath(projectRoot: string, embeddingModel: string): string { |
| 180 | const hash = createHash('sha1').update(`${projectRoot}::${embeddingModel}`).digest('hex').slice(0, 16); |
no outgoing calls
no test coverage detected