Skip to content

Commit

Permalink
refactor hgraph_params to solve static value leak
Browse files Browse the repository at this point in the history
Signed-off-by: LHT129 <[email protected]>
  • Loading branch information
LHT129 committed Dec 18, 2024
1 parent cdc79d0 commit 1619268
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 53 deletions.
99 changes: 50 additions & 49 deletions src/index/hgraph_zparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,58 @@

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_BUILD_EF_CONSTRUCTION, {BUILD_PARAMS_KEY, BUILD_EF_CONSTRUCTION}}};
static const std::unordered_map<std::string, std::vector<std::string>> 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_BUILD_EF_CONSTRUCTION, {BUILD_PARAMS_KEY, BUILD_EF_CONSTRUCTION}}};

static const std::string DEFAULT_HGRAPH_PARAMS_STR =
R"(
{
"{HGRAPH_USE_REORDER_KEY}": false,
"{HGRAPH_GRAPH_KEY}": {
"{IO_TYPE_KEY}": "{IO_TYPE_VALUE_BLOCK_MEMORY_IO}",
"{IO_PARAMS_KEY}": {
"{BLOCK_IO_BLOCK_SIZE_KEY}": {DEFAULT_BLOCK_SIZE}
},
"type": "nsw",
"{GRAPH_PARAMS_KEY}": {
"{GRAPH_PARAM_MAX_DEGREE}": 64,
"{GRAPH_PARAM_INIT_MAX_CAPACITY}": 100
}
},
"{HGRAPH_BASE_CODES_KEY}": {
"{IO_TYPE_KEY}": "{IO_TYPE_VALUE_BLOCK_MEMORY_IO}",
"{IO_PARAMS_KEY}": {
"{BLOCK_IO_BLOCK_SIZE_KEY}": {DEFAULT_BLOCK_SIZE}
},
"codes_type": "flatten_codes",
"codes_param": {},
"{QUANTIZATION_TYPE_KEY}": "{QUANTIZATION_TYPE_VALUE_PQ}",
"{QUANTIZATION_PARAMS_KEY}": {
"subspace": 64,
"nbits": 8
}
},
"precise_codes": {
"{IO_TYPE_KEY}": "aio_ssd",
"{IO_PARAMS_KEY}": {},
"codes_type": "flatten_codes",
"codes_param": {},
"{QUANTIZATION_TYPE_KEY}": "{QUANTIZATION_TYPE_VALUE_SQ8}",
"{QUANTIZATION_PARAMS_KEY}": {}
},
"{BUILD_PARAMS_KEY}": {
"{BUILD_EF_CONSTRUCTION}": 400,
"{BUILD_THREAD_COUNT}": 100
}
})";

HGraphParameters::HGraphParameters(JsonType& hgraph_param, const IndexCommonParam& common_param)
: common_param_(common_param) {
: common_param_(common_param),
default_hgraph_params_(format_map(DEFAULT_HGRAPH_PARAMS_STR, DEFAULT_MAP)) {
this->str_ = default_hgraph_params_;
this->check_common_param();
this->init_by_options();
this->refresh_json_by_string();
Expand Down Expand Up @@ -93,49 +137,6 @@ HGraphParameters::init_by_options() {
this->str_ = format_map(this->str_, option_map);
}

const std::string HGraphParameters::DEFAULT_HGRAPH_PARAMS = format_map(
R"(
{
"{HGRAPH_USE_REORDER_KEY}": false,
"{HGRAPH_GRAPH_KEY}": {
"{IO_TYPE_KEY}": "{IO_TYPE_VALUE_BLOCK_MEMORY_IO}",
"{IO_PARAMS_KEY}": {
"{BLOCK_IO_BLOCK_SIZE_KEY}": {DEFAULT_BLOCK_SIZE}
},
"type": "nsw",
"{GRAPH_PARAMS_KEY}": {
"{GRAPH_PARAM_MAX_DEGREE}": 64,
"{GRAPH_PARAM_INIT_MAX_CAPACITY}": 100
}
},
"{HGRAPH_BASE_CODES_KEY}": {
"{IO_TYPE_KEY}": "{IO_TYPE_VALUE_BLOCK_MEMORY_IO}",
"{IO_PARAMS_KEY}": {
"{BLOCK_IO_BLOCK_SIZE_KEY}": {DEFAULT_BLOCK_SIZE}
},
"codes_type": "flatten_codes",
"codes_param": {},
"{QUANTIZATION_TYPE_KEY}": "{QUANTIZATION_TYPE_VALUE_PQ}",
"{QUANTIZATION_PARAMS_KEY}": {
"subspace": 64,
"nbits": 8
}
},
"precise_codes": {
"{IO_TYPE_KEY}": "aio_ssd",
"{IO_PARAMS_KEY}": {},
"codes_type": "flatten_codes",
"codes_param": {},
"{QUANTIZATION_TYPE_KEY}": "{QUANTIZATION_TYPE_VALUE_SQ8}",
"{QUANTIZATION_PARAMS_KEY}": {}
},
"{BUILD_PARAMS_KEY}": {
"{BUILD_EF_CONSTRUCTION}": 400,
"{BUILD_THREAD_COUNT}": 100
}
})",
DEFAULT_MAP);

HGraphSearchParameters
HGraphSearchParameters::FromJson(const std::string& json_string) {
JsonType params = JsonType::parse(json_string);
Expand Down
6 changes: 2 additions & 4 deletions src/index/hgraph_zparameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,11 @@ class HGraphParameters {
private:
JsonType json_;

std::string str_{DEFAULT_HGRAPH_PARAMS};
std::string str_;

const IndexCommonParam common_param_;

static const std::string DEFAULT_HGRAPH_PARAMS;

static const std::unordered_map<std::string, std::vector<std::string>> EXTERNAL_MAPPING;
const std::string default_hgraph_params_;
};

class HGraphSearchParameters {
Expand Down

0 comments on commit 1619268

Please sign in to comment.