Revelin7Revelin7
All work
Lab note

3x Less Memory. Same Recall Quality.

Quantizing HNSW embeddings to int8 with random rotation and two-tier reranking. At a million memories with 1536-dimension embeddings, RAM drops from 6 GB to 2 GB.

6 GB → 2 GBRAM at 1M memories

6 GB to ~2 GB
HNSW vector RAM at 1M memories, 1536 dimensions
4 bytes to 1 byte
held in RAM per dimension
< 1%
recall reduction at our quality gates
2x
candidates fetched before exact reranking

The HNSW graph has to live in RAM to be fast. At 1536 dimensions each f32 embedding is 6 KB, so a million memories cost 6 GB before counting neighbour lists or metadata. Memory was the scaling limit for large vaults, ahead of disk, CPU and network.

Per-vector int8 quantization

Each vector stored in the graph is mapped to int8 with its own affine transform. We take the vector's min and max, set scale to (max - min) / 255 and zero_point to min, and keep those two f32 values next to the int8 data. That is 8 bytes of overhead per vector.

q[i]  = clamp(round((v[i] - zero_point) / scale) - 128, -128, 127)
v'[i] = (q[i] + 128) * scale + zero_point

Rotation before quantization

Embeddings concentrate their energy in a few dimensions, and a uniform int8 grid spends precision badly on that shape. Before quantizing we apply a randomized Walsh-Hadamard rotation: flip signs with a seeded random +1/-1 vector, then run an in-place butterfly transform in O(d log d). Vectors are padded to the next power of two, so 1536 dimensions become 2048. The seed is stored per index, which makes the rotation deterministic and the index portable. The transform is orthogonal, so inner products are preserved. Queries go through the same rotation.

Two-tier search

Graph traversal uses int8 distances and returns 2k candidates for a top-k request. We then load the original f32 vectors for those candidates from the RocksDB vectors column family by memory ID, recompute exact distances, and return the top k. Quantization error can change which candidates are picked. It cannot change the final scores.

What the numbers cover

The 3x figure is for the vectors at 1536 dimensions. Neighbour lists are a fixed cost per node (32 links at layer 0, 16 above, 16 bytes each), so the whole-node saving is smaller at low dimensions. Our accounting for a 384-dimension index is 520 bytes for the rotated int8 vector against 1,536 bytes for f32, and about 1,148 bytes per node against about 2,164, a 1.9x reduction. Int8 distances are currently computed by dequantizing to f32 on the fly; a SIMD int8 dot product is not written yet. 4-bit quantization, at roughly 8x, is waiting on quality benchmarks.

Quantization is on by default for new indexes. Existing indexes pick it up on the next full reindex (hebbs index --rebuild). A deployment sized at 8 GB of RAM for 1M memories fits in 3 GB.

Date

1 April 2026

Part of

HEBBS

Source

HEBBS blog

Topics

Open the original

Related