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
2.27k stars 143 forks source link

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

Closed jbrummack closed 3 months ago

jbrummack commented 6 months 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 6 months 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 6 months 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 6 months ago

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

jbrummack commented 6 months 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).