Skip to content

Commit

Permalink
introduce some constants config for hgraph (#168)
Browse files Browse the repository at this point in the history
- ef_construction & max_degree

Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
  • Loading branch information
LHT129 authored Dec 3, 2024
1 parent 339cab3 commit 28ad573
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
4 changes: 3 additions & 1 deletion examples/cpp/simple_hgraph_sq8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ main(int argc, char** argv) {
"metric_type": "l2",
"dim": 128,
"index_param": {
"base_quantization_type": "sq8"
"base_quantization_type": "sq8",
"max_degree": 26,
"ef_construction": 100
}
}
)";
Expand Down
1 change: 1 addition & 0 deletions include/vsag/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,6 @@ extern const char* const SERIALIZE_VERSION;
extern const char* const HGRAPH_USE_REORDER;
extern const char* const HGRAPH_BASE_QUANTIZATION_TYPE;
extern const char* const HGRAPH_GRAPH_MAX_DEGREE;
extern const char* const HGRAPH_BUILD_EF_CONSTRUCTION;

} // namespace vsag
1 change: 1 addition & 0 deletions src/constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,6 @@ const char* const SERIALIZE_VERSION = "VERSION";
const char* const HGRAPH_USE_REORDER = HGRAPH_USE_REORDER_KEY;
const char* const HGRAPH_BASE_QUANTIZATION_TYPE = "base_quantization_type";
const char* const HGRAPH_GRAPH_MAX_DEGREE = "max_degree";
const char* const HGRAPH_BUILD_EF_CONSTRUCTION = "ef_construction";

}; // namespace vsag
10 changes: 10 additions & 0 deletions src/index/hgraph_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ HGraphIndex::Init() {
this->pool_ =
std::make_shared<hnswlib::VisitedListPool>(this->bottom_graph_->MaxCapacity(), allocator_);

if (this->index_param_.contains(BUILD_PARAMS_KEY)) {
auto& build_params = this->index_param_[BUILD_PARAMS_KEY];
if (build_params.contains(BUILD_EF_CONSTRUCTION)) {
this->ef_construct_ = build_params[BUILD_EF_CONSTRUCTION];
}
if (build_params.contains(BUILD_THREAD_COUNT)) {
this->build_thread_count_ = build_params[BUILD_THREAD_COUNT];
}
}

if (this->build_thread_count_ > 1) {
this->build_pool_ = std::make_unique<progschj::ThreadPool>(this->build_thread_count_);
}
Expand Down
7 changes: 4 additions & 3 deletions src/index/hgraph_zparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ namespace vsag {
const std::unordered_map<std::string, std::vector<std::string>> HGraphParameters::EXTERNAL_MAPPING =
{{HGRAPH_USE_REORDER, {HGRAPH_USE_REORDER_KEY}},
{HGRAPH_BASE_QUANTIZATION_TYPE, {HGRAPH_BASE_CODES_KEY, QUANTIZATION_TYPE_KEY}},
{HGRAPH_GRAPH_MAX_DEGREE, {HGRAPH_GRAPH_KEY, GRAPH_PARAMS_KEY, GRAPH_PARAM_MAX_DEGREE}}};
{HGRAPH_GRAPH_MAX_DEGREE, {HGRAPH_GRAPH_KEY, GRAPH_PARAMS_KEY, GRAPH_PARAM_MAX_DEGREE}},
{HGRAPH_BUILD_EF_CONSTRUCTION, {BUILD_PARAMS_KEY, BUILD_EF_CONSTRUCTION}}};

HGraphParameters::HGraphParameters(JsonType& hgraph_param, const IndexCommonParam& common_param)
: common_param_(common_param) {
Expand Down Expand Up @@ -119,8 +120,8 @@ const std::string HGraphParameters::DEFAULT_HGRAPH_PARAMS = format_map(
"{QUANTIZATION_TYPE_KEY}": "{QUANTIZATION_TYPE_VALUE_SQ8}",
"{QUANTIZATION_PARAMS_KEY}": {}
},
"build_params": {
"ef_construction": 400,
"{BUILD_PARAMS_KEY}": {
"{BUILD_EF_CONSTRUCTION}": 400,
"{BUILD_THREAD_COUNT}": 5
}
})",
Expand Down
4 changes: 4 additions & 0 deletions src/inner_string_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ const char* const GRAPH_PARAMS_KEY = "graph_params";
const char* const GRAPH_PARAM_MAX_DEGREE = "max_degree";
const char* const GRAPH_PARAM_INIT_MAX_CAPACITY = "init_capacity";

const char* const BUILD_PARAMS_KEY = "build_params";
const char* const BUILD_THREAD_COUNT = "build_thread_count";
const char* const BUILD_EF_CONSTRUCTION = "ef_construction";

const std::unordered_map<std::string, std::string> DEFAULT_MAP = {
{"HGRAPH_USE_REORDER_KEY", HGRAPH_USE_REORDER_KEY},
Expand All @@ -75,7 +77,9 @@ const std::unordered_map<std::string, std::string> DEFAULT_MAP = {
{"GRAPH_PARAMS_KEY", GRAPH_PARAMS_KEY},
{"GRAPH_PARAM_MAX_DEGREE", GRAPH_PARAM_MAX_DEGREE},
{"GRAPH_PARAM_INIT_MAX_CAPACITY", GRAPH_PARAM_INIT_MAX_CAPACITY},
{"BUILD_PARAMS_KEY", BUILD_PARAMS_KEY},
{"BUILD_THREAD_COUNT", BUILD_THREAD_COUNT},
{"BUILD_EF_CONSTRUCTION", BUILD_EF_CONSTRUCTION},
};

} // namespace vsag

0 comments on commit 28ad573

Please sign in to comment.