A library for efficient similarity search and clustering of dense vectors.
 
 
 
 
 
 
Go to file
Jeff Johnson 878275f915 Faiss GPU: remove d2h copy from PQ MM debugging
Summary:
If the number of dimensions per sub-quantizer is not in the specialized list, it falls back to the generalized batch GEMM implementation.

When I implemented this, I had in a d2h copy so I could look at the computed distances. I removed the debugging code but not this copy.

Prior to this, PQ16 on 1024 dims was 6x slower than PQ32. Now, it is only 1.5x slower (it is slower because there is a higher number of dims per sub-q, despite there being more sub-qs).

Reviewed By: beauby

Differential Revision: D34526043

fbshipit-source-id: de6f70f0f0b91608eb6ae2a05da2af812546e4bc
2022-02-28 15:43:33 -08:00
.circleci Add IndexNSGPQ and IndexNSGSQ (#2218) 2022-02-18 04:51:15 -08:00
.github Change default branch references from master to main. (#2029) 2021-09-01 09:26:20 -07:00
benchs contrib clustering module (#2217) 2022-02-28 14:18:47 -08:00
c_api IndexFlatCodes: a single parent for all flat codecs (#2132) 2021-12-07 01:31:07 -08:00
cmake
conda Fix packaging (#2121) 2021-12-07 13:12:30 -08:00
contrib contrib clustering module (#2217) 2022-02-28 14:18:47 -08:00
demos Add NNDescent to faiss (#1654) 2021-02-25 16:48:28 -08:00
faiss Faiss GPU: remove d2h copy from PQ MM debugging 2022-02-28 15:43:33 -08:00
misc Enable clang-format + autofix. 2021-02-25 04:46:10 -08:00
tests contrib clustering module (#2217) 2022-02-28 14:18:47 -08:00
tutorial Enable clang-format + autofix. 2021-02-25 04:46:10 -08:00
.clang-format Re-factor factory string parsing (#2134) 2021-12-07 04:35:57 -08:00
.dockerignore
.gitignore AQ fastscan (#2169) 2022-02-22 15:24:31 -08:00
CHANGELOG.md contrib clustering module (#2217) 2022-02-28 14:18:47 -08:00
CMakeLists.txt Add separate targets for libfaiss/libfaiss_avx2. (#1772) 2021-03-26 14:28:16 -07:00
CODE_OF_CONDUCT.md
CONTRIBUTING.md Change default branch references from master to main. (#2029) 2021-09-01 09:26:20 -07:00
Dockerfile
Doxyfile
INSTALL.md Change default branch references from master to main. (#2029) 2021-09-01 09:26:20 -07:00
LICENSE
README.md Refresh github README (#2219) 2022-02-14 02:01:20 -08:00

README.md

Faiss

Faiss is a library for efficient similarity search and clustering of dense vectors. It contains algorithms that search in sets of vectors of any size, up to ones that possibly do not fit in RAM. It also contains supporting code for evaluation and parameter tuning. Faiss is written in C++ with complete wrappers for Python/numpy. Some of the most useful algorithms are implemented on the GPU. It is developed primarily at Facebook AI Research.

News

See CHANGELOG.md for detailed information about latest features.

Introduction

Faiss contains several methods for similarity search. It assumes that the instances are represented as vectors and are identified by an integer, and that the vectors can be compared with L2 (Euclidean) distances or dot products. Vectors that are similar to a query vector are those that have the lowest L2 distance or the highest dot product with the query vector. It also supports cosine similarity, since this is a dot product on normalized vectors.

Some of the methods, like those based on binary vectors and compact quantization codes, solely use a compressed representation of the vectors and do not require to keep the original vectors. This generally comes at the cost of a less precise search but these methods can scale to billions of vectors in main memory on a single server. Other methods, like HNSW and NSG add an indexing structure on top of the raw vectors to make searching more efficient.

The GPU implementation can accept input from either CPU or GPU memory. On a server with GPUs, the GPU indexes can be used a drop-in replacement for the CPU indexes (e.g., replace IndexFlatL2 with GpuIndexFlatL2) and copies to/from GPU memory are handled automatically. Results will be faster however if both input and output remain resident on the GPU. Both single and multi-GPU usage is supported.

Installing

Faiss comes with precompiled libraries for Anaconda in Python, see faiss-cpu and faiss-gpu. The library is mostly implemented in C++, the only dependency is a BLAS implementation. Optional GPU support is provided via CUDA, and and the Python interface is also optional. It compiles with cmake. See INSTALL.md for details.

How Faiss works

Faiss is built around an index type that stores a set of vectors, and provides a function to search in them with L2 and/or dot product vector comparison. Some index types are simple baselines, such as exact search. Most of the available indexing structures correspond to various trade-offs with respect to

  • search time
  • search quality
  • memory used per index vector
  • training time
  • adding time
  • need for external data for unsupervised training

The optional GPU implementation provides what is likely (as of March 2017) the fastest exact and approximate (compressed-domain) nearest neighbor search implementation for high-dimensional vectors, fastest Lloyd's k-means, and fastest small k-selection algorithm known. The implementation is detailed here.

Full documentation of Faiss

The following are entry points for documentation:

Authors

The main authors of Faiss are:

Reference

Reference to cite when you use Faiss in a research paper:

@article{johnson2019billion,
  title={Billion-scale similarity search with {GPUs}},
  author={Johnson, Jeff and Douze, Matthijs and J{\'e}gou, Herv{\'e}},
  journal={IEEE Transactions on Big Data},
  volume={7},
  number={3},
  pages={535--547},
  year={2019},
  publisher={IEEE}
}

Join the Faiss community

For public discussion of Faiss or for questions, there is a Facebook group at https://www.facebook.com/groups/faissusers/

We monitor the issues page of the repository. You can report bugs, ask questions, etc.

License

Faiss is MIT-licensed.