-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor param to replace JsonType internal
Signed-off-by: LHT129 <[email protected]>
- Loading branch information
Showing
82 changed files
with
1,656 additions
and
620 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
|
||
// Copyright 2024-present the vsag project | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "hgraph_parameter.h" | ||
|
||
#include <fmt/format-inl.h> | ||
|
||
#include "data_cell/graph_interface_parameter.h" | ||
#include "inner_string_params.h" | ||
|
||
namespace vsag { | ||
|
||
HGraphParameter::HGraphParameter(const JsonType& json) : HGraphParameter() { | ||
this->FromJson(json); | ||
} | ||
|
||
HGraphParameter::HGraphParameter() : name_(INDEX_TYPE_HGRAPH) { | ||
} | ||
|
||
void | ||
HGraphParameter::FromJson(const JsonType& json) { | ||
CHECK_ARGUMENT(json.contains(HGRAPH_USE_REORDER_KEY), | ||
fmt::format("hgraph parameters must contains {}", HGRAPH_USE_REORDER_KEY)); | ||
this->use_reorder_ = json[HGRAPH_USE_REORDER_KEY]; | ||
|
||
CHECK_ARGUMENT(json.contains(HGRAPH_BASE_CODES_KEY), | ||
fmt::format("hgraph parameters must contains {}", HGRAPH_BASE_CODES_KEY)); | ||
const auto& base_codes_json = json[HGRAPH_BASE_CODES_KEY]; | ||
this->base_codes_param_ = std::make_shared<FlattenDataCellParameter>(); | ||
this->base_codes_param_->FromJson(base_codes_json); | ||
|
||
if (use_reorder_) { | ||
CHECK_ARGUMENT(json.contains(HGRAPH_PRECISE_CODES_KEY), | ||
fmt::format("hgraph parameters must contains {}", HGRAPH_PRECISE_CODES_KEY)); | ||
const auto& precise_codes_json = json[HGRAPH_PRECISE_CODES_KEY]; | ||
this->precise_codes_param_ = std::make_shared<FlattenDataCellParameter>(); | ||
this->precise_codes_param_->FromJson(precise_codes_json); | ||
} | ||
|
||
CHECK_ARGUMENT(json.contains(HGRAPH_GRAPH_KEY), | ||
fmt::format("hgraph parameters must contains {}", HGRAPH_GRAPH_KEY)); | ||
const auto& graph_json = json[HGRAPH_GRAPH_KEY]; | ||
this->bottom_graph_param_ = GraphInterfaceParameter::GetGraphParameterByJson(graph_json); | ||
|
||
if (json.contains(BUILD_PARAMS_KEY)) { | ||
auto& build_params = json[BUILD_PARAMS_KEY]; | ||
if (build_params.contains(BUILD_EF_CONSTRUCTION)) { | ||
this->ef_construction_ = build_params[BUILD_EF_CONSTRUCTION]; | ||
} | ||
if (build_params.contains(BUILD_THREAD_COUNT)) { | ||
this->build_thread_count_ = build_params[BUILD_THREAD_COUNT]; | ||
} | ||
} | ||
} | ||
|
||
JsonType | ||
HGraphParameter::ToJson() { | ||
JsonType json; | ||
json["type"] = INDEX_TYPE_HGRAPH; | ||
|
||
json[HGRAPH_USE_REORDER_KEY] = this->use_reorder_; | ||
json[HGRAPH_BASE_CODES_KEY] = this->base_codes_param_->ToJson(); | ||
if (use_reorder_) { | ||
json[HGRAPH_PRECISE_CODES_KEY] = this->precise_codes_param_->ToJson(); | ||
} | ||
json[HGRAPH_GRAPH_KEY] = this->bottom_graph_param_->ToJson(); | ||
|
||
json[BUILD_PARAMS_KEY][BUILD_EF_CONSTRUCTION] = this->ef_construction_; | ||
json[BUILD_PARAMS_KEY][BUILD_THREAD_COUNT] = this->build_thread_count_; | ||
return json; | ||
} | ||
|
||
} // namespace vsag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
// Copyright 2024-present the vsag project | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include "data_cell/flatten_datacell_parameter.h" | ||
#include "data_cell/graph_interface_parameter.h" | ||
#include "parameter.h" | ||
|
||
namespace vsag { | ||
|
||
class HGraphParameter : public Parameter { | ||
public: | ||
explicit HGraphParameter(const JsonType& json); | ||
|
||
HGraphParameter(); | ||
|
||
void | ||
FromJson(const JsonType& json) override; | ||
|
||
JsonType | ||
ToJson() override; | ||
|
||
public: | ||
FlattenDataCellParamPtr base_codes_param_{nullptr}; | ||
FlattenDataCellParamPtr precise_codes_param_{nullptr}; | ||
GraphInterfaceParamPtr bottom_graph_param_{nullptr}; | ||
|
||
bool use_reorder_{false}; | ||
uint64_t ef_construction_{400}; | ||
uint64_t build_thread_count_{100}; | ||
|
||
std::string name_; | ||
}; | ||
|
||
} // namespace vsag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
// Copyright 2024-present the vsag project | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "flatten_datacell_parameter.h" | ||
|
||
#include <fmt/format-inl.h> | ||
|
||
#include "inner_string_params.h" | ||
|
||
namespace vsag { | ||
FlattenDataCellParameter::FlattenDataCellParameter() { | ||
} | ||
|
||
void | ||
FlattenDataCellParameter::FromJson(const JsonType& json) { | ||
CHECK_ARGUMENT(json.contains(IO_PARAMS_KEY), | ||
fmt::format("flatten interface parameters must contains {}", IO_PARAMS_KEY)); | ||
this->io_parameter_ = IOParameter::GetIOParameterByJson(json[IO_PARAMS_KEY]); | ||
|
||
CHECK_ARGUMENT( | ||
json.contains(QUANTIZATION_PARAMS_KEY), | ||
fmt::format("flatten interface parameters must contains {}", QUANTIZATION_PARAMS_KEY)); | ||
this->quantizer_parameter_ = | ||
QuantizerParameter::GetQuantizerParameterByJson(json[QUANTIZATION_PARAMS_KEY]); | ||
} | ||
|
||
JsonType | ||
FlattenDataCellParameter::ToJson() { | ||
JsonType json; | ||
json[IO_PARAMS_KEY] = this->io_parameter_->ToJson(); | ||
json[QUANTIZATION_PARAMS_KEY] = this->quantizer_parameter_->ToJson(); | ||
return json; | ||
} | ||
} // namespace vsag |
Oops, something went wrong.