FAISS Index Architecture for Vector Similarity Search
FAISS index selection is a recall, memory, build-time and data-movement decision as much as a latency decision.
One million 768-dimensional float32 vectors require roughly 3 GB for the raw vectors alone. At much larger scales, “compute cosine similarity” stops being an implementation plan and becomes a memory-layout and index-architecture problem.
I use FAISS to reason about this trade-off space. In image, face and speech embedding systems, the practical question is not merely which distance function is available, but which recall loss is acceptable under a defined latency and memory budget.
Exact search as the baseline
IndexFlatL2 and flat inner-product search store vectors and scan every candidate. Construction is inexpensive, but query work grows approximately with:
O(N × d)I keep an exact index as the quality baseline before evaluating approximate methods. Otherwise a faster query result says little about how many true neighbors were lost.
IVF: reduce the candidate space
An inverted-file index assigns vectors to coarse centroids and probes only selected partitions. nlist controls partitioning and nprobe controls how much of that partitioning is searched.
Increasing nprobe generally raises recall and latency together. I therefore select it from a measured recall/latency curve rather than a fixed recipe.
Product Quantization: memory for approximation
Product Quantization replaces full vectors with compact subspace codes. This can greatly reduce RAM and improve cache behavior, but quantization error becomes part of the retrieval contract.
For that reason I compare PQ results against the exact baseline on representative data.
HNSW and graph search
HNSW can provide strong recall/latency behavior, but its graph consumes memory and takes time to construct. Build time, serialized size, reload time and update behavior matter in a service that frequently replaces embeddings.
Cosine similarity is not an index type
For normalized vectors:
cos(x,y) = x · yso cosine search can be implemented through inner product when the normalization contract is correct. Mixing normalized and non-normalized vectors silently changes ranking semantics.
GPU does not automatically win
FAISS has optimized GPU paths, but end-to-end latency can include host/device copies and batching. For small requests, transfer can dominate computation.
I therefore measure search time separately from host-to-device transfer, device-to-host transfer and queueing.
What I measure
A useful comparison records:
- Recall@k against exact search,
- median and tail latency,
- RAM and index overhead,
- build/reload time,
- update/rebuild behavior,
- CPU/GPU utilization and transfer cost.
A vector database can add persistence, filtering and distribution, but it does not remove these index-level trade-offs.
Deriving memory cost from the representation
A float32 vector of dimension d requires 4d bytes for its components. For N vectors, the uncompressed payload is approximately 4Nd bytes, excluding vector identifiers, index metadata and working memory. Flat search provides the baseline against which other structures can be measured. IVF adds coarse centroids, posting lists and identifiers; HNSW maintains neighborhood links; product quantization stores compact subvector codes and the associated codebooks.
For a product quantizer with M subquantizers and b bits per subquantizer, the compressed code payload is approximately M × b / 8 bytes per vector. With M = 16 and b = 8, the code itself occupies 16 bytes. This is the size of the compressed representation, not the total memory cost of a deployed index. IVF-PQ retains identifiers and centroid data, while graph indexes incur adjacency overhead. Query buffers, replicated shards and model embeddings outside the index may also contribute to total resident memory.
Candidate selection in IVF
An IVF index divides the vector space into nlist coarse partitions. At query time nprobe partitions are searched, and the vectors within the selected partitions become candidates. Under approximately balanced partition sizes, the expected number of scanned candidates has the scale N × nprobe / nlist. Actual work depends on partition-size skew and the location of the query; an average count does not characterize all query latencies.
Index tuning can be regarded as a constrained problem: minimize query latency subject to a minimum Recall@K, a resident-memory limit and an index-rebuild budget. Recall@K is obtained by comparing each approximate result set with the K nearest neighbors found by exhaustive search under the same distance metric. Reporting recall together with p50, p95 and p99 latency, as well as partition-size distribution, reveals a more useful operating point than reporting one average query time.
For filtered retrieval, the exact-search ground truth must be computed over documents eligible under the query filter. Selecting the global top k before applying a permission or metadata filter can return too few results even when additional eligible neighbors exist. Evaluation should retain recall@k against that eligible exact baseline alongside candidate counts, p95/p99 latency, index memory and build cost.
Graph traversal and compressed distances
HNSW builds a proximity graph and searches it by exploring promising neighbors at progressively finer levels. The number of graph links and the search breadth determine part of the memory–latency–recall balance. In product quantization, distance computation uses a compact approximation to the original vector components, reducing memory traffic while introducing quantization error. Training samples for the codebooks should represent the actual embedding distribution, since codebook quality influences nearest-neighbor ranking.
Vector normalization is part of the metric contract. For nonzero unit-normalized vectors, the squared Euclidean distance is ||x-y||² = 2 - 2(x·y), so inner-product ranking and Euclidean-distance ranking are equivalent in ordering. This equivalence must be applied consistently to stored vectors and queries; it is not a property of unnormalized vectors in general.
Index lifecycle and model-version boundaries
Index construction, insertion, deletion, persistence and reload belong to the search architecture alongside query processing. A new embedding model may define a different vector space even if its output dimension remains unchanged. Model-version migration therefore includes regenerating representations or separating incompatible index generations and validating their result distributions.
An operational comparison uses the same dataset, embedding model, query distribution, metric and hardware. It records build time, resident memory, recall, latency percentiles, throughput under concurrent queries and the cost of returning to the previous index generation. The FAISS index catalog and index-factory documentation provide the concrete construction semantics for Flat, IVF, HNSW and PQ variants.
References
- Douze et al., The Faiss Library
- Johnson, D. A. J. Billion-Scale Similarity Search with GPUs
- Meta AI, FAISS repository and wiki
- Meta AI. FAISS indexes. https://github.com/facebookresearch/faiss/wiki/Faiss-indexes