Skip to content

Quantization

Quantization stores vectors as compressed codes and calculates candidate distances from those codes. Scalar quantization (SQ) stores one code per coordinate. Product quantization (PQ) stores one code per subvector. Quantized HNSW and Vamana can recalculate distances from the original vectors for selected candidates.

Quantization is available only in AkasicDB Enterprise Edition and is not supported in Community Edition.

AkasicDB supports the SQ method scalar, the Vamana-specific SQ methods minmax and projected_minmax8, and the PQ method product.

Supported Indexes

Index SQ PQ
Flat scalar product
IVF scalar product
HNSW scalar product
Vamana L2 scalar, minmax, projected_minmax8 product
DiskANN static search - PQ through search_pq_chunks

Flat, IVF, and HNSW support scalar and product for dense vector and vecf16 values. Vamana supports only L2 distance. Vamana projected_minmax8 accepts vector values with 161 to 65,535 dimensions.

DiskANN static search configures the number of PQ chunks with indexing.diskann.search_pq_chunks. See DiskANN for primary-index types and quantization limitations.

Quantization Methods

Method Type Encoding Supported indexes Settings and constraints
scalar SQ Derives a range for each coordinate from the training vectors and encodes each coordinate at a fixed width Flat, IVF, HNSW, Vamana Dense vector or vecf16; bits=1, 2, 4, 8
minmax SQ Uses each vector's minimum and maximum as its range and encodes the original coordinates at 4 bits Vamana L2 vector or vecf16; bits=4
projected_minmax8 SQ Projects to 160 dimensions with principal component analysis (PCA), then encodes each projected coordinate at 8 bits using a per-vector range Vamana L2 vector only; 161–65,535 dimensions; no method option
product PQ Divides a vector into subvectors of ratio dimensions and encodes each subvector with a centroid code Flat, IVF, HNSW, Vamana Dense vector or vecf16; bits=1, 2, 4, 8; ratio=1–64

scalar, minmax, and product have no method-specific dimension lower bound. The general dense-vector range of 1–65,535 dimensions applies.

If quantization is not specified, AkasicDB creates a Plain index. For supported vector types and dimensions, the recommended HNSW and Vamana profiles are as follows.

Index SQ profile PQ profile
HNSW scalar, SQ4 product, PQ8, ratio=4
Vamana L2 projected_minmax8 product, PQ8, ratio=6

The recommended Vamana SQ profile applies to vector values with 161–65,535 dimensions.

Select the quantization method explicitly with its subtable. To use the recommended Vamana SQ profile, specify the projected_minmax8 subtable. Vamana scalar and minmax are not converted to projected_minmax8. A supported explicit bits or ratio value overrides the index default.

Scalar Quantization

scalar uses 1, 2, 4, or 8 bits per dimension. When bits is omitted, HNSW uses 4 bits; Flat, IVF, and Vamana use 8 bits.

CREATE INDEX items_embedding_hnsw_sq_idx
  ON items
  USING vectoron (embedding vector_l2_ops)
  WITH (options = $$
    [indexing.hnsw]
    m = 12
    ef_construction = 300

    [indexing.hnsw.quantization.scalar]
  $$);

This HNSW index uses the SQ4 default. Specify bits to use another bit width.

Vamana SQ

Vamana L2 also supports two per-vector SQ methods. minmax derives its range from the original vector; projected_minmax8 derives its range after PCA projection.

The two methods use different stored representations and search paths. Rebuild the index to change the method.

MinMax SQ

minmax determines the quantization range from each vector's minimum and maximum values. It supports only 4 bits.

CREATE INDEX items_embedding_vamana_minmax_idx
  ON items
  USING vectoron (embedding vector_l2_ops)
  WITH (options = $$
    [indexing.vamana]

    [indexing.vamana.quantization.minmax]
    bits = 4
  $$);

ProjectedMinMax8 SQ

projected_minmax8 combines PCA projection with per-vector 8-bit MinMax quantization for Vamana SQ. During index creation, it trains a PCA model from sampled vectors and projects each vector to 160 dimensions. During search, it projects the query with the same model and uses the compressed codes to find candidates. By default, it recalculates the original 32-bit floating-point (FP32) distance for selected candidates.

projected_minmax8 has no tuning options.

CREATE TABLE image_features (
  id bigserial PRIMARY KEY,
  embedding vector(960) NOT NULL
);

CREATE INDEX image_features_vamana_projected_idx
  ON image_features
  USING vectoron (embedding vector_l2_ops)
  WITH (options = $$
    [indexing.vamana]

    [indexing.vamana.quantization.projected_minmax8]
  $$);

Product Quantization

Product quantization divides a vector into subvectors of ratio dimensions. The final subvector may contain fewer than ratio dimensions.

Index Default ratio Default bits
Flat, IVF 1 8
HNSW 4 8
Vamana 6 8

The ratio range is 1–64. Valid bits values are 1, 2, 4, and 8. Explicit values override the index defaults.

CREATE INDEX items_embedding_hnsw_pq_idx
  ON items
  USING vectoron (embedding vector_l2_ops)
  WITH (options = $$
    [indexing.hnsw]
    m = 12
    ef_construction = 300

    [indexing.hnsw.quantization.product]
  $$);

This HNSW index uses the PQ8 ratio=4 default.

Quantized Search Settings

These parameters control single instruction, multiple data (SIMD) quantized distance calculation for each index.

Index Parameter Default
Flat vectoron.flat_quantized_simd off
IVF vectoron.ivf_quantized_simd off
HNSW vectoron.hnsw_quantized_simd on
Vamana vectoron.vamana_quantized_simd on

When a parameter is on, supported CPUs and vector dimensions use SIMD. Unsupported cases fall back to non-SIMD calculation without rebuilding the index.

SQ encoding handles tail dimensions that do not fill a packed word. PQ handles a final subvector shorter than ratio. If no specialized SIMD kernel supports the selected dimension or PQ ratio, search uses the generic scorer.

Quantized HNSW and Vamana use exact refinement by default.

Parameter Default Description
vectoron.hnsw_refine on Calculates original distances for candidates popped from the HNSW bottom-layer queue.
vectoron.vamana_refine on Calculates original distances for candidates retained by Vamana.
vectoron.hnsw_early_filtering off Experimental setting that uses the current result bound to reject candidates early in the HNSW bottom layer.

When refinement is disabled, the compressed distance determines the final result.