'index_factory' in FAISS is honestly one of the cleanest index construction utilities I've seen for vector search systems.
It lets you build complex composite indexes using a single string description instead of manually wiring every component together.
These two snippets below are functionally doing the same thing:
d = wb.shape[1]
nlist = 256
m = 32
nbits = 8
opq = faiss.OPQMatrix(d, m)
vecs = faiss.IndexFlatL2(d)
sub_index = faiss.IndexIVFPQ(vecs, d, nlist, m, nbits)
q = faiss.IndexPreTransform(opq, sub_index)
index = faiss.IndexRefineFlat(q)
index.train(wb[:50000])
index.add(wb[:50000])
And this entire pipeline can be compressed into:
index_f = faiss.index_factory(d, "OPQ32,IVF256,PQ32,RFlat")
index_f.train(wb[:50000])
index_f.add(wb[:50000])
Absolutely wild abstraction. Once you understand OPQ, IVF, PQ, and refinement stages individually, this feels incredibly elegant.