nanopq

Nano Product Quantization (nanopq): a vanilla implementation of Product Quantization (PQ) and Optimized Product Quantization (OPQ) written in pure python without any third party dependencies.
Installing
You can install the package via pip. This library works with Python 3.5+ on linux.
pip install nanopq
Example
import nanopq
import numpy as np
N, Nt, D = 10000, 2000, 128
X = np.random.random((N, D)).astype(np.float32)
Xt = np.random.random((Nt, D)).astype(np.float32)
query = np.random.random((D,)).astype(np.float32)
pq = nanopq.PQ(M=8)
pq.fit(Xt)
X_code = pq.encode(X)
dists = pq.dtable(query).adist(X_code)
Author
Contributors
- @Hiroshiba fixed a bug of importlib (#3)
- @calvinmccarter implemented parametric initialization for OPQ (#14)
- @de9uch1 exntended the interface to the faiss so that OPQ can be handled (#19)
- @mpskex implemented (1) initialization of clustering and (2) dot-product for computation (#24)
- @lsb fixed a typo (#26)
Reference
- H. Jegou, M. Douze, and C. Schmid, "Product Quantization for Nearest Neighbor Search", IEEE TPAMI 2011 (the original paper of PQ)
- T. Ge, K. He, Q. Ke, and J. Sun, "Optimized Product Quantization", IEEE TPAMI 2014 (the original paper of OPQ)
- Y. Matsui, Y. Uchida, H. Jegou, and S. Satoh, "A Survey of Product Quantization", ITE MTA 2018 (a survey paper of PQ)
- PQ in faiss (Faiss contains an optimized implementation of PQ. See the difference to ours here)
- Rayuela.jl (Julia implementation of several encoding algorithms including PQ and OPQ)
- PQk-means (clustering on PQ-codes. The implementation of nanopq is compatible to that of PQk-means)
- Rii (IVFPQ-based ANN algorithm using nanopq)
- Product quantization in Faiss and from scratch (Related tutorial)