-
Notifications
You must be signed in to change notification settings - Fork 99
feat: expose per-search distance evaluation statistics #2545
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,6 +135,7 @@ HGraph::KnnSearch(const DatasetPtr& query, | |
| return make_empty_dataset_with_stats(); | ||
| } | ||
| if (iter_filter_ctx->IsFirstUsed()) { | ||
| ctx.distance_phase = DistanceEvaluationPhase::ROUTING; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] Preserve statistics for empty iterator results In this iterator-search path, a reject-all filter can still perform routing/base distance evaluations but leave |
||
| for (auto i = static_cast<int64_t>(this->route_graphs_.size() - 1); i >= 0; --i) { | ||
| auto result = this->search_one_graph(query_data, | ||
| this->route_graphs_[i], | ||
|
|
@@ -144,6 +145,7 @@ HGraph::KnnSearch(const DatasetPtr& query, | |
| &ctx); | ||
| search_param.ep = result->Top().second; | ||
| } | ||
| ctx.distance_phase = DistanceEvaluationPhase::APPROXIMATE; | ||
| } | ||
|
|
||
| search_param.ef = std::max(params.ef_search, k); | ||
|
|
@@ -433,7 +435,7 @@ HGraph::SearchWithRequest(const SearchRequest& request) const { | |
| for (const auto& pair : label_to_inner_id) { | ||
| float dist = 0.0F; | ||
| const auto inner_id = pair.second; | ||
| precise_flatten->Query(&dist, computer, &inner_id, 1); | ||
| precise_flatten->Query(&dist, computer, &inner_id, 1, &ctx); | ||
| reasoning_ctx->SetTrueDistance(inner_id, dist); | ||
| } | ||
| ctx.reasoning_ctx = reasoning_ctx.get(); | ||
|
|
@@ -453,11 +455,13 @@ HGraph::SearchWithRequest(const SearchRequest& request) const { | |
| auto vt = this->pool_->TakeOne(); | ||
|
|
||
| const auto* raw_query = get_data(query); | ||
| ctx.distance_phase = DistanceEvaluationPhase::ROUTING; | ||
| for (auto i = static_cast<int64_t>(this->route_graphs_.size() - 1); i >= 0; --i) { | ||
| auto result = this->search_one_graph( | ||
| raw_query, this->route_graphs_[i], this->basic_flatten_codes_, search_param, vt, &ctx); | ||
| search_param.ep = result->Top().second; | ||
| } | ||
| ctx.distance_phase = DistanceEvaluationPhase::APPROXIMATE; | ||
|
|
||
| FilterPtr ft = this->create_search_filter(request.filter_, params.use_extra_info_filter); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -740,6 +740,7 @@ SIMQ::KnnSearch(const DatasetPtr& query, | |
| uint64_t coarse_probe_count = 0; | ||
| auto coarse_results = coarse_search( | ||
| query_mvs[0].vectors_, query_mvs[0].len_, coarse_k, &coarse_dist_cmp, &coarse_probe_count); | ||
| stats.AddDistance(SearchStatistics::DistancePhase::ROUTING, "fp32", coarse_dist_cmp); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] Use nested HGraph distance evaluations for SIMQ routing
|
||
| uint64_t coarse_candidate_count = coarse_results.size(); | ||
| if (static_cast<int64_t>(coarse_results.size()) > rerank_k) { | ||
| coarse_results.resize(rerank_k); | ||
|
|
@@ -766,10 +767,13 @@ SIMQ::KnnSearch(const DatasetPtr& query, | |
| // Single batched Query call (enables MultiRead in MultiVectorDataCell) | ||
| if (!batch_ids.empty()) { | ||
| std::vector<float> batch_dists(batch_ids.size()); | ||
| QueryContext query_context{.stats = &stats, | ||
| .distance_phase = DistanceEvaluationPhase::RERANK}; | ||
| mv_codes_->Query(batch_dists.data(), | ||
| computer, | ||
| batch_ids.data(), | ||
| static_cast<InnerIdType>(batch_ids.size())); | ||
| static_cast<InnerIdType>(batch_ids.size()), | ||
| &query_context); | ||
| stats.dist_cmp.fetch_add(static_cast<uint32_t>(batch_ids.size()), | ||
| std::memory_order_relaxed); | ||
| for (uint64_t i = 0; i < batch_ids.size(); i++) { | ||
|
|
@@ -834,6 +838,7 @@ SIMQ::RangeSearch(const DatasetPtr& query, | |
| uint64_t coarse_probe_count = 0; | ||
| auto coarse_results = coarse_search( | ||
| query_mvs[0].vectors_, query_mvs[0].len_, coarse_k, &coarse_dist_cmp, &coarse_probe_count); | ||
| stats.AddDistance(SearchStatistics::DistancePhase::ROUTING, "fp32", coarse_dist_cmp); | ||
| uint64_t coarse_candidate_count = coarse_results.size(); | ||
| if (static_cast<int64_t>(coarse_results.size()) > rerank_k) { | ||
| coarse_results.resize(rerank_k); | ||
|
|
@@ -849,7 +854,9 @@ SIMQ::RangeSearch(const DatasetPtr& query, | |
| continue; | ||
| } | ||
| float dist = 0.0F; | ||
| mv_codes_->Query(&dist, computer, &doc_id, 1); | ||
| QueryContext query_context{.stats = &stats, | ||
| .distance_phase = DistanceEvaluationPhase::RERANK}; | ||
| mv_codes_->Query(&dist, computer, &doc_id, 1, &query_context); | ||
| ++stats.dist_cmp; | ||
| if (dist <= radius) { | ||
| in_range.emplace_back(dist, doc_id); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.