Skip to content

Commit

Permalink
Exp: Reduce prune list in build
Browse files Browse the repository at this point in the history
  • Loading branch information
Amey Varhade committed Oct 30, 2024
1 parent 85a0826 commit 7f99c6a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
5 changes: 4 additions & 1 deletion apps/build_memory_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace po = boost::program_options;
int main(int argc, char **argv)
{
std::string data_type, dist_fn, data_path, index_path_prefix, label_file, universal_label, label_type;
uint32_t num_threads, R, L, Lf, build_PQ_bytes;
uint32_t num_threads, R, L, Lf, build_PQ_bytes, reduce_prune;
float alpha;
bool use_pq_build, use_opq;

Expand Down Expand Up @@ -70,6 +70,9 @@ int main(int argc, char **argv)
program_options_utils::FILTERED_LBUILD);
optional_configs.add_options()("label_type", po::value<std::string>(&label_type)->default_value("uint"),
program_options_utils::LABEL_TYPE_DESCRIPTION);
optional_configs.add_options()("reduce_prune", po::value<uint32_t>(&reduce_prune)->default_value(0),"reduce_prune");

std::cout<<"reduce_prune: "<<reduce_prune<<std::endl;

// Merge required and optional parameters
desc.add(required_configs).add(optional_configs);
Expand Down
1 change: 1 addition & 0 deletions include/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define EXPAND_IF_FULL 0
#define DEFAULT_MAXC 750

//extern uint32_t reduce_prune;
namespace diskann
{

Expand Down
21 changes: 12 additions & 9 deletions src/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#define MAX_POINTS_FOR_USING_BITSET 10000000

//uint32_t reduce_prune = 0;

namespace diskann
{
// Initialize an index with metric m, load the data of type T with filename
Expand Down Expand Up @@ -1067,21 +1069,16 @@ void Index<T, TagT, LabelT>::occlude_list(const uint32_t location, std::vector<N
assert(result.size() == 0);
if (pool.size() > maxc)
pool.resize(maxc);
if (reduce_pool){
//diskann::cout<<"Reducing pool size from "<<pool.size()<<" to "<<(size_t)(0.5*pool.size())<<std::endl;
float k = 0.5;
size_t new_pool_size = (size_t)(k*pool.size());
if (new_pool_size > 0)
pool.resize(new_pool_size);
}

std::vector<float> &occlude_factor = scratch->occlude_factor();
// occlude_list can be called with the same scratch more than once by
// search_for_point_and_add_link through inter_insert.
occlude_factor.clear();
// Initialize occlude_factor to pool.size() many 0.0f values for correctness
occlude_factor.insert(occlude_factor.end(), pool.size(), 0.0f);

float cur_alpha = 1;
// Change the cur_alpha to alpha
float cur_alpha = alpha;
while (cur_alpha <= alpha && result.size() < degree)
{
// used for MIPS, where we store a value of eps in cur_alpha to
Expand Down Expand Up @@ -1330,8 +1327,14 @@ template <typename T, typename TagT, typename LabelT> void Index<T, TagT, LabelT

{
LockGuard guard(_locks[node]);
std::vector<uint32_t> reduced_pruned_list = pruned_list;

_graph_store->set_neighbours(node, pruned_list);
bool reduce_prune = true;
if (reduce_prune){
//std::cout<<"reduce prune"<<reduce_prune<<std::endl;
reduced_pruned_list.resize((uint32_t)_indexingRange/2);
}
_graph_store->set_neighbours(node, reduced_pruned_list);
assert(_graph_store->get_neighbours((location_t)node).size() <= _indexingRange);
}

Expand Down

0 comments on commit 7f99c6a

Please sign in to comment.