Created
June 16, 2024 01:50
-
-
Save calebdre/d2071e6934b96aa947d738e59a2fb759 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// math -> https://mathjs.org/index.html | |
export function cosineSimilarity(embedding1: number[], embedding2: number[]): number { | |
const dotProduct = math.dot(embedding1, embedding2) | |
const magnitude1 = math.norm(embedding1) | |
const magnitude2 = math.norm(embedding2) | |
return dotProduct / (magnitude1 * magnitude2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment