Initializer

This module contains functionality related to the the initializer module for augmentation.bootstrap.

Initializer

AugmentationInitializer

Bases: EmbeddingInitializer

Initializer for the augmentation process.

Extends the EmbeddingInitializer to set up the environment for augmentation tasks. This initializer is responsible for loading the required configuration and registering all necessary components with the dependency injection container.

Multiple components are used in the embedding, augmentation and evaluation processes. To avoid code duplication, this initializer is used to bind the components to the injector. It is intended to be subclassed by the specific initializers for each process.

Source code in src/augmentation/bootstrap/initializer.py
 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
113
114
115
116
117
118
119
class AugmentationInitializer(EmbeddingInitializer):
    """Initializer for the augmentation process.

    Extends the EmbeddingInitializer to set up the environment for augmentation tasks.
    This initializer is responsible for loading the required configuration and
    registering all necessary components with the dependency injection container.

    Multiple components are used in the embedding, augmentation and evaluation processes.
    To avoid code duplication, this initializer is used to bind the components to the injector.
    It is intended to be subclassed by the specific initializers for each process.
    """

    def __init__(
        self,
        configuration_class: Type[
            BaseConfiguration
        ] = AugmentationConfiguration,
        package_loader: BasePackageLoader = AugmentationPackageLoader(),
    ):
        """Initialize the AugmentationInitializer.

        Args:
            configuration_class: The configuration class to use for loading settings.
                                Defaults to AugmentationConfiguration.
            package_loader: Package loader instance responsible for loading required packages.
                           Defaults to a new AugmentationPackageLoader instance.
        """
        super().__init__(
            configuration_class=configuration_class,
            package_loader=package_loader,
        )
        self._initialize_default_prompt()

    def _initialize_default_prompt(self) -> None:
        """
        Initialize the default prompt templates for the augmentation process managed by Langfuse.
        """
        configuration = self.get_configuration()
        langfuse_prompt_service = LangfusePromptServiceFactory.create(
            configuration=configuration.augmentation.langfuse
        )

        langfuse_prompt_service.create_prompt_if_not_exists(
            prompt_name="default_condense_prompt",
            prompt_template=DEFAULT_CONDENSE_PROMPT_TEMPLATE,
        )

        langfuse_prompt_service.create_prompt_if_not_exists(
            prompt_name="default_context_prompt",
            prompt_template=DEFAULT_CONTEXT_PROMPT_TEMPLATE,
        )

        langfuse_prompt_service.create_prompt_if_not_exists(
            prompt_name="default_context_refine_prompt",
            prompt_template=DEFAULT_CONTEXT_REFINE_PROMPT_TEMPLATE,
        )

        langfuse_prompt_service.create_prompt_if_not_exists(
            prompt_name="default_system_prompt",
            prompt_template="",
        )

__init__(configuration_class=AugmentationConfiguration, package_loader=AugmentationPackageLoader())

Initialize the AugmentationInitializer.

Parameters:
  • configuration_class (Type[BaseConfiguration], default: AugmentationConfiguration ) –

    The configuration class to use for loading settings. Defaults to AugmentationConfiguration.

  • package_loader (BasePackageLoader, default: AugmentationPackageLoader() ) –

    Package loader instance responsible for loading required packages. Defaults to a new AugmentationPackageLoader instance.

Source code in src/augmentation/bootstrap/initializer.py
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
def __init__(
    self,
    configuration_class: Type[
        BaseConfiguration
    ] = AugmentationConfiguration,
    package_loader: BasePackageLoader = AugmentationPackageLoader(),
):
    """Initialize the AugmentationInitializer.

    Args:
        configuration_class: The configuration class to use for loading settings.
                            Defaults to AugmentationConfiguration.
        package_loader: Package loader instance responsible for loading required packages.
                       Defaults to a new AugmentationPackageLoader instance.
    """
    super().__init__(
        configuration_class=configuration_class,
        package_loader=package_loader,
    )
    self._initialize_default_prompt()

AugmentationPackageLoader

Bases: EmbeddingPackageLoader

Package loader for augmentation components.

Extends the EmbeddingPackageLoader to load additional packages required for the augmentation process, including LLMs, retrievers, postprocessors, and chat engines.

Source code in src/augmentation/bootstrap/initializer.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class AugmentationPackageLoader(EmbeddingPackageLoader):
    """Package loader for augmentation components.

    Extends the EmbeddingPackageLoader to load additional packages required
    for the augmentation process, including LLMs, retrievers,
    postprocessors, and chat engines.
    """

    def __init__(
        self, logger: logging.Logger = LoggerConfiguration.get_logger(__name__)
    ):
        """Initialize the AugmentationPackageLoader.

        Args:
            logger: Logger instance for logging information. Defaults to a logger
                   configured with the current module name.
        """
        super().__init__(logger)

    def load_packages(self) -> None:
        """Load all required packages for augmentation.

        Calls the parent class's load_packages method first to load embedding packages,
        then loads additional packages specific to augmentation.
        """
        super().load_packages()
        self._load_packages(
            [
                "src.augmentation.components.llms",
                "src.augmentation.components.retrievers",
                "src.augmentation.components.postprocessors",
                "src.augmentation.components.chat_engines",
            ]
        )

__init__(logger=LoggerConfiguration.get_logger(__name__))

Initialize the AugmentationPackageLoader.

Parameters:
  • logger (Logger, default: get_logger(__name__) ) –

    Logger instance for logging information. Defaults to a logger configured with the current module name.

Source code in src/augmentation/bootstrap/initializer.py
31
32
33
34
35
36
37
38
39
40
def __init__(
    self, logger: logging.Logger = LoggerConfiguration.get_logger(__name__)
):
    """Initialize the AugmentationPackageLoader.

    Args:
        logger: Logger instance for logging information. Defaults to a logger
               configured with the current module name.
    """
    super().__init__(logger)

load_packages()

Load all required packages for augmentation.

Calls the parent class's load_packages method first to load embedding packages, then loads additional packages specific to augmentation.

Source code in src/augmentation/bootstrap/initializer.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def load_packages(self) -> None:
    """Load all required packages for augmentation.

    Calls the parent class's load_packages method first to load embedding packages,
    then loads additional packages specific to augmentation.
    """
    super().load_packages()
    self._load_packages(
        [
            "src.augmentation.components.llms",
            "src.augmentation.components.retrievers",
            "src.augmentation.components.postprocessors",
            "src.augmentation.components.chat_engines",
        ]
    )