fix(knowledge): keep vector candidate selection bounded - #7960
Merged
Merged
Conversation
An underfilled ANN traversal rescored the whole compact projection and joined the visible document set to it. That fallback is O(corpus): on a 132k-chunk index it took 1.9s, and on a corpus an order of magnitude larger it exceeds the retrieval budget, so the vector leg returned nothing at all rather than fewer rows. Widening the search has no affordable form here. Measured at 10% visibility on the same index, scanning 6.5k tuples instead of 1.5k took 5.1s and 9.7s on consecutive identical runs, and joining visibility before scoring took 8.4s because it turns a sequential scan into a random lookup per document. The bounded traversal itself costs ~115ms whether or not it fills. The traversal is now the whole candidate set. An underfilled one yields fewer candidates and is reported as such, which strictly beats a leg that times out.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
|
…ersal The plan assertion still required the removed CTEs, and the predicates selecting which captured query to assert against matched the old CTE name with a lowercase fallback the rendered statement never produces. The candidate assertions would have stopped running rather than failing, so they now key on the visibility lateral through one shared predicate. The plan check drops the fallback-specific expectations and gains the one that guards this change: the traversal must never reach the projection by document lookup or sequential scan, at any candidate count.
Collaborator
Author
Collaborator
Author
|
@cubic-dev-ai review this PR |
Contributor
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
vectorCandidateScannow reportsplannedorunderfilled, so a reduced rerank pool is visible in diagnostics rather than silent.vectorInitialCandidateCountis dropped with the CTE that produced itWhy, with measurements
Every organization-scoped search was timing out on the vector leg and returning no vector results at all. Instrumentation traced it to the candidate CTE, and the plans explain it. All figures below are
EXPLAIN (ANALYZE, BUFFERS)on the same search index, where visibility admitted a tenth of the corpus:max_scan_tuples1k→20k)The rescan was already the best of the widening strategies, which is the point: no widening strategy is affordable. On a corpus an order of magnitude larger it runs well past the retrieval budget, and a leg that exceeds its budget contributes nothing — so fewer candidates strictly beats every alternative measured.
This also matches the documented failure mode for filtered ANN search: post-filtering that escalates to progressively larger scans is known to produce unpredictable latency, and the exhaustive variant is its degenerate case.
Trade-off
Recall is lower when visibility is selective enough to underfill the traversal, because the rerank pool is smaller. It is strictly higher than the current behaviour, which returns an empty vector leg once the budget is exceeded. Authorization is unchanged — the same visibility predicate still gates every candidate, and the surviving query keeps the live-source conditions.
Type of Change
Testing
Query plans measured on a real corpus for each alternative above. Unit test rewritten to assert the underfilled traversal is kept rather than widened, and that the candidate query contains no
UNION ALLorfiltered_scores. Lint,check:audits(46 audits),docs-manifest:check, block-registry check, andtype-checkpass; knowledge suites pass (2,921 tests).Checklist