-
Notifications
You must be signed in to change notification settings - Fork 453
feat: adaptive vector search #7680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: adaptive vector search #7680
Conversation
Signed-off-by: Dennis Zhuang <[email protected]>
Signed-off-by: Dennis Zhuang <[email protected]>
Signed-off-by: Dennis Zhuang <[email protected]>
Summary of ChangesHello @killme2008, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant enhancement to vector search capabilities by implementing an adaptive top-k mechanism. This system intelligently refines vector search queries by iteratively adjusting the number of candidates considered, ensuring more accurate results, especially when complex filters are applied. The changes span across query optimization, physical execution, and storage layer interactions, providing a robust and observable solution for vector similarity search. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces an adaptive vector search mechanism, a significant feature for more accurate top-k vector searches when combined with filters. It works by adaptively fetching more candidates from the vector index. The implementation includes a new optimizer rule (AdaptiveVectorTopKRule), a custom logical plan node (AdaptiveVectorTopKLogicalPlan), and a physical execution node (AdaptiveVectorTopKExec) that contains the adaptive loop logic. This loop progressively increases the number of candidates (k) until enough results are found to satisfy the query's LIMIT and OFFSET. The PR also adds new configuration options and metrics for control and observability, extends vector search interfaces with predicate support, and includes new integration tests. The implementation appears solid and well-tested. I have one minor suggestion for code simplification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Adds adaptive (dynamic overfetch) execution for vector Top-K queries so results remain correct with filters / OFFSET / tie-breakers, while improving observability via new vector-index k metrics.
Changes:
- Introduces
AdaptiveVectorTopKRule+ DataFusion extension logical/physical nodes to iteratively re-plan/retry vector Top-K with increasing k. - Extends vector search plumbing with optional limit/offset/tie-breakers and adds predicate-capable vector index search APIs.
- Adds/updates golden tests and metrics reporting for vector-index requested/returned k (including distributed MergeScan aggregation).
Reviewed changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/cases/standalone/common/tql-explain-analyze/explain.result | Updates explain output to include the new adaptive optimizer rule stage. |
| tests/cases/standalone/common/function/vector/vector_index_explain.result | Updates vector explain plans to show AdaptiveVectorTopKExec. |
| tests/cases/standalone/common/function/vector/dynamic_overfetch.sql | Adds SQL test coverage for dynamic overfetch correctness (filters, offsets, partitions). |
| tests/cases/standalone/common/function/vector/dynamic_overfetch.result | Adds expected outputs for dynamic overfetch test cases. |
| tests-integration/tests/http.rs | Sets vector_topk_max_rounds in integration test config. |
| src/store-api/src/storage/requests.rs | Extends VectorSearchRequest; introduces VectorSearchPredicate and default predicate-aware engine search. |
| src/store-api/src/storage.rs | Re-exports VectorSearchPredicate. |
| src/query/src/vector_search/planner.rs | Adds extension planner to build AdaptiveVectorTopKExec from the logical node. |
| src/query/src/vector_search/plan.rs | Adds AdaptiveVectorTopKLogicalPlan (DataFusion extension logical node). |
| src/query/src/vector_search/options.rs | Adds DataFusion config extension for adaptive vector Top-K runtime bounds. |
| src/query/src/vector_search/mod.rs | Wires new vector_search module exports. |
| src/query/src/vector_search/exec.rs | Implements adaptive retry loop executor + metrics and unit tests. |
| src/query/src/query_engine/state.rs | Registers optimizer rule, extension planner, and session extension options. |
| src/query/src/options.rs | Adds query config knobs for adaptive vector Top-K. |
| src/query/src/optimizer/scan_hint/vector_search.rs | Captures tie-breakers + limit/offset into vector search hints. |
| src/query/src/optimizer/adaptive_vector_topk.rs | Adds optimizer rewrite from Sort+Limit to AdaptiveVectorTopK extension node. |
| src/query/src/optimizer.rs | Exposes adaptive vector top-k optimizer module. |
| src/query/src/lib.rs | Exports vector_search module. |
| src/query/src/dist_plan/merge_scan.rs | Fixes vector-index k metric aggregation (avoid over-counting) and adds tests. |
| src/mito2/src/sst/parquet/reader.rs | Passes predicate placeholder to vector index applier; records requested/returned k metrics. |
| src/mito2/src/sst/index/vector_index/applier.rs | Adds predicate parameter and uses predicate-aware search API. |
| src/mito2/src/read/scan_util.rs | Plumbs and exposes vector-index requested/returned k scan metrics via DataFusion gauges. |
| src/mito2/src/read/scan_region.rs | Removes fixed overfetch multiplier and uses request k directly. |
| src/mito2/src/read/pruner.rs | Clarifies cache-hit metric behavior and keeps error path explicit. |
| src/index/src/vector/engine/usearch.rs | Implements predicate-aware search using USearch filtered_search. |
| src/index/src/vector/apply.rs | Adds predicate-aware search at applier level + mapping adapter + unit test. |
| src/flow/src/adapter.rs | Updates flownode defaults to include new query options. |
| src/cmd/tests/load_config_test.rs | Updates config loading test expectations for new query options. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/cases/standalone/common/function/vector/vector_index_explain.result
Outdated
Show resolved
Hide resolved
Signed-off-by: Dennis Zhuang <[email protected]>
Signed-off-by: Dennis Zhuang <[email protected]>
Signed-off-by: Dennis Zhuang <[email protected]>
Signed-off-by: Dennis Zhuang <[email protected]>
Signed-off-by: Dennis Zhuang <[email protected]>
Signed-off-by: Dennis Zhuang <[email protected]>
Signed-off-by: Dennis Zhuang <[email protected]>
Signed-off-by: Dennis Zhuang <[email protected]>
I hereby agree to the terms of the GreptimeDB CLA.
Refer to a related PR or issue link (optional)
#7668
What's changed and what's your intention?
PR Checklist
Please convert it to a draft if some of the following conditions are not met.