Skip to content

Faster Exact Search 🎉

Compare
Choose a tag to compare
@ashvardanian ashvardanian released this 25 Sep 14:36
· 1 commit to be501724db187954804f13f20e0a8a1aacf2a9f8 since this release

At the cost of using a bit more memory, I've made the exact search significantly faster.
LLM don't always need billion-scale vector search, but they often need to search through a small set of high-dimensional vectors.
I've added a benchmark you can run on your hardware to compare USearch against FAISS's exact search functionality.

$ python python/scripts/bench_exact.py --ndim 256 --n 100_000 --q 10 --k 100
USearch:  0.013957023620605469
FAISS:    0.04720497131347656

$ python python/scripts/bench_exact.py --ndim 256 --n 100_000 --q 10 --k 100 --half
USearch:  0.014386892318725586
FAISS:    0.08691692352294922

Even without hardware acceleration from SimSIMD, on the M2 Mac Book Pro:

  • USearch performs 3.3x faster than FAISS on single-precision f32 vectors.
  • USearch performs 6.1x faster than FAISS on half-precision f16 vectors.

In some settings, the difference may reach 10x. Below are samples for the 13th Gen Intel Core i9-13950HX x86 CPU:

$ python python/scripts/bench_exact.py --ndim 256 --n 100_000 --q 10 --k 100
USearch:  0.024287939071655273
FAISS:    0.2323017120361328

$ python python/scripts/bench_exact.py --ndim 256 --n 100_000 --q 10 --k 100 --half
USearch:  0.04021167755126953
FAISS:    0.20610713958740234

$ python python/scripts/bench_exact.py --ndim 256 --n 100_000 --q 100 --k 100
USearch:  0.12478017807006836
FAISS:    0.5975005626678467

$ python python/scripts/bench_exact.py --ndim 256 --n 100_000 --q 100 --k 100 --half
USearch:  0.423309326171875
FAISS:    0.7565422058105469

$ python python/scripts/bench_exact.py --ndim 256 --n 10_000 --q 10 --k 100 --half
USearch:  0.02945685386657715
FAISS:    0.11811184883117676

$ python python/scripts/bench_exact.py --ndim 256 --n 10_000 --q 100 --k 100 --half
USearch:  0.06946372985839844
FAISS:    0.15354132652282715

The script is located at python/scripts/bench_exact.py and has a few CLI parameters:

  • --ndim - number of vector dimensions.
  • --n - number of vectors in the dataset to search.
  • --q - number of vectors to query among n.
  • --k - number of closest neighbors to retrieve per query.
  • --half - use half-precision.

For large q, FAISS works quite well - in such cases, it redirects the query to the linked BLAS implementation. But it means it supports only two metrics - L2 and inner product. With USearch exact search, you can still use all the same metrics as with usearch.index.Index class and provide custom JIT-ed CompiledMetric.


Thanks to @ebursztein, @guyrosin, and @vprelovac for suggesting the use case and spotting the issues!
Next step - expose exact search in JS, Rust, and Swift bindings 🎉

Hashes

  • docs.tar.gz : edb8e2a80790e80b75b5d6f869d327643d6bc6bff335561e90bcf6b648ff334e
  • usearch-v2.6.0.tar.gz : 3759c4c1102bc937b322dd9be1ddb372d3d713b6f8a74d475c487ccb9bdd378b
  • usearch-v2.6.0.zip : 66ba82ad76265d19afb061f79982355c1aa665489acc3b02ad68fce13b04e88a
  • usearch_linux_amd_2.6.0.deb : 6edd76af1d54a18da5a14002575fed425325017d5ae6b675f4995efd83b22045
  • usearch_linux_arm_2.6.0.deb : c16148a391381ecc87dbb038c0e1ad7a5c42728e6f25665aade1584f3e6adb9f
  • usearch_macOS_arm64_2.6.0.zip : 82697239671093d2c43e61682e465e1160cf77bed223cad62a735b81a86e00d9
  • usearch_macOS_x86_64_2.6.0.zip : 3b59742d3725e8153496c511ed966863c0cefb11c38517603f0917f51c5d5861
  • usearch_wasm_linux_arm64_2.6.0.tar.gz : 6fe59c9ec43109c4fa8c20d41c1ea64f86903123c61ac8a2034acc5f8a26dc26
  • usearch_wasm_linux_x86_64_2.6.0.tar.gz : 1e266401ce200490437493a54d9bd4cc522346305667c14ce84a21c28f8ae8ca
  • usearch_wasm_macos_arm64_2.6.0.zip : a10bd9a94925cc26a16fcaf9198e1277b3aa978b5248a21c732b9f5e1cbacb31
  • usearch_wasm_macos_x86_64_2.6.0.zip : 7dc81152a16c59ddabd3304e00f76cce2c43413447cf38aeb4b187af4c9f7c75
  • usearch_wasm_windows_x64_2.6.0.tar.gz : 6a6b701077d47830b26063005452369b9386a8f3210be7b6b724acce084a546a
  • usearch_wasm_windows_x86_2.6.0.tar.gz : af01ec3098a58f25d3e80f1747f019d4b705bf908d35f48d3b71aa7294756a9d
  • usearch_windows_x64_2.6.0.tar : aa3e1a054d6d340d0c967c361d46977513de3d14d3b5f0afaabc01c7add381a0
  • usearch_windows_x86_2.6.0.tar : 412c79eeec7909f33d9325c5bae5d22bcf78332e0b934ff198b5a0a41f552813