What is FAISS?
FAISS is an open-source library that searches a set of dense vectors for the vectors closest to a query vector. The name stands for Facebook AI Similarity Search. The project spells it “Faiss”.
What it does
A dense vector is a fixed-length list of numbers. A neural network can turn an image or a text into such a vector, which is called an embedding. FAISS stores many vectors in an index. Given a query vector, it returns the nearest vectors and their distances. It compares vectors with L2 (Euclidean) distance or dot product. It also supports cosine similarity, which is the dot product of normalized vectors.
Meta’s Fundamental AI Research group develops FAISS. The library is written in C++ and has Python wrappers. Some algorithms also run on a GPU.
Index types
The index type sets the balance between speed and exactness.
- IndexFlatL2 and IndexFlatIP compare the query with every vector, so the result is exact. IndexFlatIP uses the inner product. With normalized vectors it gives cosine similarity.
- IndexIVFFlat splits the vectors into nlist cells. A query searches only nprobe of them. This is faster, but the nearest neighbor can be missed if its cell is not searched.
- IndexHNSWFlat searches a graph of the vectors (a hierarchical navigable small world graph).
- IndexIVFPQ adds product quantization, which stores each vector in compressed form.
Most indexes must be trained on example vectors before use. IndexFlatL2 does not need training.
Scale
FAISS can search sets of vectors that do not fit in RAM. In the 2017 paper, the authors built a nearest neighbor graph of 1 billion vectors in under 12 hours on 4 GPUs.
Frequently Asked Questions
- Who develops FAISS and what language is it written in?
- FAISS is developed primarily at Meta's Fundamental AI Research group. It is written in C++ and has wrappers for Python and numpy. The code is MIT-licensed. Meta announced it in March 2017.
- Is FAISS a vector database?
- No. FAISS is a library that you call from your own program. Its project page describes it as a library for similarity search and clustering of dense vectors, not as a database.
- How does FAISS find cosine similarity?
- FAISS compares vectors with L2 distance or dot product. For cosine similarity, first normalize the vectors to unit length. Then use an inner product index such as IndexFlatIP. Cosine similarity is the dot product of normalized vectors.
- Does FAISS always return the exact nearest neighbor?
- No. The flat indexes (IndexFlatL2 and IndexFlatIP) search every vector and so return exact results. Partitioned indexes such as IndexIVFFlat search only some of the data. They are faster, but they lose the guarantee to find the nearest neighbor.
References
- faiss-github
- facebookresearch/faiss, README Meta Fundamental AI Research (GitHub)
- faiss-wiki-indexes
- Faiss indexes (Faiss wiki) Meta Fundamental AI Research (GitHub)
- faiss-wiki-getting-started
- Getting started (Faiss wiki) Meta Fundamental AI Research (GitHub)
- faiss-meta-2017
- Faiss: A library for efficient similarity search Engineering at Meta
- johnson-2017
- Billion-scale similarity search with GPUs (Johnson, Douze, Jegou), arXiv:1702.08734 arXiv
- douze-2024
- The Faiss library (Douze et al.), arXiv:2401.08281 arXiv
This is a reference entry. TarmacView provides drone inspection services and doesn't sell the equipment or materials described in this glossary.