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
 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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
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
    hecate_search: HecateSearchSettings | None
    pgvector_search: PgvectorSearchSettings | None
    tfidf_search: TfidfSearchSettings | None
    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", {}))
        hecate_raw = raw.get("hecate_search")
        pgvector_raw = raw.get("pgvector_search")
        tfidf_raw = raw.get("tfidf_search")
        self.hecate_search = build_dataclass(HecateSearchSettings, hecate_raw) if hecate_raw is not None else None
        self.pgvector_search = build_dataclass(PgvectorSearchSettings, pgvector_raw) if pgvector_raw is not None else None
        self.tfidf_search = build_dataclass(TfidfSearchSettings, tfidf_raw) if tfidf_raw is not None else None
        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

        configured_searchers = [
            name
            for name, value in (
                ("hecate_search", self.hecate_search),
                ("pgvector_search", self.pgvector_search),
                ("tfidf_search", self.tfidf_search),
            )
            if value is not None
        ]
        if len(configured_searchers) != 1:
            raise ValueError(
                "Exactly one top-level vector search block must be configured: "
                "hecate_search, pgvector_search, or tfidf_search. "
                f"Configured: {configured_searchers or '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),
            "llm_mapping": serialize_dataclass(self.llm_mapping),
        }
        if self.hecate_search is not None:
            result["hecate_search"] = serialize_dataclass(self.hecate_search)
        if self.pgvector_search is not None:
            result["pgvector_search"] = serialize_dataclass(self.pgvector_search)
        if self.tfidf_search is not None:
            result["tfidf_search"] = serialize_dataclass(self.tfidf_search)
        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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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", {}))
    hecate_raw = raw.get("hecate_search")
    pgvector_raw = raw.get("pgvector_search")
    tfidf_raw = raw.get("tfidf_search")
    self.hecate_search = build_dataclass(HecateSearchSettings, hecate_raw) if hecate_raw is not None else None
    self.pgvector_search = build_dataclass(PgvectorSearchSettings, pgvector_raw) if pgvector_raw is not None else None
    self.tfidf_search = build_dataclass(TfidfSearchSettings, tfidf_raw) if tfidf_raw is not None else None
    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

    configured_searchers = [
        name
        for name, value in (
            ("hecate_search", self.hecate_search),
            ("pgvector_search", self.pgvector_search),
            ("tfidf_search", self.tfidf_search),
        )
        if value is not None
    ]
    if len(configured_searchers) != 1:
        raise ValueError(
            "Exactly one top-level vector search block must be configured: "
            "hecate_search, pgvector_search, or tfidf_search. "
            f"Configured: {configured_searchers or 'none'}."
        )