How facebookresearch/faiss works
Faiss is a C++ similarity-search and clustering library with Python and C interfaces, CPU indexes, and optional GPU indexes. The main workflow is to create or train an index, add identified vectors, then search with L2 or dot-product similarity; index choice trades search time, quality, memory, and training/addition cost. The graph also shows quantization, inverted-list storage, wrappers, and distributed search. Some connections are documented in the README; distributed relationships follow the shown demo and server excerpts, while unsampled implementation details are omitted.
Main entry points: Index.cpp Index API · IndexIVF.cpp IVF Search · distributed_query_demo.py Distributed Query Demo · search_server.py Distributed Search Server
Components 26
Indexing and Search
- Index API
faiss/Index.cpp - Index Factory
faiss/index_factory.cpp - Exact Flat Search
faiss/IndexFlat.cpp - IVF Search
faiss/IndexIVF.cpp - Graph Indexes
faiss/IndexHNSW.cpp - Binary Indexes
faiss/IndexBinary.cpp - GPU Indexes
faiss/gpu/GpuIndex.h
Training and Compression
- Clustering
faiss/Clustering.cpp - Product Quantization
faiss/IndexPQ.cpp - Scalar Quantization
faiss/IndexScalarQuantizer.cpp - E-means Quantizers
contrib/e_means/quantizer.py - Triton Assignment
contrib/e_means/triton_assignment.py - Benchmark Index Framework
benchs/bench_fw/index.py - Benchmark Descriptors
benchs/bench_fw/descriptors.py - E-means Paper Runs
benchs/e_means/paper_bench.py - Paper Datasets
benchs/e_means/paper_data.py - Paper Experiment Runner
benchs/e_means/paper_xb.py
Index Storage and IO
- Inverted Lists
faiss/invlists/InvertedLists.cpp - On-disk Lists
faiss/invlists/OnDiskInvertedLists.cpp
Language Interfaces
- Python Wrappers
faiss/python/class_wrappers.py - C API
c_api/IndexIVF_c.h
Distributed Search
- RPC Transport
contrib/rpc.py - Distributed Search Server
benchs/distributed_ondisk/search_server.py - Combined IVF Index
benchs/distributed_ondisk/combined_index.py - Distributed Query Demo
benchs/distributed_ondisk/distributed_query_demo.py
Other components
- Application
Connections 23
- Application → Index API: adds and searches
README.md - Index Factory → Index API: creates indexes
README.md - Index API → Exact Flat Search: supports exact search
README.md - Index API → IVF Search: supports approximate search
README.md - Index API → Graph Indexes: supports graph search
README.md - Index API → Binary Indexes: supports binary search
README.md - Clustering → IVF Search: trains quantizers
- Product Quantization → IVF Search: compresses vectors
- Scalar Quantization → IVF Search: compresses vectors
- IVF Search → Inverted Lists: stores vectors
- On-disk Lists → Inverted Lists: implements storage
- E-means Quantizers → Triton Assignment: supports assignment
contrib/e_means/triton_assignment.py - Python Wrappers → Index API: wraps indexes
README.md - C API → Index API: exposes index API
c_api/IndexIVF_c.h - GPU Indexes → Index API: provides GPU alternative
README.md - Benchmark Descriptors → Benchmark Index Framework: supplies descriptors
benchs/bench_fw/descriptors.py - E-means Paper Runs → Paper Datasets: loads datasets
benchs/e_means/paper_bench.py - E-means Paper Runs → Paper Experiment Runner: runs experiments
benchs/e_means/paper_bench.py - Distributed Query Demo → RPC Transport: connects clients
benchs/distributed_ondisk/distributed_query_demo.py - Distributed Query Demo → Combined IVF Index: loads local index
benchs/distributed_ondisk/distributed_query_demo.py - Distributed Query Demo → Distributed Search Server: builds split search
benchs/distributed_ondisk/distributed_query_demo.py - Distributed Search Server → RPC Transport: serves requests
benchs/distributed_ondisk/search_server.py - Distributed Search Server → Combined IVF Index: uses combined index
benchs/distributed_ondisk/search_server.py