You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Inefficient function the get the closest vectors from an array.
constclosestVectors=(vec,vectors)=>{constdistances=vectors.map(v=>cosineSimilarity(vec,v));constmin=Math.min(...distances);// Check if multiple with same distanceconstminIndices=distances.reduce((a,e,i)=>{if(e===min)a.push(i);returna;},[]);// Return list of closest vectorsreturn{vectors: minIndices.map(i=>vectors[i]),distances: minIndices.map(i=>distances[i])};};
When using a metric such as Cosine similarity, the returned vector is almost never the one with the smallest distance value.
Example:
Dataset
Inefficient function the get the closest vectors from an array.
Testing
Clearly the tree returns a vector with a slightly larger distance (0.998 vs 0.999).
The text was updated successfully, but these errors were encountered: