GitHub - facebookresearch/faiss: A library for efficient similarity search and clustering of dense vectors.

Open original

Faiss is an open-source C++ library with Python bindings for searching and clustering large sets of dense vectors, including sets too big to fit in RAM. Its GPU implementations are built for speed, and it's developed mainly by Meta's Fundamental AI Research group.

  • Compressed-representation indexes can scale to billions of vectors in main memory on a single server, at some cost to search precision.
  • HNSW and NSG add graph-based indexing structures on top of raw vectors to make search faster.
  • GPU indexes can be swapped in as drop-in replacements for CPU ones (e.g., IndexFlatL2 to GpuIndexFlatL2), with single and multi-GPU support.
  • The library is MIT-licensed and only requires a BLAS implementation as a core dependency.

Faiss is a C++ library, with Python bindings, for finding similar vectors fast. You give it a set of vectors, each tagged with an integer ID, and it returns the nearest neighbors to a query vector under either L2 (Euclidean) distance or dot product. Cosine similarity works too, since it reduces to a dot product on normalized vectors. The library is built for collections that can run from modest sizes up to ones too large for RAM. It's developed mainly by Meta's Fundamental AI Research group, and the core dependency is just a BLAS implementation. GPU support via CUDA or AMD ROCm is optional, and NVIDIA's cuVS backend can be enabled as well. Precompiled builds are available through Anaconda as faiss-cpu, faiss-gpu, and faiss-gpu-cuvs, and the build uses cmake. The real content is in the index types, because each one picks a point on a trade-off curve between search speed, recall, memory per vector, training time, add time, and whether it needs unsupervised training data. Exact search is the baseline. Binary vectors and compact quantization codes store only compressed representations and throw away the originals. That costs some precision but lets a single server hold billions of vectors in main memory. Graph-based methods like HNSW and NSG keep the raw vectors and layer an indexing structure on top to speed up queries. The GPU path is a drop-in swap in many cases: replace IndexFlatL2 with GpuIndexFlatL2 and transfers happen automatically, though you'll get better throughput if inputs and outputs stay on the GPU. Single and multi-GPU setups are both supported. The project claims, as of March 2017, the fastest exact and approximate nearest-neighbor search for high-dimensional vectors, the fastest Lloyd's k-means, and the fastest small k-selection it knew of. That's a dated claim, so treat it as historical rather than current. For anyone using it seriously, the practical entry points are the wiki (tutorial, FAQ, troubleshooting), the per-class doxygen docs, and the benchmark READMEs tied to the Polysemous codes, Billion-scale GPU search, and Link and code papers. The 2024 paper "The Faiss library" (arXiv 2401.08281) is the citation to use for the library as a whole, with the 2019 IEEE paper for GPU work. The main authors are Hervé Jégou, who started the project, Matthijs Douze on most of the CPU side, Jeff Johnson on the GPU code, and several others on binary indexes, NSG, additive quantization, SIMD optimizations, and the build and benchmarking tooling. Questions go to the GitHub Discussions board, bugs to the Issues tab, and the code is MIT-licensed.

Ask about this article