Repository navigation
Conversation
|
Workflow [PR], commit [77c57bc] Summary: ❌
AI ReviewSummaryThis PR keeps Findings
Final Verdict
|
There was a problem hiding this comment.
Pull request overview
This PR improves MergeTree vector similarity skip-index usage by keeping vector index analysis enabled even when primary key pruning leaves only a subset of marks in a part, and constraining USearch traversal/results to PK-allowed marks via filtered_search.
Changes:
- Extend the vector similarity index condition API to accept an optional per-granule PK
MarkRangesrow-filter. - Pass PK-surviving
MarkRangesinto vector index analysis duringfilterMarksUsingIndex, enabling vector search under partial PK pruning. - Add a stateless regression test covering partial PK pruning scenarios (including PK range + vector ORDER BY LIMIT, with/without additional filters).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/queries/0_stateless/04217_vector_similarity_pk_partial_pruning.sql | Adds stateless queries to validate correctness under partial PK pruning with vector similarity ordering. |
| tests/queries/0_stateless/04217_vector_similarity_pk_partial_pruning.reference | Adds expected outputs for the new stateless test. |
| src/Storages/MergeTree/MergeTreeIndices.h | Extends IMergeTreeIndexCondition with GranuleRowFilter and an optional row-filter argument for vector ANN. |
| src/Storages/MergeTree/MergeTreeIndexVectorSimilarity.h | Updates vector similarity condition interface to accept the optional row-filter. |
| src/Storages/MergeTree/MergeTreeIndexVectorSimilarity.cpp | Implements PK-aware ANN via USearch filtered_search and adds key→mark predicate logic. |
| src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp | Removes the early-return that disabled vector index under partial PK pruning; constructs/passes row-filter to ANN. |
…n the granule instead of global row lookup
…row offsets for _distance filtering
…missing per granule
…kRangeForRowOffset
…parts Address the AI review "Request changes" verdict on ClickHouse#104754. 1. New setting `vector_search_min_surviving_pk_fraction` (default `0.5`): the minimum fraction of the marks of a part that must survive primary key analysis for the `vector_similarity` index to be used on a partially pruned part. Below it, `filterMarksUsingIndex` skips the index for the part, as before this feature, and exact distances are computed for the surviving rows. The measurement posted in the pull request (1M x 64 dim, single part, single HNSW granule) shows `filtered_search` is ~2x faster than the brute-force fallback when 80% of the part survives, but ~1.7x slower at 10% and ~10x slower at 2%, because the filtered graph traversal rejects most of the visited neighbours. The threshold keeps the win for wide slices and the old behavior for selective ones. 2. `04217_vector_similarity_pk_partial_pruning`: assert the ordered ids *and* distances of a cross-granule result against the brute-force baseline, using a mark-aligned filter (`id <= 2 OR id >= 6`) so both skip-index granules contribute hits and no row is removed afterwards. This covers the part-global `_distance` / row-offset merge that the previous row-count and primary-key membership assertions could not. Also cover the new threshold: below it the index is not used (`USearchSearchCount = 0`) and the result is exact, while with the threshold disabled the same query post-filters the index hits and returns fewer rows. 3. Because the default threshold restores the previous behavior for selective primary key conditions, `02354_vector_search_nonindexed_columns` and `04490_vector_search_rescoring_prewhere_eligibility` no longer need the expectation changes made earlier in this branch and are reverted to `master`. `02354_vector_search_pre_and_post_filtering` sets the new setting explicitly instead of depending on the default, and `02354_vector_search_rescoring` keeps the brute-force baseline and additionally shows the index-path result for the same query.
|
Pushed 1. Selectivity fallback for 2. Cross-granule assertion in 3. The 4. Recall of the partial-PK index path — worth a design decision before this merges. The primary key ranges are mark-granular, so the index searches a superset of the qualifying rows and the exact predicate then removes some of its top- SELECT id FROM tab_pk_partial WHERE id >= 9 ORDER BY L2Distance(vec, [0., 2.]) LIMIT 3
-- index path (vector_search_min_surviving_pk_fraction = 0): []
-- brute force (use_skip_indexes = 0): [9, 10, 11]( Verified locally on a build of this branch: |
|
Added |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 213/253 (84.19%) · Uncovered code |
|
Hi @alexey-milovidov @shankar-iyer, would really appreciate a review! |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Object file sizes68 object files changed (+104.92 KiB total), 0 added.
737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units357 translation units recompiled, 4316 s compile time in total, 357 of them have a recent master baseline. |
|
@rschu1ze @alexey-milovidov @shankar-iyer It looks like this PR now requires manual approval again for running the CI, probably after the latest merge from master / maintainer-side updates. Could you please take another look when you get a chance? The latest PR workflow on the current head is green, and I believe the main review points have been addressed. Thanks! |
|
@zex-hyd This PR contains rather complex changes and we are busy with other vector search developments at the moment. Expect some delay, sorry. |
|
Thanks for the update, @rschu1ze. |
…larity-pk-partial-filter Resolve the conflict with the move of the settings changes history into the setting declarations (ee6b44f): the history records this PR added to `SettingsChangesHistory.cpp` now live as trailing arguments of the `DECLARE` of each setting. - retargeted PR record [email protected] to 26.10 (settings-history check rule) Also resolved conflicts in: - `docs/reference/settings/session-settings/manifest.json` - `src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp` - `src/Storages/MergeTree/MergeTreeIndexVectorSimilarity.cpp` Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
|
||
| This setting is the minimum fraction of the marks of a part that must survive primary key analysis for the vector similarity index to be used. If fewer marks survive, ClickHouse skips the vector similarity index for the part and computes exact distances for the surviving rows instead. Valid range: [0.0, 1.0]. `0` always uses the index, `1` uses it only if the primary key prunes nothing. | ||
| )", 0, \ | ||
| {"26.10", 1.0, 0.5, "New setting: minimum fraction of the marks of a part surviving primary key analysis for the vector similarity index to be used on a partially pruned part. previous_value=1.0 so `compatibility` with versions before 26.8 restores the legacy rule of using the vector index only when the primary key prunes nothing."}) \ |
There was a problem hiding this comment.
The compatibility cutoff for this setting is inconsistent across the branch: this source-of-truth entry uses 26.10, the description text still says "compatibility with versions before 26.8", and the generated docs/reference/settings/session-settings/vector-search.mdx in the same PR still renders 26.8. Because the actual compatibility behavior keys off this history entry, either the rollback boundary is wrong or the published guidance will tell users the wrong version to pin. Please settle on one cutoff and regenerate the settings docs from that same source.
Fixes the case where
vector_similarityskip indexes were not used when a primary key condition left only a subset of marks in a part. Previously, that situation skipped vector index analysis entirely, so reads could not use the HNSW granule to narrow work the way the index is intended.This PR keeps running vector index analysis under partial PK pruning and passes surviving PK
MarkRangesinto USearchfiltered_searchas a predicate, so graph traversal only keeps neighbors whose rows map to PK-allowed data marks.Motivated by #104122. Typical pattern: a long-retention table (for example tickets by time in the primary key) plus a narrow time predicate and
ORDER BYvector distance withLIMIT— partial PK on the part plus vector search.When other skip indexes (minmax, set, text) run earlier in the pipeline and narrow
MarkRanges, the vector path still sees that reducedrangesinput, so behavior stays conjunctive without extra glue.limitis oversampled withvector_search_index_fetch_multiplierwhenrow_filteris set, using the same rule asadditional_filters_presentand rescoring.filtered_searchcan still return fewer thanlimithits if the PK slice removes almost all rows inside a granule.Stateless:
04217_vector_similarity_pk_partial_pruning.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Vector similarity skip indexes are used when the primary key leaves only a subset of marks in a part: neighbors are filtered with USearch
filtered_searchto PK-allowed data marks instead of skipping the vector index for that case.Documentation entry for user-facing changes
Note
Medium Risk
Changes MergeTree mark filtering and vector-search hint propagation during query execution; mistakes could cause incorrect pruning or
_distanceordering behavior under mixed PK/skip-index conditions.Overview
Enables
vector_similarityskip index usage even when primary key pruning leaves only a subset of marks in a part, by passing PK-surviving row intervals into USearchfiltered_searchand restricting ANN hits to those ranges.Updates vector-search hint handling to merge per-granule ANN results into part-global row offsets, conservatively dropping
_distancehints if any non-empty granule lacks distances, and adds per-index_markcaching to avoid repeated ANN work when marks are referenced by multiple PK ranges.Adds new
VectorSearchUtilstypes (GranuleRowFilter,ANNSearchOverrides) and adjusts tests to expect index usage under partial PK pruning, plus a new stateless regression test (04217_vector_similarity_pk_partial_pruning).Reviewed by Cursor Bugbot for commit 082abd3. Bugbot is set up for automated code reviews on this repo. Configure here.
Workflow [PR]
Sync PR [sync-upstream/pr/104754]