Skip to content

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

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

mgravell wants to merge 7 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-rc2. 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-rc2 (reports redis_version:8.11.241), 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.
@mgravell
mgravell marked this pull request as ready for review November 27, 2026 12:53
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T15:08:49.790708Z 5a87fa9 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3e3d53d159

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/NRedisStack/Search/Schema.cs Resolved
Adding compressionAlgorithm / trainingThreshold as optional parameters replaced the shipped
10-parameter method, which is a binary break for compiled callers. Restore it without optional
parameters, hidden and de-prioritised, forwarding to the new overload.

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