Skip to content
New issue

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

Normalize to speed up distance calculation #1

Merged
merged 1 commit into from
Oct 27, 2024
Merged

Normalize to speed up distance calculation #1

merged 1 commit into from
Oct 27, 2024

Conversation

kelindar
Copy link
Owner

This pull request introduces several optimizations and enhancements to the vector similarity calculations. The most important changes include adding a new dot product function, normalizing vectors before calculations, and updating benchmarks and tests to reflect these changes.

Optimizations and Enhancements:

  • internal/cosine/simd/simd.go: Introduced the DotProduct function to calculate the dot product between two vectors, added genericDotProduct for non-hardware implementations, and updated the Cosine function to use genericCosine for non-hardware cases. [1] [2]

  • bruteforce.go: Added vector normalization in the Add and Search methods to ensure vectors are unit vectors, allowing the use of dot product for cosine similarity calculations. [1] [2] [3]

Performance Improvements:

  • internal/cosine/cosine_apple.c, internal/cosine/cosine_avx.c, internal/cosine/cosine_neon.c: Added the f32_dot_product function to each SIMD implementation to support efficient dot product calculations. [1] [2] [3]

Benchmark and Test Updates:

Miscellaneous:

  • bruteforce_test.go: Updated benchmark results to reflect the performance improvements from using dot product and vector normalization.

@kelindar kelindar merged commit 2c06460 into main Oct 27, 2024
4 checks passed
@kelindar kelindar deleted the dotproduct branch October 27, 2024 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant