HNSW or SQ8: Choosing an Index When Every Read Is a Request
On a local disk or in RAM, an index is judged by how few distances it computes. On object storage there’s another bill: every read is a request with its own latency, and the number of requests matters as much as the bytes. Itzma has two dense index kinds, and they differ mostly in how they spend that.
What both of them share
Both indexes work on codes of one byte per dimension, a quarter the size of
the f32 vectors they stand for. Neither is trusted for the final answer. An
index proposes rerank * top_k candidates (the default multiplier is 4),
and those are rescored against their exact vectors. The closest top_k win. So the distances in a result are exact whichever index ran, and what an
index can get wrong is recall: a true neighbour it never proposed.
An index belongs to one segment. A query asks each indexed segment for candidates, scans segments with no index and the unfolded log tail, drops anything a newer source overwrote or deleted, and merges. A damaged index is an error. The query never quietly falls back to a flat scan over it.
SQ8: read only what you probe
SQ8 stores one byte per dimension, and for segments of 100,000 rows or more
it groups the codes into about sqrt(rows) clustered partitions. A query
reads only the partitions it probes, by default about 2 * sqrt(nlist).
Each dimension keeps its own minimum and scale, and a value is decoded as min + code × scale, so the error stays within half a step.
A small SQ8 index over 2,000 2D points. A segment this small gets one
partition by default, so nlist is set to 8 to show the idea. The table shows
the original floats, the one-byte codes and what they decode to.
That keeps each query’s reads small and predictable even when nothing is cached. The cost is that it’s a clustered index, so it’s approximate unless a query probes every partition, and each query pays for several ranged reads.
HNSW: one request, then walk
HNSW is a graph over the same one-byte codes. A query fetches the segment’s whole index object in a single request, then walks the graph out of those bytes.
A small HNSW index over 2,000 2D points. The query starts at the entry point on the top layer and drops down to its nearest neighbour.
Once that object sits in a cache, a query costs no request for it at all. Cold, it costs one larger read. HNSW also takes longer to build.
So the two kinds fail differently. SQ8 is steady and a little chatty. HNSW is cheap when warm and heavy when cold, because the entry fee is the whole object. Which one is right depends on how a deployment actually reads: long-lived processes with a cache can amortize the large fetch, while short-lived ones that mostly start cold may not. Itzma’s default is HNSW, and a namespace can hold both kinds. A rebuild can switch one segment’s kind.
What was measured
Recall@10 for HNSW at 32 segments was 0.987 on SIFT1M and 0.984 on GloVe-25. SQ8 with its default settings reached 0.99 or more on both. Those are the only two datasets I’ve measured, and neither number says anything about latency over a real network. I haven’t measured that, which is also why the request-gate defaults in the library are only starting points.
The read budget
Every query attempt has a read budget, 1 GiB by default. An indexed segment
is charged only for what it actually fetches. So a namespace bigger than the
budget can still be queried once its large segments are indexed, and a query
with no index, or one that sets exact, is bounded by the budget alone. If
the index isn’t there, the budget is what stops a flat scan from running
away.
On object storage, a read has a price, so the library states it and caps it. Picking HNSW or SQ8 is then a question of which shape of cost fits the workload. Neither is faster across the board.