A lightweight, header-only C++20 library for highly optimized numeric top-k selection, well-suited for vector database applications.
This fast top-k library adopts codes from Google Research's ScaNN (Scalable Nearest Neighbors) project.
It is refactored as a lean, header-only library with no external dependencies beyond the standard library. Makes it easy to integrate into various projects without the complexity of managing additional dependencies like Bazel, Abseil or TensorFlow, which ScaNN might utilize.
Check test or benchmark as examples.
- CPU: Intel Core i9-9880H @ 2.30GHz
- Compiler: Apple clang version 16.0.0
- Sources: fast topk and faiss
- Other methods, such as torch.topk and std::nth_element, were also benchmarked but showed significantly worse results.
- GPU accelerated implementation with radix k-th selection.
This library benefits from the excellent work done by the Google Research's ScaNN (Scalable Nearest Neighbors) project.