diff --git a/min_vec/configs/parameters_validator.py b/min_vec/configs/parameters_validator.py index 6470869..ecf3912 100644 --- a/min_vec/configs/parameters_validator.py +++ b/min_vec/configs/parameters_validator.py @@ -24,6 +24,14 @@ def check_configs(self, configs: dict, update_configs_dict: dict): self.logger.warning(f"The database configuration {key} has been set to {value}, " f"the new value {update_configs_dict[key]} will be ignored.") + for key, value in update_configs_dict.items(): + if key not in configs: + self.logger.warning(f"The database configuration {key} is not set, " + f"and it will be set to {value}.") + configs[key] = value + + return configs + def load_configs(self, configs_json: Path): """Load the configurations.""" try: @@ -39,6 +47,8 @@ def save_configs(self, configs_json: Path, configs: dict): try: with open(configs_json, 'w') as f: json.dump(configs, f) + + return configs except (PermissionError, OSError) as e: self.logger.error(f"Failed to save the MinVectorDB configurations.") raise e @@ -46,6 +56,9 @@ def save_configs(self, configs_json: Path, configs: dict): def __call__(self, func): @wraps(func) def wrapper(*args, **kwargs): + # first parameter is self + self_instance = args[0] + kwargs = generate_function_kwargs(func, *args, **kwargs) dir_path = Path(kwargs.get("database_path")) @@ -66,11 +79,11 @@ def wrapper(*args, **kwargs): configs_json = self.database_path_parent / Path('configs.json') if first_create or not configs_json.exists(): - self.save_configs(configs_json, update_configs_dict) + final_configs = self.save_configs(configs_json, update_configs_dict) else: existing_configs = self.load_configs(configs_json) - self.check_configs(existing_configs, update_configs_dict) + final_configs = self.check_configs(existing_configs, update_configs_dict) - return func(*args, **kwargs) + return func(self_instance, **final_configs) return wrapper