Add vector query execution semantics: filtered ANN, threshold search, and compound retrieval (Phase 3)#18114
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #18114 +/- ##
============================================
+ Coverage 63.93% 63.94% +0.01%
- Complexity 1594 1614 +20
============================================
Files 3178 3181 +3
Lines 193466 193717 +251
Branches 29880 29911 +31
============================================
+ Hits 123683 123871 +188
- Misses 60010 60065 +55
- Partials 9773 9781 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…shold search, and compound retrieval (Phase 3) Introduces backend capability model, execution mode enum (8 modes), filtered ANN with candidate over-fetch, approximate threshold/radius search via exact refinement, compound query patterns, and execution mode reporting in explain output. All existing VECTOR_SIMILARITY queries remain backward compatible with no SQL changes required. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace pre-scan with inline check: isVectorSimilarityFilter(childFilter) && childFilters.size() > 1. Remove unused hasVectorSimilarityChild helper. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…index Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…apshot, enum switch comment - ExactVectorScanFilterOperator.computeExactThreshold: call toImmutableRoaringBitmap() - VectorSimilarityFilterOperator.applyThresholdRefinement: snapshot volatile _vectorExplainContext - VectorBackendType.buildCapabilities: add comment explaining why name() is used in switch Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
L2 squared distances average ~256 for 128-dim Gaussian vectors. Use thresholds 200/240/260 to produce meaningful result counts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… compound retrieval Tests cover: - Basic top-K backward compatibility - Filtered ANN (vector + metadata filter AND) - Filtered ANN reduces result count - Threshold/radius search with vectorDistanceThreshold - Compound filter + threshold - Execution mode in EXPLAIN output - Filtered ANN mode in EXPLAIN output Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ectorTest VectorTest (HNSW/COSINE): - Add category column for filtered ANN testing - testFilteredAnn: vector + metadata filter AND, verify filter + ordering - testFilteredAnnReducesResults: filtered count <= unfiltered count - testExplainShowsExecutionMode: execution mode in EXPLAIN output IvfFlatVectorTest (IVF_FLAT/EUCLIDEAN): - Add category column for compound query testing - testThresholdSearch: vectorDistanceThreshold returns within-distance results - testCompoundFilterAndThreshold: filter + threshold, both conditions verified Removes standalone VectorPhase3QuerySemanticsTest. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds Phase 3 vector query execution semantics, introducing explicit execution modes, backend capability modeling, filtered ANN over-fetching, and distance-threshold (“radius”) search with explain/debug visibility.
Changes:
- Introduces
VectorBackendCapabilities+ wires capabilities intoVectorBackendTypefor backend-neutral planning decisions. - Adds
VectorExecutionModeand plumbs execution-mode reporting into vector operators and explain output. - Adds
vectorDistanceThresholdquery option with threshold refinement paths for ANN and exact-scan fallback, plus new unit/integration tests and a perf benchmark.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| pinot-spi/src/main/java/org/apache/pinot/spi/utils/CommonConstants.java | Adds vectorDistanceThreshold query option key constant. |
| pinot-common/src/main/java/org/apache/pinot/common/utils/config/QueryOptionsUtils.java | Parses/validates vectorDistanceThreshold query option. |
| pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/creator/VectorBackendCapabilities.java | New immutable capability model for vector backends. |
| pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/creator/VectorBackendType.java | Attaches capabilities to each backend type via getCapabilities(). |
| pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/index/creator/VectorExecutionMode.java | New enum describing vector execution strategies. |
| pinot-core/src/main/java/org/apache/pinot/core/operator/filter/VectorQueryExecutionContext.java | Centralized execution-mode selection + context container. |
| pinot-core/src/main/java/org/apache/pinot/core/operator/filter/VectorSearchParams.java | Adds threshold parameter support to vector search params. |
| pinot-core/src/main/java/org/apache/pinot/core/operator/filter/VectorExplainContext.java | Extends explain context with execution mode. |
| pinot-core/src/main/java/org/apache/pinot/core/plan/FilterPlanNode.java | Detects vector+AND patterns to mark filtered execution semantics and pass flags into operators. |
| pinot-core/src/main/java/org/apache/pinot/core/operator/filter/VectorSimilarityFilterOperator.java | Implements filtered over-fetch + threshold refinement and exposes execution mode in explain. |
| pinot-core/src/main/java/org/apache/pinot/core/operator/filter/ExactVectorScanFilterOperator.java | Adds threshold-based exact scan fallback and explain execution mode. |
| pinot-core/src/test/java/org/apache/pinot/core/operator/filter/VectorSearchParamsTest.java | Unit tests for distance-threshold parsing and defaults. |
| pinot-core/src/test/java/org/apache/pinot/core/operator/filter/VectorSimilarityFilterOperatorTest.java | Unit tests for filtered/threshold behavior and execution-mode reporting. |
| pinot-core/src/test/java/org/apache/pinot/core/operator/filter/VectorQueryExecutionContextTest.java | Tests for mode selection rules and builder behavior. |
| pinot-core/src/test/java/org/apache/pinot/core/operator/filter/VectorCompoundQueryTest.java | Tests compound patterns (filter+topK, filter+threshold) and mode reporting. |
| pinot-segment-spi/src/test/java/org/apache/pinot/segment/spi/index/creator/VectorBackendCapabilitiesTest.java | Unit tests for capability model and backend integration. |
| pinot-segment-spi/src/test/java/org/apache/pinot/segment/spi/index/creator/VectorExecutionModeTest.java | Unit tests for execution mode enum properties. |
| pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/custom/VectorTest.java | Adds integration coverage for filtered ANN + explain output. |
| pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/custom/IvfFlatVectorTest.java | Adds integration coverage for threshold search and filter+threshold compound query. |
| pinot-perf/src/main/java/org/apache/pinot/perf/BenchmarkVectorPhase3.java | Adds a Phase 3 benchmark harness for filtered/threshold patterns. |
1. Threshold mode now honors explicit vectorMaxCandidates via getEffectiveMaxCandidates instead of falling through to topK 2. Remove unused capabilities parameter from selectExecutionMode; the method now takes 4 boolean args instead of 4 booleans + capabilities 3. FilterPlanNode sets hasMetadataFilter only when AND has a non-vector sibling (hasNonVectorSibling), not just any sibling 4. Strengthen EXPLAIN assertion in VectorTest to require executionMode presence rather than accepting VECTOR_SIMILARITY as a fallback 5. Replace brittle testModeCount (hardcoded 8) with testExpectedModesExist that asserts each expected mode by name Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove the 2x over-fetch for filtered ANN queries. vectorSimilarity(col, q, 10) must return at most 10 docs regardless of metadata filters. The bitmap AND with the metadata filter correctly reduces the result set. Also document the approximate nature of threshold search via ANN candidates: recall is limited by the candidate pool size (vectorMaxCandidates). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ld input; document FILTER_THEN_ANN as reserved - Throw IllegalStateException when vectorDistanceThreshold is set but forward index is unavailable (instead of silently returning raw ANN results) - Add Preconditions.checkState in FilterPlanNode for early detection - Trim whitespace before parsing vectorDistanceThreshold for robustness - Add Javadoc to FILTER_THEN_ANN clarifying it is reserved for future backends Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Documentation for this PR has been created in the pinot-contrib/pinot-docs repository: PR: pinot-contrib/pinot-docs#722 Documentation includes:
See Vector Query Execution Semantics for the full documentation. |
…-semantics docs: add vector query execution semantics and vectorDistanceThreshold option (apache/pinot#18114)
Summary
VectorBackendCapabilitiesdeclares 5 query-time capabilities per backend (topKAnn, filterAwareSearch, approximateRadius, exactRerank, runtimeSearchParams), wired intoVectorBackendType.getCapabilities()VectorExecutionModedefines 8 explicit modes with centralized selection logicFilterPlanNodedetects AND(VECTOR_SIMILARITY, non-vector-filter) patterns; execution mode is explicit in explain outputvectorDistanceThresholdquery option enables distance-based filtering via ANN candidate generation + exact threshold refinement from forward index; works in both indexed and exact-scan fallback pathsExecution Mode Reference
The runtime selects one of 8 explicit modes based on query shape. The selected mode is reported in EXPLAIN output.
Mode Selection Rules (centralized in
VectorQueryExecutionContext.selectExecutionMode)Mode Details
ANN_TOP_KANN_TOP_K_WITH_RERANKvectorExactRerank=trueor IVF_PQ defaultANN_THEN_FILTERWHERE vectorSimilarity(...) AND col = 'x'ANN_THEN_FILTER_THEN_RERANKvectorExactRerank=trueFILTER_THEN_ANNANN_THRESHOLD_SCANvectorDistanceThresholdset, no filterANN_THRESHOLD_THEN_FILTERvectorDistanceThreshold+ metadata filterEXACT_SCANHow to see the execution mode
Output includes
executionMode:ANN_THEN_FILTERin the vector operator's explain attributes.How the mode is determined (code path)
FilterPlanNode.constructPhysicalOperator()detects AND(VECTOR_SIMILARITY, non-vector siblings) viahasNonVectorSibling()VectorSimilarityFilterOperatorconstructor receiveshasMetadataFilterflag +VectorSearchParams(which carriesdistanceThreshold)VectorQueryExecutionContext.selectExecutionMode(hasVectorIndex, hasMetadataFilter, hasThresholdPredicate, exactRerank)returns the modeVectorExplainContextand reported viatoExplainString()andexplainAttributes()Threshold search semantics
When
vectorDistanceThresholdis set:vectorMaxCandidates, defaulttopK * 10), then exact distance is computed for each candidate. Only candidates within the threshold are returned. This is approximate — vectors within the threshold but outside the ANN candidate pool will be missed. IncreasevectorMaxCandidatesfor better recall.ExactVectorScanFilterOperatorperforms brute-force scan and returns all vectors within the threshold (exact, no recall loss).l2Distance()function returns sqrt, sovectorDistanceThreshold=100matches vectors wherel2Distance() <= 10.Sample Table Config
HNSW (default, supports realtime)
{ "tableName": "products_OFFLINE", "tableType": "OFFLINE", "fieldConfigList": [ { "name": "embedding", "indexTypes": ["VECTOR"], "encodingType": "RAW", "properties": { "vectorIndexType": "HNSW", "vectorDimension": "128", "vectorDistanceFunction": "COSINE" } } ] }IVF_FLAT (offline only, tunable nprobe)
{ "tableName": "articles_OFFLINE", "tableType": "OFFLINE", "fieldConfigList": [ { "name": "embedding", "indexTypes": ["VECTOR"], "encodingType": "RAW", "properties": { "vectorIndexType": "IVF_FLAT", "vectorDimension": "128", "vectorDistanceFunction": "EUCLIDEAN", "nlist": "64", "version": "1" } } ] }IVF_PQ (offline only, compressed, rerank enabled by default)
{ "tableName": "images_OFFLINE", "tableType": "OFFLINE", "fieldConfigList": [ { "name": "embedding", "indexTypes": ["VECTOR"], "encodingType": "RAW", "properties": { "vectorIndexType": "IVF_PQ", "vectorDimension": "128", "vectorDistanceFunction": "EUCLIDEAN", "nlist": "64", "pqM": "16", "pqNbits": "8", "version": "1" } } ] }Sample Queries
1. Basic top-K ANN (unchanged from Phase 1/2)
Execution mode:
ANN_TOP_K2. Top-K ANN with exact rerank (Phase 2)
Execution mode:
ANN_TOP_K_WITH_RERANK3. Filtered ANN — metadata filter + top-K (Phase 3, new)
Execution mode:
ANN_THEN_FILTERANN returns top-10 candidates, bitmap AND with metadata filters reduces the set. Result is <= 10 rows.
4. Filtered ANN with rerank (Phase 3, new)
Execution mode:
ANN_THEN_FILTER_THEN_RERANK5. Threshold/radius search — find all similar vectors within a distance (Phase 3, new)
Execution mode:
ANN_THRESHOLD_SCANANN generates a candidate pool (default:
topK * 10= 1000), exact distance is computed for each. Only candidates with distance <= 0.3 are returned.6. Compound: metadata filter + threshold search (Phase 3, new)
Execution mode:
ANN_THRESHOLD_THEN_FILTER7. IVF with tuned nprobe (Phase 2, works with all Phase 3 modes)
8. EXPLAIN to see execution mode
Output includes:
Query Options Reference
vectorNprobevectorExactRerankvectorMaxCandidatesvectorDistanceThresholdBenchmark Results
Exact brute-force scan baseline for Phase 3 query patterns. Measured on synthetic Gaussian vectors with L2 (Euclidean squared) distance. All latencies are single-segment, single-threaded.
Filtered Exact Scan (50K vectors, 128-dim, topK=10)
Threshold/Radius Scan (50K vectors, 128-dim)
Filtered Threshold Scan (50K vectors, 128-dim, threshold=240.0)
Scale Test (100K vectors, 128-dim)
Backward Compatibility
All existing VECTOR_SIMILARITY queries work unchanged. No SQL, schema, table config, or wire protocol changes. The new
vectorDistanceThresholdquery option is purely additive.Test plan
VectorBackendCapabilitiesTest— capability model for all backends (8 tests)VectorExecutionModeTest— mode properties and presence checks (6 tests)VectorBackendTypeTest— existing + new capability integration (8 tests)VectorQueryExecutionContextTest— mode selection logic for all query shapes (16 tests)VectorSearchParamsTest— threshold parsing, negative thresholds for dot-product (19 tests)VectorSimilarityFilterOperatorTest— filtered ANN, threshold refinement, execution mode reporting (21 tests)VectorCompoundQueryTest— compound patterns: filter+topK, filter+threshold, backward compat (9 tests)VectorTest(integration) — filtered ANN, filtered reduces results, EXPLAIN execution modeIvfFlatVectorTest(integration) — threshold search, compound filter+thresholdBenchmarkVectorPhase3— performance benchmark for filtered and threshold workloads🤖 Generated with Claude Code