Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/config/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,19 @@ def __init__(self, config_file: Optional[str] = None):
"""Initialize configuration manager.

Args:
config_file: Path to configuration file. Defaults to 'config.yaml' in project root.
config_file: Path to configuration file. If None, resolved lazily
from OPENRAG_CONFIG_PATH on first access.
"""
if config_file:
self.config_file = Path(config_file)
else:
from config.paths import get_config_file_path
self.config_file = Path(get_config_file_path())
self._config_file: Optional[Path] = Path(config_file) if config_file else None
self._config: Optional[OpenRAGConfig] = None


@property
def config_file(self) -> Path:
"""Lazily resolve config file path on first access."""
if self._config_file is None:
from config.paths import get_config_file_path
self._config_file = Path(get_config_file_path())
return self._config_file

def load_config(self) -> OpenRAGConfig:
"""Load configuration from environment variables and config file.
Expand Down
12 changes: 11 additions & 1 deletion src/config/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"""

import os

from utils.logging_config import get_logger
logger = get_logger(__name__)

# ---------------------------------------------------------------------------
# Documents directory
Expand All @@ -17,6 +18,7 @@ def get_documents_path() -> str:
Environment variable: OPENRAG_DOCUMENTS_PATH
Default: ``openrag-documents`` (relative to the working directory)
"""
logger.debug(f"OPENRAG_DOCUMENTS_PATH: {os.getenv('OPENRAG_DOCUMENTS_PATH')}")
return os.getenv("OPENRAG_DOCUMENTS_PATH") or "openrag-documents"


Expand All @@ -29,6 +31,7 @@ def get_keys_path() -> str:
Environment variable: OPENRAG_KEYS_PATH
Default: ``keys`` (relative to the working directory)
"""
logger.debug(f"OPENRAG_KEYS_PATH: {os.getenv('OPENRAG_KEYS_PATH')}")
return os.getenv("OPENRAG_KEYS_PATH") or "keys"


Expand All @@ -41,6 +44,7 @@ def get_flows_path() -> str:
Environment variable: OPENRAG_FLOWS_PATH
Default: ``flows`` (relative to the working directory)
"""
logger.debug(f"OPENRAG_FLOWS_PATH: {os.getenv('OPENRAG_FLOWS_PATH')}")
return os.getenv("OPENRAG_FLOWS_PATH") or "flows"


Expand All @@ -50,6 +54,7 @@ def get_flows_backup_path() -> str:
Environment variable: OPENRAG_FLOWS_BACKUP_PATH
Default: ``<flows_path>/backup``
"""
logger.debug(f"OPENRAG_FLOWS_BACKUP_PATH: {os.getenv('OPENRAG_FLOWS_BACKUP_PATH')}")
return os.getenv("OPENRAG_FLOWS_BACKUP_PATH") or os.path.join(get_flows_path(), "backup")


Expand All @@ -62,11 +67,14 @@ def get_config_path() -> str:
Environment variable: OPENRAG_CONFIG_PATH
Default: ``config`` (relative to the working directory)
"""

logger.debug(f"OPENRAG_CONFIG_PATH: {os.getenv('OPENRAG_CONFIG_PATH')}")
return os.getenv("OPENRAG_CONFIG_PATH") or "config"


def get_config_file_path() -> str:
"""Return the full path to the config.yaml file."""
logger.debug(f"get_config_file_path: {os.path.join(get_config_path(), 'config.yaml')}")
return os.path.join(get_config_path(), "config.yaml")
Comment on lines +77 to 78
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_config_file_path() currently calls get_config_path() twice (once inside the debug f-string and again for the return). That duplicates env lookups and will also emit duplicate debug logs. Please compute the config dir/path once in a local variable and reuse it for both logging and the return value.

Suggested change
logger.debug(f"get_config_file_path: {os.path.join(get_config_path(), 'config.yaml')}")
return os.path.join(get_config_path(), "config.yaml")
config_path = get_config_path()
logger.debug(f"get_config_file_path: {os.path.join(config_path, 'config.yaml')}")
return os.path.join(config_path, "config.yaml")

Copilot uses AI. Check for mistakes.


Expand All @@ -79,6 +87,7 @@ def get_data_path() -> str:
Environment variable: OPENRAG_DATA_PATH
Default: ``data`` (relative to the working directory)
"""
logger.debug(f"OPENRAG_DATA_PATH: {os.getenv('OPENRAG_DATA_PATH')}")
return os.getenv("OPENRAG_DATA_PATH") or "data"


Expand All @@ -90,4 +99,5 @@ def get_data_file(filename: str) -> str:
get_data_file("conversations.json")
# → "data/conversations.json" (or $OPENRAG_DATA_PATH/conversations.json)
"""
logger.debug(f"get_data_file: {os.path.join(get_data_path(), filename)}")
return os.path.join(get_data_path(), filename)
Comment on lines +102 to 103
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_data_file() calls get_data_path() twice (once for the debug message and once for the return), which repeats env reads and can produce duplicate debug output. Please store data_path = get_data_path() once and reuse it.

Suggested change
logger.debug(f"get_data_file: {os.path.join(get_data_path(), filename)}")
return os.path.join(get_data_path(), filename)
data_path = get_data_path()
logger.debug(f"get_data_file: {os.path.join(data_path, filename)}")
return os.path.join(data_path, filename)

Copilot uses AI. Check for mistakes.
14 changes: 9 additions & 5 deletions src/config/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from config.paths import get_flows_path
import asyncio
import os
import threading
Expand All @@ -8,6 +7,15 @@
import httpx
from agentd.patch import patch_openai_with_mcp
from dotenv import load_dotenv

from dotenv import load_dotenv
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

load_dotenv is imported twice in a row. Please remove the duplicate import (keep only one) so the module import section stays clean and deterministic.

Suggested change
from dotenv import load_dotenv

Copilot uses AI. Check for mistakes.
load_dotenv(override=False)
load_dotenv("../", override=False)

from config.paths import get_flows_path
from utils.env_utils import get_env_int, get_env_float

import httpx
Comment on lines +11 to +18
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are multiple duplicated imports introduced here (e.g., get_env_int/get_env_float and httpx are imported twice). This will trip linters and makes the import ordering harder to reason about; please deduplicate and keep a single import for each symbol/module.

Suggested change
from dotenv import load_dotenv
load_dotenv(override=False)
load_dotenv("../", override=False)
from config.paths import get_flows_path
from utils.env_utils import get_env_int, get_env_float
import httpx
load_dotenv(override=False)
load_dotenv("../", override=False)
from config.paths import get_flows_path

Copilot uses AI. Check for mistakes.
from openai import AsyncOpenAI
from opensearchpy import AsyncOpenSearch
from opensearchpy._async.http_aiohttp import AIOHttpConnection
Expand All @@ -16,12 +24,8 @@
from utils.container_utils import get_container_host
from utils.embedding_fields import build_knn_vector_field
from utils.logging_config import get_logger
# Import configuration manager
from .config_manager import config_manager

load_dotenv(override=False)
load_dotenv("../", override=False)

logger = get_logger(__name__)

# Environment variables
Expand Down
Loading