{"record":{"id":"708688a98852a877","repo":"iflytek/astron-agent","slug":"ragflow-base-url-not-configured-in-environment-variables","errorCode":null,"errorMessage":"RAGFLOW_BASE_URL not configured in environment variables","messagePattern":"RAGFLOW_BASE_URL not configured in environment variables","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"core/knowledge/infra/ragflow/ragflow_client.py","lineNumber":60,"sourceCode":"_session_lock = asyncio.Lock()\n_rag_object = None\n_rag_object_config_key = None\n\n\ndef get_rag_object() -> Any:\n    \"\"\"\n    Get or create RAGFlow client instance with proper configuration loading\n    \"\"\"\n    global _rag_object, _rag_object_config_key\n    base_url = _config_value(\"base_url\", \"RAGFLOW_BASE_URL\", \"\")\n    api_key = _config_value(\"api_token\", \"RAGFLOW_API_TOKEN\", \"\")\n    config_key = (base_url, api_key)\n    if _rag_object is None or _rag_object_config_key != config_key:\n        if RAGFlow is None:\n            raise ImportError(\"ragflow_sdk is not available\")\n\n        if not base_url:\n            raise ValueError(\"RAGFLOW_BASE_URL not configured in environment variables\")\n        if not api_key:\n            raise ValueError(\n                \"RAGFLOW_API_TOKEN not configured in environment variables\"\n            )\n\n        _rag_object = RAGFlow(api_key=api_key, base_url=base_url)\n        _rag_object_config_key = config_key\n        print(f\"RAGFlow client initialized with base_url: {base_url}\")\n\n    return _rag_object\n\n\ndef _load_ragflow_config() -> Dict[str, Any]:\n    \"\"\"\n    Load RAGFlow configuration from constants module (with caching)\n\n    Returns:\n        Configuration dictionary","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/knowledge/infra/ragflow/ragflow_client.py#L42-L78","documentation":"get_rag_object requires RAGFLOW_BASE_URL to construct the RAGFlow SDK client. When the resolved base_url is empty (the 'base_url' config value and RAGFLOW_BASE_URL env var both unset/empty), a ValueError is raised so the SDK is never instantiated with a blank endpoint.","triggerScenarios":"First call to any RAGFlow operation (upload_document_to_dataset, retrieval, etc.) when the environment/config in the core/knowledge process has no RAGFLOW_BASE_URL, causing get_rag_object to fail before creating the client.","commonSituations":"Env var not set in docker-compose/helm values; .env file not loaded; variable defined under a wrong key or in the wrong service's environment; secret/configmap mount missing in the deployed pod.","solutions":["Set RAGFLOW_BASE_URL in the core/knowledge service environment (e.g. http://ragflow:9380) and restart","Check docker-compose/helm env/secret wiring for the knowledge service","Confirm with `env | grep RAGFLOW` inside the running container that the variable is present and non-empty","If RAGFlow is optional in this deployment, gate the code path on configuration instead of calling it unconditionally"],"exampleFix":"# before (docker-compose.yml, knowledge service)\n# environment: []\n# after\nenvironment:\n  - RAGFLOW_BASE_URL=http://ragflow:9380\n  - RAGFLOW_API_TOKEN=${RAGFLOW_API_TOKEN}","handlingStrategy":"validation","validationCode":"import os\ndef ragflow_env_ready() -> bool:\n    return bool(os.environ.get('RAGFLOW_BASE_URL', '').strip())","typeGuard":null,"tryCatchPattern":"try:\n    rag = get_rag_object()\nexcept ValueError as e:\n    if 'RAGFLOW_BASE_URL' in str(e):\n        logger.error('RAGFlow base URL missing: %s', e)\n        rag = None","preventionTips":["Set RAGFLOW_BASE_URL in deployment manifests before first use","Validate required RAGFlow env vars at service startup","Document required env vars in the deployment README/helm values"],"tags":["configuration","environment","ragflow"],"backgroundTag":"missing-env-var","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}