Skip to content

Search: SQ8 compression and training threshold for HNSW vector fields (Redis 8.12) - #583

Draft
mgravell wants to merge 2 commits into
masterfrom
marc/hnsw-sq8
Draft

mgravell wants to merge 2 commits into
masterfrom
marc/hnsw-sq8

Conversation

@mgravell

@mgravell mgravell commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Client support for RediSearch MOD-14958 (RediSearch/RediSearch#11330, merged 2026-09-22; VectorSimilarity MOD-14956/7/8/60): COMPRESSION SQ8 and TRAINING_THRESHOLD on HNSW vector fields.

What the server does

  • COMPRESSION SQ8: 8-bit scalar quantization of stored vectors. HNSW only; FLOAT32/FLOAT16 with L2/IP/COSINE only.
  • TRAINING_THRESHOLD n: vectors stay in the flat tier until n have arrived, then a mean is learned and they migrate into the compressed graph; searchable throughout. Default 10240, max 102400, explicit 0 = no training. Only valid with COMPRESSION.
  • FT.INFO attributes gain compression and training_threshold (absent on uncompressed fields). Disk/Flex indexes reject both. Schema encoding v28.

What this PR adds

  • HnswVectorField.CompressionAlgorithm and .TrainingThreshold, emitted after the graph parameters when set.
  • AddHnswVectorField(..., compressionAlgorithm:, trainingThreshold:) as optional parameters appended after missingIndex, so existing positional callers compile unchanged. (Binary-breaking for compiled callers of the old signature, as any optional-parameter addition is; flagged for review.)
  • VectorCompressionAlgorithm.SQ8. The enum stays shared across algorithms; the COMPRESSION token mapping is now one helper used by both HNSW and SVS-VAMANA.
  • No client-side validation of type/metric/threshold combinations. The server owns the rules and its errors are clear; tests pin that they surface as RedisServerException:
    • COMPRESSION is only supported for FLOAT32 and FLOAT16 vector types
    • TRAINING_THRESHOLD is irrelevant when compression was not requested
  • FT.INFO: nothing to do; InfoResult.Attributes is untyped per field and the new keys flow through.
  • CI: Redis 8.12 added to both matrices (PR and nightly) via tests/dockers/.env.v8.12 pinned to redislabs/client-libs-test:8.12-m02-int. Same change as 8.12 CMS: support CELL_SIZE, fix CMS.INFO field parsing, cover negative INCRBY #562; whichever merges second is a no-op there.
new Schema().AddHnswVectorField("v", VectorType.FLOAT16, 768, VectorDistanceMetric.CosineDistance,
    compressionAlgorithm: VectorCompressionAlgorithm.SQ8, trainingThreshold: 2048);
// FT.CREATE idx SCHEMA v VECTOR HNSW 10 DIM 768 TYPE FLOAT16 DISTANCE_METRIC COSINE COMPRESSION SQ8 TRAINING_THRESHOLD 2048

Tests

  • TestIndexingCreation_Hnsw_Sq8: argument rendering, with and without threshold.
  • TestCreate_Hnsw_Sq8 (8.12+, standalone + cluster): create, FT.INFO round trip including the server default of 10240 and the absence of both keys on an uncompressed field, KNN below the training threshold.
  • TestCreate_Hnsw_Sq8_ServerRejectsInvalidCombinations (8.12+): the two server errors above, plus an SVS-only compression value on HNSW.

Run locally against redislabs/client-libs-test:8.12-m02-int (reports redis_version:255.255.255), standalone and cluster, RESP2 and RESP3: 75/75 in the Search creation set. Library builds with 0 warnings on all TFMs. With the matrix change, the 8.12-gated tests now run in CI too.

Not done, deliberately

  • No GlobalSQ8 for SVS-VAMANA (its scalar option); separate token, separate ticket if wanted.
  • No typed FT.INFO surface for the new keys.

… (Redis 8.12)

RediSearch MOD-14958 adds `COMPRESSION SQ8` and `TRAINING_THRESHOLD` to
HNSW vector fields: 8-bit scalar quantization of the stored vectors for
FLOAT32/FLOAT16 with L2, IP or cosine, with an optional mean learned from
the first N vectors (server default 10240, maximum 102400, 0 = no
training) while they stay searchable in the flat tier.

HnswVectorField gains CompressionAlgorithm and TrainingThreshold, emitted
after the graph parameters when set, and AddHnswVectorField gains the
matching optional parameters (appended, so positional callers are
unaffected at the source level). VectorCompressionAlgorithm gains SQ8;
the token mapping is now shared with the SVS-VAMANA field.

No client-side validation of type/metric/threshold combinations: the
server owns those rules and reports them clearly ("COMPRESSION is only
supported for FLOAT32 and FLOAT16 vector types", "TRAINING_THRESHOLD is
irrelevant when compression was not requested"), and the tests pin that
the errors surface as RedisServerException. FT.INFO's new `compression`
and `training_threshold` attribute keys flow through the existing
untyped Attributes dictionaries.

Tests are gated to 8.12.0 and were run against the 8.12-m02-int image,
standalone and cluster, RESP2 and RESP3.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant