Skip to content
Matthijs Douze edited this page Jan 16, 2020 · 34 revisions

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 (versions 2 and 3). Some of the most useful algorithms are implemented on the GPU. It is developed by Facebook AI Research.

What is similarity search?

Given a set of vectors x_i in dimension d, Faiss build a data structure in RAM from it. After the structure is constructed, when given a new vector x in dimension d it performs efficiently the operation:

i = argmin_i ||x - x_i||

where ||.|| is the Euclidean distance (L2).

If Faiss terms, the data structure is an index, an object that has an add method to add x_i vectors. Note that the x_i's are assumed to be fixed.

Computing the argmin is the search operation on the index.

This is all what Faiss is about. It can also:

  • return not just the nearest neighbor, but also the 2nd nearest, 3rd, ..., k-th nearest neighbor

  • search several vectors at a time rather than one (batch processing). For many index types, this is faster than searching one vector after another

  • trade precision for speed, ie. give an incorrect result 10% of the time with a method that's 10x faster or uses 10x less memory

  • perform maximum inner product search argmax_i <x, x_i> instead of minimum Euclidean search. There is also limited support for other distances (L1, Linf, etc.).

  • return all elements that are within a given radius of the query point (range search)

  • store the index on disk rather than in RAM.

Research foundations of Faiss

Faiss is based on years of research. Most notably it implements:

A general paper about product quantization and related methods: "A Survey of Product Quantization", Yusuke Matsui, Yusuke Uchida, Hervé Jégou, Shin’ichi Satoh, ITE transactions on MTA, 2018.

This wiki

This wiki contains high-level information about Faiss and a tutorial. Navigate it using the sidebar.

Most examples are in Python for brievity, but the C++ API is exactly the same, so the translation for one to the other is trivial most of the times.

Clone this wiki locally