Skip to content

config

Config

Configuration class for the exact-matching workflow.

Loads settings from a YAML file and provides structured access via per-component settings dataclasses that are shared with other config classes (e.g. :class:ConfigDrugMapping).

Source code in src/ariadne/utils/config.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
class Config:
    """
    Configuration class for the exact-matching workflow.

    Loads settings from a YAML file and provides structured access via
    per-component settings dataclasses that are shared with other config
    classes (e.g. :class:`ConfigDrugMapping`).
    """

    verbatim_mapping: VerbatimMappingSettings
    term_cleaning: TermCleanerSettings
    vector_search: VectorSearchSettings
    llm_mapping: LlmMapperSettings
    hierarchy: HierarchySettings | None

    def __init__(self, filename: str = "config_condition_mapping.yaml"):
        """
        Initializes the Config object by loading settings from the specified YAML file.

        Args:
            filename: The path to the YAML configuration file. Defaults to
                        'config_condition_mapping.yaml' in the current working
                        directory or project root.
        """
        path = Path.cwd() / filename
        if not path.exists():
            path = get_project_root() / filename
            if not path.exists():
                raise FileNotFoundError(f"Could not find {filename} in {Path.cwd()} or project root.")
        with path.open("r", encoding="utf-8") as fh:
            raw = yaml.safe_load(fh) or {}

        self.verbatim_mapping = build_dataclass(VerbatimMappingSettings, raw.get("verbatim_mapping", {}))
        self.term_cleaning = build_dataclass(TermCleanerSettings, raw.get("term_cleaning", {}))
        self.vector_search = build_dataclass(VectorSearchSettings, raw.get("vector_search", {}))
        self.llm_mapping = build_dataclass(LlmMapperSettings, raw.get("llm_mapping", {}))
        hierarchy_raw = raw.get("hierarchy")
        self.hierarchy = build_dataclass(HierarchySettings, hierarchy_raw) if hierarchy_raw is not None else None

    def to_dict(self) -> Dict[str, Any]:
        result: Dict[str, Any] = {
            "verbatim_mapping": serialize_dataclass(self.verbatim_mapping),
            "term_cleaning": serialize_dataclass(self.term_cleaning),
            "vector_search": serialize_dataclass(self.vector_search),
            "llm_mapping": serialize_dataclass(self.llm_mapping),
        }
        if self.hierarchy is not None:
            result["hierarchy"] = serialize_dataclass(self.hierarchy)
        return result

__init__(filename='config_condition_mapping.yaml')

Initializes the Config object by loading settings from the specified YAML file.

Parameters:

Name Type Description Default
filename str

The path to the YAML configuration file. Defaults to 'config_condition_mapping.yaml' in the current working directory or project root.

'config_condition_mapping.yaml'
Source code in src/ariadne/utils/config.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
def __init__(self, filename: str = "config_condition_mapping.yaml"):
    """
    Initializes the Config object by loading settings from the specified YAML file.

    Args:
        filename: The path to the YAML configuration file. Defaults to
                    'config_condition_mapping.yaml' in the current working
                    directory or project root.
    """
    path = Path.cwd() / filename
    if not path.exists():
        path = get_project_root() / filename
        if not path.exists():
            raise FileNotFoundError(f"Could not find {filename} in {Path.cwd()} or project root.")
    with path.open("r", encoding="utf-8") as fh:
        raw = yaml.safe_load(fh) or {}

    self.verbatim_mapping = build_dataclass(VerbatimMappingSettings, raw.get("verbatim_mapping", {}))
    self.term_cleaning = build_dataclass(TermCleanerSettings, raw.get("term_cleaning", {}))
    self.vector_search = build_dataclass(VectorSearchSettings, raw.get("vector_search", {}))
    self.llm_mapping = build_dataclass(LlmMapperSettings, raw.get("llm_mapping", {}))
    hierarchy_raw = raw.get("hierarchy")
    self.hierarchy = build_dataclass(HierarchySettings, hierarchy_raw) if hierarchy_raw is not None else None

load_hierarchy_settings(filename='config_condition_mapping.yaml')

Load hierarchy settings from the top-level config file.

Parameters:

Name Type Description Default
filename str

Path to YAML config (CWD first, then project root).

'config_condition_mapping.yaml'
Source code in src/ariadne/utils/config.py
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def load_hierarchy_settings(filename: str = "config_condition_mapping.yaml") -> HierarchySettings:
    """Load hierarchy settings from the top-level config file.

    Args:
        filename: Path to YAML config (CWD first, then project root).
    """
    hierarchy = Config(filename).hierarchy
    if hierarchy is None:
        raise ValueError(
            "Config is missing the optional 'hierarchy' section. "
            "Add a 'hierarchy' block to run hierarchy workflows."
        )

    if not hierarchy.prompts.extraction or not hierarchy.prompts.extraction.strip():
        raise ValueError("hierarchy.prompts.extraction is empty in config.")
    if not hierarchy.prompts.selection or not hierarchy.prompts.selection.strip():
        raise ValueError("hierarchy.prompts.selection is empty in config.")

    return cast(HierarchySettings, hierarchy)