Skip to content

Commit 7070d3a

Browse files
committed
add: WIP Phase 4 first pass; Getting previous tests to pass
1 parent 90f3b24 commit 7070d3a

3 files changed

Lines changed: 22 additions & 21 deletions

File tree

src/include/detail/graph/greedy_search.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <unordered_set>
4141
#include <vector>
4242

43+
#include "detail/linalg/vector.h"
4344
#include "scoring.h"
4445
#include "utils/fixed_min_heap.h"
4546

src/include/index/vamana_group.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class vamana_index_group : public base_index_group<index_type> {
194194
return {};
195195
}
196196
auto json = nlohmann::json::parse(metadata_.label_enumeration_str_);
197-
return json.get<std::unordered_map<std::string, uint32_t>>();
197+
return json.template get<std::unordered_map<std::string, uint32_t>>();
198198
}
199199

200200
// Set label enumeration from unordered_map, converting to JSON string
@@ -210,7 +210,7 @@ class vamana_index_group : public base_index_group<index_type> {
210210
return {};
211211
}
212212
auto json = nlohmann::json::parse(metadata_.start_nodes_str_);
213-
return json.get<std::unordered_map<uint32_t, uint64_t>>();
213+
return json.template get<std::unordered_map<uint32_t, uint64_t>>();
214214
}
215215

216216
// Set start nodes from unordered_map, converting to JSON string

src/include/index/vamana_index.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,11 @@ class vamana_index {
509509
filter_labels_ = filter_labels;
510510

511511
// Find start nodes (load-balanced) using find_medoid
512-
start_nodes_ = find_medoid(feature_vectors_, filter_labels_, distance_function_);
512+
// find_medoid returns std::unordered_map<uint32_t, size_t>, so convert to id_type
513+
auto start_nodes_size_t = find_medoid(feature_vectors_, filter_labels_, distance_function_);
514+
for (const auto& [label, node_id] : start_nodes_size_t) {
515+
start_nodes_[label] = static_cast<id_type>(node_id);
516+
}
513517

514518
// No single medoid in filtered mode
515519
} else {
@@ -540,9 +544,8 @@ class vamana_index {
540544
}
541545

542546
// NEW: Use filtered or unfiltered search based on mode
543-
std::vector<id_type> visited;
544547
if (filter_enabled_) {
545-
auto&& [_, __, v] = filtered_greedy_search_multi_start(
548+
auto&& [_, __, visited] = filtered_greedy_search_multi_start(
546549
graph_,
547550
feature_vectors_,
548551
filter_labels_,
@@ -553,24 +556,9 @@ class vamana_index {
553556
l_build_,
554557
distance_function_,
555558
true);
556-
visited = std::move(v);
557-
} else {
558-
auto&& [_, __, v] = ::best_first_O4 /*greedy_search*/ (
559-
graph_,
560-
feature_vectors_,
561-
medoid_,
562-
feature_vectors_[p],
563-
1,
564-
l_build_,
565-
true,
566-
distance_function_);
567-
visited = std::move(v);
568-
}
569559

570-
total_visited += visited.size();
560+
total_visited += visited.size();
571561

572-
// NEW: Use filtered or unfiltered prune based on mode
573-
if (filter_enabled_) {
574562
filtered_robust_prune(
575563
graph_,
576564
feature_vectors_,
@@ -581,6 +569,18 @@ class vamana_index {
581569
r_max_degree_,
582570
distance_function_);
583571
} else {
572+
auto&& [_, __, visited] = ::best_first_O4 /*greedy_search*/ (
573+
graph_,
574+
feature_vectors_,
575+
medoid_,
576+
feature_vectors_[p],
577+
1,
578+
l_build_,
579+
true,
580+
distance_function_);
581+
582+
total_visited += visited.size();
583+
584584
robust_prune(
585585
graph_,
586586
feature_vectors_,

0 commit comments

Comments
 (0)