liveBook · Manning

Product quantization

As explained in Natural Language Processing in Action, Second Edition

Product quantization is a vector-compression technique that splits a vector into subvectors and quantizes each subvector separately.

Product quantization compresses a high-dimensional vector by splitting it into smaller subvectors, then quantizing each subvector separately with clustering. This reduces memory use and can accelerate nearest-neighbor search while preserving important information. section 10.3.6

Why it matters in semantic search:

  • Integer-based indexing can use less memory and run substantially faster than floating-point computation. section 10.3.6
  • Splitting long document vectors into separately quantized subvectors improves compression while retaining subtle signal needed by semantic, plagiarism, and LLM-detector searches. section 10.3.6
  • Composite designs such as IVFPQ and HNSW plus PQ combine product quantization with approximate nearest-neighbor indexing. section 10.3.6

From quantized floats to product quantization

A simple NumPy experiment scales decimal values into integers and rescales them afterward. Product quantization applies the same broad idea to multiple subvectors, using clustering rather than one crude global conversion. section 10.3.6

Listing 10.14 Quantizing numpy floats
>>> import numpy as np
>>> v = np.array([1.1, 2.22, 3.333, 4.4444, 5.55555])
>>> type(v[0])
numpy.float64
>>> (v * 1_000_000).astype(np.int32)
array([1100000, 2220000, 3333000, 4444400, 5555550], dtype=int32)
>>> v = (v * 1_000_000).astype(np.int32)       #1
>>> v = (v + v) // 2
>>> v / 1_000_000
array([1.1    , 2.22   , 3.333  , 4.4444 , 5.55555])    #2

Inspect the integer conversion and rescaling steps behind the basic quantization intuition. section 10.3.6

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains subvector splitting and clustering, but defers package-level implementation details and pipeline configuration.
Examples
Uses NumPy integer conversion, document vectors, IVFPQ, and HNSW plus PQ as concrete illustrations.
What you can do after
Build it into semantic-search indexes while balancing compression, latency, throughput, and resource constraints.
How it connects
Connects product quantization with semantic search, clustering, approximate nearest neighbors, IVFPQ, HNSW, and composite indexes.

Also explained in

Compare how 3 books explain product quantization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.