---
title: "Scalar Quantisation and int8 Vector Storage in Production"
date: "2026-11-22T07:17:12+07:00"
description: "How scalar quantisation converts float32 embeddings to int8 for 4x smaller storage and faster scans, with practical accuracy safeguards."
author: "AI Assistant"
image: "https://blog.redlinesoft.net/images/post/scalar-quantization-int8-vectors.jpg"
alt: "Float values mapped onto a discrete int8 scale"
tags: ['scalar-quantization', 'int8', 'compression', 'production']
---

## Introduction

If product quantisation feels heavy-handed, **scalar quantisation (SQ)** is the simpler cousin: round each number in the vector to a smaller numeric type. Convert float32 embeddings to **int8** and you cut storage and bandwidth by 4× with a degradation profile that is easy to understand — and usually easy to defend.

## How Scalar Quantisation Works

Instead of learning codebooks (as PQ does), scalar quantisation applies a **per-dimension (or global) mapping** from floats to a discrete grid:

1. Observe the value range of each dimension (or the whole vector): `[min, max]`.
2. Divide that range into 255 intervals (for int8).
3. Map every float to the nearest integer level; store the int8.
4. At query time, either dequantise on the fly or compute distances directly in integer arithmetic.

```
q(x) = round((x − min) / (max − min) × 255)   // → 0..255
```

Variants include uniform quantisation (equal-width bins), non-uniform bins (fit a distribution), and asymmetric distance computation — where the query stays float and only the database is quantised, avoiding double error.

## SQ vs PQ

| | Scalar quantisation (int8) | Product quantisation |
|---|---|---|
| Mechanism | Per-value rounding | Subvector codebook lookup |
| Compression | 4× (float32 → int8) | 8–64× |
| Error | Small, bounded per value | Larger, structural |
| Recall impact | Typically 0.98–0.99+ | 0.90–0.97 (needs rescore) |
| Implementation | Trivial | Requires trained codebooks |
| Distance compute | Fast integer ops | Table lookups + adds |

SQ is the "almost free" compression: 4× memory for a fraction of a recall point. PQ is the aggressive one for when 4× is not enough.

## Production Considerations

- **Calibrate on real data.** Min/max per dimension from a sample of your actual corpus; outliers stretch ranges and waste levels. Percentile clipping (e.g., 1st–99th) often helps.
- **Keep a rescore path.** Store int8 in the hot index; rescore the top-100 candidates from float originals (or from a coarser store) if you need the last recall points.
- **Watch the metric.** SQ interacts better with dot product/Euclidean under asymmetric computation than with plain cosine on quantised query *and* database.
- **int8 SIMD is fast.** Modern CPUs multiply int8 pairs in wide registers; many workloads get *faster* scans despite the dequant step, because memory bandwidth — not arithmetic — is the bottleneck.
- **A/B against ground truth.** Measure recall@10 vs your float baseline before shipping; int8 regressions are usually < 1%.

## When to Use int8 SQ

- Memory is ~4× too large with float32 but PQ feels like overkill
- You want simple, explainable compression with no training step
- Latency is bandwidth-bound and you suspect smaller data will scan faster
- Combined with PQ for a two-stage design (int8 or PQ for scan, float for rescore)

## Conclusion

Scalar quantisation is the pragmatic middle ground of vector compression: divide each dimension's range into 256 levels, store bytes instead of floats, and recover almost all recall — especially with a rescore stage. For most production teams' first step below float32, int8 is the right move.

## References

- [Wikipedia: Vector quantization](https://en.wikipedia.org/wiki/Vector_quantization) (source topic cited Product quantization, which redirects here)
