Last active
July 8, 2023 03:19
-
-
Save usametov/509f3466e141db6f125b815c5ae12c75 to your computer and use it in GitHub Desktop.
cosine-similarity
This file contains hidden or 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
(:require [tech.v3.datatype.functional :as func]) | |
(defn cosine-similarity | |
[v1 v2] | |
(/ (func/dot-product v1 v2) | |
(Math/sqrt (* (func/magnitude-squared v1) (func/magnitude-squared v2))))) | |
;; Maybe, we don't really need to divide by magnitudes product. | |
;; it looks like embeddings coming from openai are already normalized. |
This file contains hidden or 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
{:deps { | |
techascent/tech.ml.dataset {:mvn/version "7.000-beta-51"} | |
techascent/tech.datatype {:mvn/version "5.18"}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment