We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hello, It will be great if we can choose between euclidean and cosinus similarity in LLPhant\Embeddings\VectorStores\DistancesL2Utils.
This 2 approaches have advantage and disadvantage in function what we want to do.
Example :
public function cosineSimilarity($vector1, $vector2): float|int { // Calculate the dot product of the two vectors $dotProduct = array_sum(array_map(function ($a, $b) { return $a * $b; }, $vector1, $vector2)); // Calculate the magnitudes of each vector $magnitude1 = sqrt(array_sum(array_map(function ($a) { return $a * $a; }, $vector1))); $magnitude2 = sqrt(array_sum(array_map(function ($a) { return $a * $a; }, $vector2))); // Avoid division by zero if ($magnitude1 * $magnitude2 == 0) { return 0; } // Calculate the cosine similarity $cosineSimilarity = $dotProduct / ($magnitude1 * $magnitude2); return $cosineSimilarity; }
The text was updated successfully, but these errors were encountered:
Yes I agree 👍️
Sorry, something went wrong.
No branches or pull requests
Hello,
It will be great if we can choose between euclidean and cosinus similarity in LLPhant\Embeddings\VectorStores\DistancesL2Utils.
This 2 approaches have advantage and disadvantage in function what we want to do.
Example :
The text was updated successfully, but these errors were encountered: