From 046f0bba746242d94d46ab446c6c7b5b29991404 Mon Sep 17 00:00:00 2001 From: lgphone Date: Thu, 20 Mar 2025 10:45:40 +0800 Subject: [PATCH] Fix: optimize setting config initialization to resolve Minio initialization error (#6282) ### What problem does this PR solve? Optimize setting configuration initialization to resolve Minio initialization error caused by using a specific storage. Reproduction Scenario: Using Aliyun OSS as the backend storage with the STORAGE_IMPL environment variable set to OSS. The service_conf.yaml.template configuration file contains OSS-related configurations, while other storage configurations are commented out. When the service starts, it still attempts to initialize the Minio storage. Since there is no Minio configuration in service_conf.yaml.template, it results in an error due to the missing configuration file. Optimization Measures: Automatically determine the required initialization configuration based on the environment variable. Do not initialize configurations for unused resources. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- rag/settings.py | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/rag/settings.py b/rag/settings.py index d1c32e6bf..7fa497c16 100644 --- a/rag/settings.py +++ b/rag/settings.py @@ -21,12 +21,32 @@ from api.utils.file_utils import get_project_base_directory # Server RAG_CONF_PATH = os.path.join(get_project_base_directory(), "conf") -ES = get_base_config("es", {}) -INFINITY = get_base_config("infinity", {"uri": "infinity:23817"}) -AZURE = get_base_config("azure", {}) -S3 = get_base_config("s3", {}) -MINIO = decrypt_database_config(name="minio") -OSS = get_base_config("oss", {}) +# Get storage type and document engine from system environment variables +STORAGE_IMPL_TYPE = os.getenv('STORAGE_IMPL', 'MINIO') +DOC_ENGINE = os.getenv('DOC_ENGINE', 'elasticsearch') + +ES = {} +INFINITY = {} +AZURE = {} +S3 = {} +MINIO = {} +OSS = {} + +# Initialize the selected configuration data based on environment variables to solve the problem of initialization errors due to lack of configuration +if DOC_ENGINE == 'elasticsearch': + ES = get_base_config("es", {}) +elif DOC_ENGINE == 'infinity': + INFINITY = get_base_config("infinity", {"uri": "infinity:23817"}) + +if STORAGE_IMPL_TYPE in ['AZURE_SPN', 'AZURE_SAS']: + AZURE = get_base_config("azure", {}) +elif STORAGE_IMPL_TYPE == 'AWS_S3': + S3 = get_base_config("s3", {}) +elif STORAGE_IMPL_TYPE == 'MINIO': + MINIO = decrypt_database_config(name="minio") +elif STORAGE_IMPL_TYPE == 'OSS': + OSS = get_base_config("oss", {}) + try: REDIS = decrypt_database_config(name="redis") except Exception: