skip to content

In a Redis vector set, what do VADD's Q8, BIN and NOQUANT options trade, and what does REDUCE add on top?

level: middleimportance: should knowfreq 20%

answer

  1. bytes per component, then recall
  2. Q8 is already the default
  3. the graph does not shrink
  4. every later VADD repeats the flags
  5. REDUCE sits right before the vector

basics

~20 s

Quantization trades recall for memory and speed: Q8, the default, stores one byte per component, BIN one bit, and NOQUANT a full float. REDUCE also cuts the component count by projection. All are fixed when the key is created.

solid answer

~40 s

`Q8`, the default, stores each component as a signed byte, four times smaller than a float, with a small recall loss and faster search. `BIN` keeps one bit per component, 32 times smaller and fastest, with a real recall loss. `NOQUANT` keeps 32-bit floats: best precision, slowest, most memory. `REDUCE dim` shrinks the component count by projection before the vector is stored, also at a recall cost. Those ratios apply to the vector only: graph links, per-node bookkeeping and strings stay, so at 300 dimensions the whole key shrinks far less. Every choice is fixed at creation, and on 8.10 later `VADD` calls must repeat them or get an error, for instance `ERR asked quantization mismatch with existing vector set`. Changing one means rebuilding into a new key.

code

plaintext · 6 lines
plaintext
> VADD emb:bin VALUES 3 0.1 0.2 0.3 a BIN
(integer) 1
> VADD emb:bin VALUES 3 0.1 0.2 0.4 b
(error) ERR asked quantization mismatch with existing vector set
> VADD emb:bin VALUES 3 0.1 0.2 0.4 b BIN
(integer) 1

go deeper

for a junior

Remember the three options and their sizes: a float, a byte or a bit per component, with the byte form as the default.

for a middle

Explain why the key shrinks less than the vector: links, per-node counters and strings stay, and show the mismatch error that a forgotten flag produces on a later VADD.

for a senior

Measure instead of quoting ratios: compare VSIM against TRUTH on your own embeddings, and read MEMORY USAGE, since recall loss varies widely across embedding models.

for a principal

Treat the choice as a schema decision. It cannot be changed in place, so keep the source embeddings outside Redis so a rebuild stays possible.

## What quantization means here **Quantization** stores a vector at lower precision than the 32-bit floats you send. In a Redis vector set it is chosen on the first `VADD` for a key, and it applies to every element from then on. | `VADD` option | Stored per component | A 300-dimension vector | What the docs report | |---|---|---|---| | `NOQUANT` | 4-byte float | 1,200 bytes | Best precision, slowest, most memory | | `Q8` (default) | 1 signed byte | 300 bytes | High recall, around twice as fast or better | | `BIN` | 1 bit | 40 bytes, rounded up to 64-bit words | Fastest, lower recall | **Recall** is the share of true nearest neighbours a search actually returns. With `BIN`, the distance is a normalized Hamming distance, the count of differing bits scaled to the range 0 to 2 so that it stays comparable in meaning to a cosine distance. The practical rule from the docs is to use `Q8` unless the use case demands either maximum precision or maximum savings. A common wrong assumption is that vectors stay at full precision until you opt in. They do not: `Q8` is what you get if you say nothing. ## Why the whole key shrinks much less The 4x and 32x figures describe the vector alone. The module README's own test on 3 million elements with 300 dimensions and short JSON attributes shows what happens to the key: | Key | `MEMORY USAGE` | Per element | |---|---|---| | `Q8` | 3,107,002,888 bytes | about 1,036 bytes | | `REDUCE 100` with `Q8` | 2,507,122,888 bytes | about 836 bytes | | `BIN` | 2,327,002,888 bytes | about 776 bytes | Only 300 of those 1,036 bytes are the vector. The rest does not respond to quantization: - **Graph links:** on average `M*2 + M*0.33` pointers of 8 bytes each, about 298 bytes at the default `M` of 16. - **Per-node bookkeeping:** `hnsw.h` keeps a visited counter for each of 32 thread slots, 256 bytes per node. - **Strings:** the element name and any JSON attributes. So moving from `Q8` to `BIN` here saves about 25 percent, not 8x. The picture changes with size: at 1,536 dimensions the vector dominates and quantization saves far more. Lowering `M` shrinks the link share too, and the README notes that a higher search `EF` can buy the recall back with CPU time. ## What each option costs in recall The README measured top-10 recall against a linear scan on the same 3-million-word Word2Vec set: - `Q8`: 95.98 percent - `BIN`: 35.48 percent - `REDUCE 100`: 40.20 percent - `REDUCE 50`: 24.42 percent - `REDUCE 25`: 14.31 percent The same README gives 95 to 80 percent elsewhere as an example of the `BIN` penalty, so treat these as one extreme test and not as constants. The loss depends on your embeddings. Measure it: compare `VSIM` results against the same query with `TRUTH`, which does an exact linear scan. ## What REDUCE does `REDUCE dim` applies a **projection**, a fixed linear transform that maps each input vector to fewer components. It must come immediately before the vector: `VADD key REDUCE 100 VALUES 300 ... element`. `VDIM` then reports 100, while queries keep sending full 300-component vectors and Redis projects them with the matrix it stored. The matrix is saved in the RDB file along with the graph. The docs call this random projection. In 8.10's `vset.c` the matrix is built deterministically from a Hadamard-style sign pattern, and its comment says replicas therefore get the same weights. That disagrees with the docs' troubleshooting page, which says replicas produce different projected vectors, so trust the code for this release. Projection pays off on large vectors. The README notes that with certain embedding models `BIN` does much better than projecting by a similar factor, so test both. ## The choices are fixed at creation On every call, `VADD` starts from the defaults and compares them with the key, so a flag you omit counts as the default: 1. Create with `BIN`, and a later plain `VADD` fails with `ERR asked quantization mismatch with existing vector set`. 2. Create with `M 32`, and a later `VADD` without `M` fails with `ERR asked M value mismatch with existing vector set`. 3. Create with `REDUCE`, and a later `VADD` without it fails with a dimension mismatch. The client must therefore send the same options on every write. `VINFO` shows what a key uses, in `quant-type`, `hnsw-m`, `vector-dim` and `projection-input-dim`. To change a choice, write a new key from your original embeddings. `VEMB` returns only an approximation, so a `Q8` set cannot be promoted to `NOQUANT` by reading itself back.

  • How would you move an existing Redis vector set from `Q8` to `NOQUANT`?
    Build a new key from the original embeddings kept in your system of record, passing `NOQUANT` on every `VADD`, then point reads at it. `VEMB` will not do as a source, because a `Q8` set returns only a de-quantized approximation, so the lost precision cannot return. `VRANGE` can list the element names to re-embed, in small batches.
  • Why might raising `M` cost more than the vectors themselves?
    Each node at layer zero holds `M*2` links of 8 bytes. At `M` 64 that is 1,024 bytes per node before upper layers, more than three times a 300-byte `Q8` vector. The docs suggest going to 32 or above only when near-perfect recall is really needed, and raising `EF` at query time buys recall with CPU instead of memory.

  • BIN makes the whole vector set 32 times smaller.
  • Vectors stay at full precision unless you pass Q8.
  • NOQUANT only matters on the first VADD, so later calls can omit it.
  • REDUCE is always a better way to cut memory than BIN.
  • VEMB returns exactly what you sent, so a set can be rebuilt losslessly from itself.

Assumes Redis 8.10; the option checks and the deterministic projection matrix were read from modules/vector-sets/vset.c at 8.10.3.