Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
add more logs to HNSW (#760)
Browse files Browse the repository at this point in the history
Signed-off-by: cqy123456 <[email protected]>
  • Loading branch information
cqy123456 authored Mar 22, 2023
1 parent 66e941b commit a7cc1f7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion knowhere/index/vector_index/IndexHNSW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "common/Exception.h"
#include "common/Log.h"
#include "common/Timer.h"
#include "common/Utils.h"
#include "hnswlib/hnswlib/hnswalg.h"
#include "index/vector_index/adapter/VectorAdapter.h"
Expand Down Expand Up @@ -63,6 +64,9 @@ IndexHNSW::Load(const BinarySet& index_binary) {
} catch (std::exception& e) {
KNOWHERE_THROW_MSG(e.what());
}
LOG_KNOWHERE_INFO_ << "Loaded HNSW index. #points num:" << index_->max_elements_ << " #M:" << index_->M_
<< " #max level:" << index_->maxlevel_ << " #ef_construction:" << index_->ef_construction_
<< " #dim:" << *(size_t*)(index_->space_->get_dist_func_param());
}

void
Expand Down Expand Up @@ -94,12 +98,17 @@ IndexHNSW::AddWithoutIds(const DatasetPtr& dataset_ptr, const Config& config) {

GET_TENSOR_DATA(dataset_ptr)
utils::SetBuildOmpThread(config);
knowhere::TimeRecorder build_time("Building HNSW cost");
index_->addPoint(p_data, 0);

#pragma omp parallel for
for (int i = 1; i < rows; ++i) {
index_->addPoint((reinterpret_cast<const float*>(p_data) + Dim() * i), i);
}
build_time.RecordSection("");
LOG_KNOWHERE_INFO_ << "HNSW built with #points num:" << index_->max_elements_ << " #M:" << index_->M_
<< " #max level:" << index_->maxlevel_ << " #ef_construction:" << index_->ef_construction_
<< " #dim:" << *(size_t*)(index_->space_->get_dist_func_param());
}

DatasetPtr
Expand Down Expand Up @@ -289,7 +298,7 @@ IndexHNSW::QueryByRangeImpl(int64_t n, const float* xq, float*& distances, int64

float radius = GetMetaRadius(config);
bool range_filter_exist = CheckKeyInConfig(config, meta::RANGE_FILTER);
float range_filter = range_filter_exist ? GetMetaRangeFilter(config) : (1.0/0.0);
float range_filter = range_filter_exist ? GetMetaRangeFilter(config) : (1.0 / 0.0);
bool is_ip = (index_->metric_type_ == 1); // L2: 0, InnerProduct: 1

std::vector<std::vector<int64_t>> result_id_array(n);
Expand Down

0 comments on commit a7cc1f7

Please sign in to comment.