agsamantha/node_modules/langchain/dist/util/ml-distance-euclidean/euclidean.js

11 lines
245 B
JavaScript
Raw Normal View History

2024-10-02 15:15:21 -05:00
export function squaredEuclidean(p, q) {
let d = 0;
for (let i = 0; i < p.length; i++) {
d += (p[i] - q[i]) * (p[i] - q[i]);
}
return d;
}
export function euclidean(p, q) {
return Math.sqrt(squaredEuclidean(p, q));
}