unum-cloud / usearch

Fast Open-Source Search & Clustering engine × for Vectors & 🔜 Strings × in C++, C, Python, JavaScript, Rust, Java, Objective-C, Swift, C#, GoLang, and Wolfram 🔍
https://unum-cloud.github.io/usearch/
Apache License 2.0
1.92k stars 109 forks source link

(breaking) FIX for unexpected segfault when index dimensions don't add up #413

Open jbrummack opened 1 month ago

jbrummack commented 1 month ago

This should fix the problem of segfaulting by checking whether the dimensions are adding up and handling the edge case of hamming distance. Due to cxx::Exception being private I had to create a new error type that wraps C++ Exceptions and can output errors from "rustland". Therefore this fix could introduce breaking changes It works in my (small) codebase and passes tests, but due to finding more cases that cause an unexpected segfault in rust, I suggest merging these fixes together later.

ashvardanian commented 1 month ago

If we perform the size check in the C layer - we would avoid breaking changes and could merge as is. How does that sound?

jbrummack commented 1 month ago

Sounds like a better solution. Adding some more tests in the Rust part is probably a good idea; throwing out the changes in Rust except the test for having different vector sizes and relying on the C layer for making it pass.

ashvardanian commented 1 month ago

Yes, @jbrummack! Please let me know if you'd have time to implement those changes 🤗

jbrummack commented 1 month ago

I certainly have time to implement more Rust tests, as its probably synergistic with using the library in projects. I am not really constrained by time, but looking at the c layer would take a while since I don't have much experience with c/c++ (yet).