SuperAPI AI Directory

faiss

A library for efficient similarity search and clustering of dense vectors

Open website

About this tool

Purpose

Faiss is a library for efficient similarity search and clustering of dense vectors. It is aimed at scenarios that require quickly finding similar vectors among a large number of vectors, such as retrieval tasks that measure similarity by L2 (Euclidean) distance or dot product. The project is mainly developed by Meta's Fundamental AI Research team.

Main capabilities

Faiss assumes that instances are represented as vectors and identified by integers, and vectors can be compared using L2 distance or dot product. Vectors similar to a query vector are those with the smallest L2 distance or the largest dot product. Since cosine similarity is equivalent to the dot product on normalized vectors, Faiss also supports that metric.

The library includes a variety of similarity search methods:

  • Some methods (such as those based on binary vectors and compact quantization codes) use only compressed representations of vectors and do not need to retain the original vectors. This usually comes at the cost of reduced accuracy, but can scale to billions of vectors in the memory of a single server.
  • Other methods (such as HNSW and NSG) add index structures on top of the original vectors to make search more efficient.

Faiss also includes auxiliary code for evaluation and parameter tuning.

Usage

Faiss is written in C++ and provides complete Python/numpy wrappers. Some of the most useful algorithms are implemented on GPU. GPU implementations can accept input from CPU or GPU memory; on a server with a GPU, a GPU index can be used as a direct replacement for a CPU index (for example, replacing IndexFlatL2 with GpuIndexFlatL2), and copying of GPU memory is handled automatically. If both input and output reside on the GPU, results will be faster. Single-GPU and multi-GPU use are supported.

Faiss provides Anaconda precompiled libraries for Python, including faiss-cpu, faiss-gpu, and faiss-gpu-cuvs. The library is mainly implemented in C++, and its only dependency is a BLAS implementation. Optional GPU support is provided through CUDA or AMD ROCm, and the Python interface is also optional. The backend GPU implementation from NVIDIA cuVS can also optionally be enabled. The project is compiled using cmake; see INSTALL.md for details.

How it works

Faiss is built around one type of index: this type stores a set of vectors and provides functions for searching using L2 and/or dot product vector comparison. Some index types are simple baselines, such as exact search. Most available index structures differ in the following trade-offs:

  • The memory used per indexed vector
  • Whether external data is needed for unsupervised training

GPU implementations provide high-speed exact and approximate (compressed-domain) nearest neighbor search for high-dimensional vectors, Lloyd's k-means, and small-k selection algorithms.

Documentation and community

Complete documentation is available on the wiki page, including tutorials, FAQ, and troubleshooting sections. The doxygen documentation provides per-class information extracted from code comments. To reproduce the results of research papers (such as Polysemous codes, Billion-scale similarity search with GPUs), refer to the benchmarks README; for Link and code: Fast indexing with graphs and compact regression codes, see the link_and_code README.

For public discussion or questions, visit GitHub Discussions; the repository also monitors the issues page for bug reports or questions.

Main authors

  • Hervé Jégou initiated the Faiss project and wrote the first implementation
  • Matthijs Douze implemented most of CPU Faiss
  • Jeff Johnson implemented all of GPU Faiss
  • Lucas Hosseini implemented binary indexes and the build system
  • Chengqi Deng implemented NSG, NNdescent, and a large amount of additive quantization code
  • Alexandr Guzhva made many optimizations: SIMD, memory allocation and layout, fast decoding kernels for vector codecs, etc.
  • Gergely Szilvasy is responsible for the build system and benchmarking framework

License

Faiss is under the MIT license; see the LICENSE file in the top-level directory for details. Copyright © Meta Platforms, Inc.aspects:

  • The memory used per indexed vector
  • Whether external data is needed for unsupervised training

GPU implementations provide high-speed exact and approximate (compressed-domain) nearest neighbor search for high-dimensional vectors, Lloyd's k-means, and small-k selection algorithms.

Documentation and community

Complete documentation is available on the wiki page, including tutorials, FAQ, and troubleshooting sections. The doxygen documentation provides per-class information extracted from code comments. To reproduce the results of research papers (such as Polysemous codes, Billion-scale similarity search with GPUs), refer to the benchmarks README; for Link and code: Fast indexing with graphs and compact regression codes, see the link_and_code README.

For public discussion or questions, visit GitHub Discussions; the repository also monitors the issues page for bug reports or questions.

Main authors

  • Hervé Jégou initiated the Faiss project and wrote the first implementation
  • Matthijs Douze implemented most of CPU Faiss
  • Jeff Johnson implemented all of GPU Faiss
  • Lucas Hosseini implemented binary indexes and the build system
  • Chengqi Deng implemented NSG, NNdescent, and a large amount of additive quantization code
  • Alexandr Guzhva made many optimizations: SIMD, memory allocation and layout, fast decoding kernels for vector codecs, etc.
  • Gergely Szilvasy is responsible for the build system and benchmarking framework

License

Faiss is under the MIT license; see the LICENSE file in the top-level directory for details. Copyright © Meta Platforms, Inc.