$ show facebookresearch/faiss
FAISS (Facebook AI Similarity Search) is a high-performance library for efficient similarity search and clustering of dense vectors. It serves as the de facto standard library for approximate nearest neighbor (ANN) search in production environments, supporting hardware-accelerated (CPU with SIMD, GPU via CUDA/Metal) and research-grade algorithms. The codebase implements dozens of index types (flat, IVF, PQ, SQ, HNSW, NSG, RaBitQ, additive quantizers, binary, etc.), each with multiple encoding and scanning strategies. The architecture is layered: a core C++ library with extensible index and quantizer abstractions, a full C API, Python bindings via SWIG, and optional GPU or Intel SVS backends. Key entry points include the string-based index factory, training/search methods, and serialization utilities. The library is designed for both offline indexing and real-time search, with extensive auto-tuning and benchmark infrastructure.
The LLM identified 5 files worth highlighting for reuse:
Provides a compile-time and runtime SIMD dispatch framework that selects the best available instruction set (AVX2, AVX512, NEON, SVE, RVV) to execute a lambda. The `with_selected_simd_levels` function enables writing performance-critical code once and instantiating it per ISA via template specializations. This pattern is reusable in any C++ library that needs portable SIMD optimization without sacrificing peak performance.
Abstract base for packing/unpacking fixed-size code arrays into dense byte streams, used for efficient storage and SIMD batch processing. Concrete implementations exist for flat codes, PQ, RaBitQ, and fast-scan formats. The design isolates code format logic from index storage, making it straightforward to add new encoding schemes without altering the rest of the inverted list or scanning pipeline.
Defines the interface for inverted list storage (adding, reading, updating vectors and codes). Implementations include array-backed, on-disk (mmap), block-compressed, and RocksDB-backed variants, plus concatenation and dispatching wrappers. The registration mechanism (InvertedListsIOHook) allows custom storage engines to be loaded transparently during index deserialization, making the storage layer fully pluggable.
Implements automatic parameter space exploration for index configurations. The `ParameterSpace` class encodes ranges and per-index constraints; `AutoTuneCriterion` quantifies recall vs. speed; `OperatingPoints` records the Pareto frontier of trade-offs. This framework is independent of any specific index type and can be reused to tune any configurable algorithm with per-point cost and quality metrics.
Hierarchy of ID selectors for filtering search results: range, array, batch, bitmap, translated, and logical compositions (AND, OR, XOR, NOT). The selector is passed to the inverted list scanner to skip unwanted vectors early. The composition pattern (e.g., IDSelectorAnd, IDSelectorNot) allows building complex filters dynamically, reusable in any vector search system that needs predicate-based filtering.