Skip to content

feat(hnsw): quantization, narrow vector columns, exact prefilter, memory-sized models - #31468

Merged
XuPeng-SH merged 16 commits into
matrixorigin:mainfrom
cpegeric:hnsw_quantization
Oct 28, 2026
Merged

XuPeng-SH merged 16 commits into
matrixorigin:mainfrom
cpegeric:hnsw_quantization

Conversation

@cpegeric

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #31467

What this PR does / why we need it:

Design: docs/design/20261026-hnsw-quantization.md (status: proposed — design review requested).

Behavior

  • QUANTIZATION on HNSW: float32 / float16 / bf16 / float64 / int8 / uint8 (int8/uint8 L2 only, one trained range per index; no widening; fixed at CREATE, REINDEX keeps it).
  • vecf16 / vecbf16 / vecint8 / vecuint8 columns are indexed, synced and searched in their own element type; a vector already in the stored type goes to usearch as is.
  • The int8/uint8 range is kept in a key/value hidden table hnsw_dict (only int8/uint8 indexes have it; existing indexes need no upgrade).
  • max_index_capacity default 0: each model holds what fits 75% of available host memory (dimension, stored width, M), as IVF-PQ; build and sync use the index option, then the session variable, then the estimate. Models reserve only the rows they receive.
  • hnsw_create(params, cfg) counts, samples and streams the source itself (no CROSS APPLY).
  • Exact prefiltered search when the qualifying row count ≤ hnsw_prefilter_exact_threshold (default 5000, from a measured exact-vs-walk crossover).

Validation

  • Unit tests for every changed package (catalog, frontend, iscp, table_function, sql/plan, vectorindex/..., bootstrap); BVT vector_hnsw_quantization 179/179 and all existing HNSW BVT files pass.
  • wiki_all 1M (768-d, M=100, ef_construction=400, ef_search=200, k=20, 200 queries x 8 concurrency, arm64 Mac); every build is a single model:
f32 float16 bf16 int8
build 337.5 s 869.5 s 239.6 s 148.3 s
recall@20 0.9965 0.9935 0.9922 0.9637
warm QPS 1201 830 1318 1292
warm p50 5.89 ms 8.55 ms 5.11 ms 5.52 ms

Limits

  • Uses the usearch fork (cpegeric/usearch, filtered search exact flag) until Add: Exact filtered search in C and Go unum-cloud/USearch#828 merges.
  • A single large model is rewritten whole by each ISCP sync; CDC tail + idxcron merge is the follow-up PR.
  • float16 is slow on this arm64 build (usearch without SimSIMD); bf16/int8 are not affected.

🤖 Generated with Claude Code

cpegeric and others added 5 commits October 26, 2026 23:34
- QUANTIZATION option for HNSW: float32/float16/bf16/float64 for every
  op_type, int8/uint8 for L2 only. MO converts vectors and queries to the
  storage type before usearch. int8/uint8 use one trained [min,max] range
  sampled like IVF-Flat (SAMPLE ... PERCENT ... LIMIT), stored in the
  metadata table (quantize_min/quantize_max); CDC reuses it.
- Index vecf16/vecbf16/vecint8/vecuint8 columns directly.
- REINDEX keeps quantization and rejects changing it.
- Exact filtered search when the prefilter candidate count is at most
  hnsw_prefilter_exact_threshold (default 100000).
- usearch 2.26.5 matrixone_20261030 (usearch_filtered_search exact flag);
  Go binding redirected to cpegeric/usearch.
- Upgrade 4.0.18 adds the metadata columns to existing HNSW indexes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Design doc docs/design/20261026-hnsw-quantization.md; every claim maps
  to a BVT section and unit tests.
- BVT reorganized by claim; tie-free query points; adds narrowing,
  l2sq, empty-table CDC, delete, saturation, REINDEX retrain, copy
  ALTER/CLONE/TRUNCATE, exact-threshold and overflow cases.
- Sync: a model created before int8/uint8 bounds were known takes them
  once trained (a chunk with no vectors no longer wedges the sync).
- Reject a finite element the stored type cannot hold instead of
  storing Inf (float16/bf16/float32 narrowing).
- Rescale int8/uint8 distances in float64.
- Build the quantized metadata column list without patching SQL text.
- Exact prefiltered search comments state its cost precisely.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A filtered graph walk is cheaper than the exact scan once qualifying rows
exceed roughly 30-85 x ef_search, nearly independent of index size and
dimension (measured at 100k/1M rows, 128/768 dims). 5000 sits at that
crossover for the default ef_search.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-scanning build, narrow types

- int8/uint8 indexes keep their range in a key/value hidden table (hnsw_dict)
  instead of two metadata columns; the 4.0.18 upgrade is removed.
- max_index_capacity defaults to 0: a model holds what fits 75% of available
  host memory (dimension, stored width, M), as ivfpq; build and sync use the
  index option, then the session variable, then the estimate. Models reserve
  only the rows they receive.
- hnsw_create(params, cfg) counts, samples and streams the source itself; no
  CROSS APPLY.
- Build, sync, CDC and search use the column's element type; a vector already
  in the stored type is passed to usearch as it is.
- ISCP accepts the third hidden table; a vecint8/vecuint8 index without a dict
  uses its type range; a multi-batch sync grows the model's reservation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

- Unit tests for the hnsw_dict table def, quantization/column checks, the
  QUANTIZATION param, and narrow-type search dispatch (diff coverage 84.8%).
- usearch >= 2.25 replaced SimSIMD with NumKong and ignores the SimSIMD CMake
  flags, so remove the SimSIMD tarball and its thirdparties Makefile rules.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@XuPeng-SH

XuPeng-SH commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: a74601615dd2a7b1713281ee6d0a8a930617461e

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mo-bot review · mo-bot-local · review

Commit: a74601615dd2a7b1713281ee6d0a8a930617461e

Assessment: approve

Reviewed the complete delta, design, linked issue and discussion. The prior streaming-cleanup deadlock is resolved: capacity two accommodates the verified two-error publication bound. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

Validation:

  • Full table_function package passed with the race detector. Build-error and caller-cancellation regressions each passed 28 repetitions; stream-error and successful-build controls passed 100 repetitions.

  • Qualified retained HNSW/plugin/usearchex and targeted ISCP/planner results against unchanged inputs; verified 199 native inputs and six native output hashes.

  • Receipts, source fingerprints, logs and all five discussion items reconciled. Source unchanged. Artifacts: /home/xupeng/.local/state/mo-bot/jobs/ae0562ff3b3e82762188bb0d/attempt-1/validation-audit.json and discussion-assessment.json.

Limitations:

  • Cancellation tests use the real builder with a stream stub matching the inspected production executor contract.

  • No local distributed SQL BVT or production-scale performance rerun; frozen CI conclusions lack raw logs.

@mergify mergify Bot added the queued label Oct 27, 2026
@mergify

mergify Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue

2 h 8 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Tue 27 Oct, 19:41 · rule main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue 21:50 · a746016

Reason

Pull request #31468 has been dequeued

Queue conditions are not satisfied:

  • -conflict [📌 queue requirement]

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Requeued — the merge queue status continues in this comment ↓.

Times in UTC · dashboard · how the merge queue works

@mergify mergify Bot added dequeued and removed queued labels Oct 27, 2026
@mergify

mergify Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue

1 h 29 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Wed 28 Oct, 00:11 · rule main · triggered by @cpegeric with the merge queue checkbox
  • 🚫 Left the queue 01:41 · 1663a28

Reason

The pull request #31468 has been manually updated

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

Times in UTC · dashboard · how the merge queue works

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement kind/feature size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants