baidu/puck
Puck is a high-performance ANN search engine
TL;DR
Puck is a C++ library (with Python bindings) for fast, low‑memory approximate nearest‑neighbor (ANN) search. It ships two algorithms:
- Puck – tuned for massive collections (hundreds of millions to billions of vectors) with a heavy focus on memory compression.
- Tinker – a slightly slower but higher‑recall variant that uses more RAM and works best on medium‑size datasets (10‑100 M vectors). Both support cosine, Euclidean (L2) and inner‑product similarity and integrate with the standard ANN‑benchmark suite.
What it does
- Build an index from a set of high‑dimensional vectors (stored in the
.fvecsbinary format). - Search the index for the nearest neighbours of a query vector, returning results as L2 distances (cosine and IP are internally converted).
- Provides two complementary algorithms:
- Puck – uses product‑quantization (PQ) to store vectors at ~¼ of the original size, ideal when RAM is scarce.
- Tinker – stores additional similarity‑relationship information, consuming more memory but delivering higher recall on medium‑scale data.
- Includes benchmarks against other popular ANN libraries (FAISS, NMSLIB) via the big‑ann‑benchmarks suite.
Why it matters
- Industrial‑scale retrieval often has to balance three constraints: latency, recall, and memory. Puck’s compression lets you keep billions of vectors in RAM that would otherwise be impossible to fit.
- The library shows state‑of‑the‑art performance on the NeurIPS 2021 ANN competition (top results on several 1‑billion‑vector tracks) and claims a 70 % speed/recall improvement since then.
- By offering both a ultra‑compact mode (Puck) and a higher‑accuracy mode (Tinker), users can pick the right trade‑off for their workload without switching code bases.
How to get started (quick‑start)
- Install prerequisites – Intel MKL, Python ≥ 3.6, CMake ≥ 3.21.
- Clone and build
Addgit clone https://github.com/baidu/puck.git && cd puck cmake -DCMAKE_BUILD_TYPE=Release \ -DMKLROOT=${MKLROOT} \ -DBLA_VENDOR=Intel10_64lp_seq \ -DBLA_STATIC=ON \ -B build . cd build && make && make install-DWITH_TESTING=ONto compile the GTest suite, or runpython3 setup.py installfor the Python wrapper. - Prepare data – convert your vectors to the
.fvecslittle‑endian binary format. - Train & build the index
cd build/output/build_tools cp YOUR_FEATURE_FILE puck_index/all_data.feat.bin sh script/puck_train_control.sh -t -b # trains then builds - Search
Adjustcd ../../ ln -s build_tools/puck_index . ./bin/search_client QUERY.fvecs results.txt --flagfile=conf/puck.confconf/puck.confto tune parameters such as probe count, number of probes, etc.
Who should use it
| Audience | Why it fits |
|---|---|
| Large‑scale data engineers (10⁸–10⁹ vectors) | Need sub‑GB RAM footprints; Puck’s PQ compression gives ~4× memory reduction. |
| R&D teams evaluating ANN algorithms | Comes with ready‑to‑run benchmarks and scripts that plug into the big‑ann‑benchmarks suite. |
| Python‑centric ML pipelines | Python bindings let you call the same high‑performance C++ core from NumPy‑style code. |
| Latency‑sensitive services | Designed for low‑latency search; the two‑layer inverted index and multi‑level quantization are optimized for fast look‑ups. |
Limitations / open questions
- Hardware dependence – The build process expects Intel MKL; on non‑Intel CPUs you may need to adjust BLAS settings or rebuild without MKL.
- Memory‑only index – The current implementation works with in‑memory data; there is no out‑of‑core or disk‑backed mode.
- Feature‑only documentation – The README covers build and usage, but deeper API docs (e.g., parameter meanings, Python class signatures) are sparse.
- Community size – The project appears to be maintained mainly by Baidu; external contributions may be limited.
TL;DR again
Puck = fast, memory‑efficient ANN library (C++ + Python) for huge vector collections, offering two algorithms (compact Puck vs. higher‑recall Tinker) and competitive benchmark results.
Related
- Project
- Project
- Project
- Project