fix: refactor rescore limit by trengrj · Pull Request #13536 · weaviate/weaviate · GitHub
Skip to content

fix: refactor rescore limit - #13536

Open
trengrj wants to merge 2 commits into
mainfrom
trengrj/rescore
Open

trengrj wants to merge 2 commits into
mainfrom
trengrj/rescore

Conversation

@trengrj

@trengrj trengrj commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

What's being changed:

rescoreLimit now bounds HNSW rescoring to min(ef, max(k, rescoreLimit)) for every quantizer. Previously only SQ and RQ honoured it, and only when rescoreLimit >= k; otherwise the whole ef was rescored, a 10x jump in object-bucket reads between k=20 and k=21 with default settings. Rescoring is one random disk read per candidate, so this is what made rescore dominate an incident profile on an IOPS-throttled volume.

Reads per query, dynamic ef defaults, limit 20:

k before after
10 20 20
21 168 21
100 500 100

The contract is now shared by PQ, BQ, SQ and RQ (entities/vectorindex/hnsw/rescore_limit.go):

value meaning
-1 automatic (stored default), resolves per quantizer
0 rescoring disabled
positive used as-is
below -1 rejected

Automatic resolves to:

quantizer before after
SQ, RQ 8-bit, RQ 4-bit 20 20
RQ 1-bit 512 256
PQ no limit 256
BQ no limit 256

Upgrades: existing SQ and RQ collections keep the number in their schema. PQ and BQ collections have no key and land on automatic. Pinned by a RAFT snapshot restore test, a parser test and an index-level test. Schema output for new collections shows -1 where it used to show 20/512.

Also: PQ and BQ rescoreLimit is classified as a query-time change in the replica move guard.

Copilot AI balanced review requested due to automatic review settings October 14, 2026 05:34

@orca-security-eu orca-security-eu 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.

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Passed Passed SAST high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Vulnerabilities high 0   medium 0   low 0   info 0 View in Orca

Copilot AI 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.

🟡 Changes recommended

RQ-1 acceptance assertions still expect concrete defaults and will fail when the schema returns the new automatic value.

1 open finding
What changed in this PR

Refactors HNSW rescoring into a shared, configurable limit model across all quantizers.

Changes:

  • Adds automatic and disabled rescore-limit semantics.
  • Supports bounded rescoring for PQ, BQ, SQ, and RQ.
  • Expands configuration, upgrade, and search tests.
File Description
test/​acceptance/​schema/​get_schema_without_client_test.go Updates serialized defaults.
test/​acceptance/​schema/​default_quantization_test.go Updates default RQ-8 assertions.
entities/​vectorindex/​hnsw/​sq_config.go Uses shared limit parsing.
entities/​vectorindex/​hnsw/​rq_config.go Refactors RQ defaults and parsing.
entities/​vectorindex/​hnsw/​rescore_limit.go Defines shared limit behavior.
entities/​vectorindex/​hnsw/​pq_config.go Adds PQ rescore configuration.
entities/​vectorindex/​hnsw/​config.go Applies automatic defaults.
entities/​vectorindex/​hnsw/​config_test.go Tests parsing and compatibility.
entities/​vectorindex/​hnsw/​bq_config.go Adds BQ rescore configuration.
entities/​vectorindex/​dynamic/​config_test.go Updates dynamic-index expectations.
cluster/​schema/​schema_test.go Marks new fields query-safe.
cluster/​schema/​rescore_limit_upgrade_test.go Tests legacy snapshot restoration.
cluster/​schema/​movement_guard.go Normalizes new fields.
adapters/​repos/​db/​vector/​hnsw/​search.go Applies bounded rescoring uniformly.
adapters/​repos/​db/​vector/​hnsw/​search_test.go Tests rescoring gates and bounds.
adapters/​repos/​db/​vector/​hnsw/​rescore_limit_test.go Tests real quantizer behavior.
adapters/​repos/​db/​vector/​hnsw/​config_update_test.go Tests runtime updates.
adapters/​repos/​db/​vector/​dynamic/​index_test.go Updates compression test configs.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

rescoreLimit, err = jsonRescoreLimit.Int64()
require.Nil(t, err)
require.Equal(t, int64(hnsw.DefaultRQRescoreLimit), rescoreLimit)
require.Equal(t, int64(hnsw.RescoreLimitAuto), rescoreLimit)

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.

Updated both RQ-1 HNSW assertions to expect RescoreLimitAuto in aa98569.

Co-authored-by: trengrj <2173919+trengrj@users.noreply.github.com>
@sonarqubecloud

Copy link
Copy Markdown

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.

4 participants