Guide · Open source
How to use Faiss: install, build an index and search vectors
Updated · written with AI from the project's own documentation and checked against our catalogue data
Faiss is an open-source library from Meta for finding the vectors in a collection that are most similar to a query vector, such as embeddings of text or images. It is written in C++ with Python and numpy wrappers. This guide explains what Faiss does, how to install it, how its index types trade off speed, memory and quality, and when a different tool is a better fit.
Quick start
- 1Confirm you need a similarity search library. Faiss suits embedding search over large collections. If your dataset is small, a simple brute-force search in another tool may be enough.
- 2Install the Python package. Use Anaconda to install a precompiled build such as faiss-cpu, or faiss-gpu if you have a supported GPU and CUDA or ROCm.
- 3Prepare your vectors. Represent each item as a dense vector with an integer ID. Decide whether you will compare with L2 distance or dot product, or cosine similarity via normalized vectors.
- 4Pick an index type. Start with an exact baseline index, then try compressed or graph-based indexes if memory or speed becomes a problem.
- 5Add vectors and search. Add your vectors to the index and run a search with a query vector to get the nearest matches.
- 6Tune and evaluate. Use Faiss's evaluation and parameter tuning tools to balance search time, quality and memory for your data.
What Faiss does and who it is for
Faiss is a library for efficient similarity search and clustering of dense vectors. It assumes each item is represented as a vector and identified by an integer. Similar vectors are those with the lowest L2 (Euclidean) distance or the highest dot product to the query. Cosine similarity is also supported, since it is a dot product on normalized vectors.
Faiss is a library, not a finished application. It has no user interface and does not handle storage, filtering or updates for you. It is best suited to developers building semantic search or recommendation features, teams with very large vector collections, Python users who want numpy-compatible search, and researchers comparing approximate nearest neighbor methods.
Install Faiss with Anaconda or build it from source
Faiss ships precompiled libraries for Anaconda in Python. The source README lists faiss-cpu, faiss-gpu and faiss-gpu-cuvs packages hosted on anaconda.org under the pytorch channel. The only required dependency is a BLAS implementation. GPU support is optional and uses CUDA or AMD ROCm.
To build from source, you need CMake. The README points to INSTALL.md for the full build steps, so check that file for exact instructions for your platform.
- Precompiled Python packages: use Anaconda (faiss-cpu, faiss-gpu or faiss-gpu-cuvs).
- Required dependency: a BLAS implementation.
- Building from source: CMake, following INSTALL.md.
- Optional: CUDA or AMD ROCm for GPU support; the Python interface is also optional.
git clone https://github.com/facebookresearch/faiss.gitChoose an index type for your data
Faiss is built around an index type that stores a set of vectors and provides a search function. Some index types are simple baselines, such as exact search. Others trade accuracy for speed and memory. The README describes these trade-offs: search time, search quality, memory used per vector, training time, adding time, and whether unsupervised training needs external data.
Compressed methods based on binary vectors and quantization codes keep only a compressed form of the vectors, which can scale to billions of vectors in main memory on one server but usually gives less precise results. Graph-based methods such as HNSW and NSG add an indexing structure on top of the raw vectors to make search faster.
- Exact search: a baseline for checking accuracy on small data.
- Compressed indexes: lower memory use, less precise results.
- Graph indexes (HNSW, NSG): faster approximate search on top of raw vectors.
Use the GPU when you have one
GPU indexes can be a drop-in replacement for CPU indexes. The README gives the example of replacing IndexFlatL2 with GpuIndexFlatL2. Copies to and from GPU memory are handled automatically, but results are faster when both input and output stay on the GPU. Single and multi-GPU use are both supported.
Where to find documentation and get help
The full documentation is on the project wiki, which includes a getting-started tutorial, a FAQ and a troubleshooting section. Per-class API details are in the doxygen documentation at faiss.ai. For public questions, use the GitHub discussions page, and report bugs through the issues page.
- Wiki: github.com/facebookresearch/faiss/wiki (tutorial, FAQ, troubleshooting).
- API reference: faiss.ai.
- Questions: github.com/facebookresearch/faiss/discussions.
- Bugs: github.com/facebookresearch/faiss/issues.
What people use it for
- Semantic text search over sentence embeddings.
- Image similarity search over visual embeddings.
- Recommendation features that find items with similar vectors.
- Searching billion-scale vector collections on a single server with compressed indexes.
- Benchmarking approximate nearest neighbor methods for research.
Frequently asked questions
Is Faiss free to use?
Yes. Faiss is MIT-licensed, according to its README and LICENSE file. You can read the LICENSE file in the repository's top-level directory for the full terms.
What do I need to install Faiss?
The only required dependency for the library is a BLAS implementation. Anaconda is needed for the precompiled Python packages, and CMake is needed if you build from source. GPU support is optional and needs CUDA or AMD ROCm.
How do I install Faiss with Anaconda?
The README links to precompiled packages on anaconda.org: faiss-cpu, faiss-gpu and faiss-gpu-cuvs under the pytorch channel. Choose the CPU package unless you have a supported GPU. Check the README and INSTALL.md for the exact install command.
Can Faiss run on a GPU?
Yes. Some of the most useful algorithms are implemented on the GPU, and GPU indexes can replace CPU indexes, for example GpuIndexFlatL2 in place of IndexFlatL2. Both single and multi-GPU usage is supported.
Does Faiss handle datasets that do not fit in RAM?
The README says Faiss contains algorithms that search sets of vectors of any size, up to ones that may not fit in RAM. Compressed methods can scale to billions of vectors in main memory on a single server.
How does Faiss compare with Annoy, hnswlib, ScaNN or Milvus?
The README does not compare Faiss with these projects, so this page cannot make a benchmark claim. Faiss is a library focused on search and clustering, while Milvus is a vector database. Test candidates on your own data before choosing.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
Use Faiss if you are a developer or researcher who needs fast, memory-aware similarity search over dense vectors and is comfortable working with a library in Python or C++. Pick a different tool if you want a finished search app with a user interface, or a managed database that handles storage, filtering and updates, or if your dataset is small enough for a simple brute-force search.
Install options & downloads