Element Enrichers#
ragbits.document_search.ingestion.enrichers.router.ElementEnricherRouter
#
ElementEnricherRouter(enrichers: Mapping[type[Element], ElementEnricher] | None = None)
Bases: WithConstructionConfig
The class responsible for routing the element to the correct enricher based on the element type.
Initialize the ElementEnricherRouter instance.
PARAMETER | DESCRIPTION |
---|---|
enrichers |
The mapping of element types and their enrichers. To override default enrichers.
TYPE:
|
Source code in packages/ragbits-document-search/src/ragbits/document_search/ingestion/enrichers/router.py
subclass_from_config
classmethod
#
Initializes the class with the provided configuration. May return a subclass of the class, if requested by the configuration.
PARAMETER | DESCRIPTION |
---|---|
config |
A model containing configuration details for the class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided configuration. |
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
The class can't be found or is not a subclass of the current class. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
subclass_from_factory
classmethod
#
Creates the class using the provided factory function. May return a subclass of the class, if requested by the factory.
PARAMETER | DESCRIPTION |
---|---|
factory_path |
A string representing the path to the factory function in the format of "module.submodule:factory_name".
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided factory function. |
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
The factory can't be found or the object returned is not a subclass of the current class. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
preferred_subclass
classmethod
#
preferred_subclass(config: CoreConfig, factory_path_override: str | None = None, yaml_path_override: Path | None = None) -> Self
Tries to create an instance by looking at project's component preferences, either from YAML or from the factory. Takes optional overrides for both, which takes a higher precedence.
PARAMETER | DESCRIPTION |
---|---|
config |
The CoreConfig instance containing preferred factory and configuration details.
TYPE:
|
factory_path_override |
A string representing the path to the factory function in the format of "module.submodule:factory_name".
TYPE:
|
yaml_path_override |
A string representing the path to the YAML file containing the Ragstack instance configuration.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
If the default factory or configuration can't be found. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
from_config
classmethod
#
Initialize the class with the provided configuration.
PARAMETER | DESCRIPTION |
---|---|
config |
A dictionary containing configuration details for the class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The ElementEnricherRouter. |
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
If any of the provided parsers cannot be initialized. |
Source code in packages/ragbits-document-search/src/ragbits/document_search/ingestion/enrichers/router.py
get
#
get(element_type: type[Element]) -> ElementEnricher
Get the enricher for the element.
PARAMETER | DESCRIPTION |
---|---|
element_type |
The element type.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ElementEnricher
|
The enricher for processing the element. |
RAISES | DESCRIPTION |
---|---|
EnricherNotFoundError
|
If no enricher is found for the element type. |
Source code in packages/ragbits-document-search/src/ragbits/document_search/ingestion/enrichers/router.py
ragbits.document_search.ingestion.enrichers.base.ElementEnricher
#
Bases: Generic[ElementT]
, WithConstructionConfig
, ABC
Base class for element enrichers, responsible for providing additional information about elements.
Enrichers operate on raw elements and are used to fill in missing fields that could not be filled in during parsing. They usually deal with summarizing text or describing images.
subclass_from_config
classmethod
#
Initializes the class with the provided configuration. May return a subclass of the class, if requested by the configuration.
PARAMETER | DESCRIPTION |
---|---|
config |
A model containing configuration details for the class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided configuration. |
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
The class can't be found or is not a subclass of the current class. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
subclass_from_factory
classmethod
#
Creates the class using the provided factory function. May return a subclass of the class, if requested by the factory.
PARAMETER | DESCRIPTION |
---|---|
factory_path |
A string representing the path to the factory function in the format of "module.submodule:factory_name".
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided factory function. |
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
The factory can't be found or the object returned is not a subclass of the current class. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
preferred_subclass
classmethod
#
preferred_subclass(config: CoreConfig, factory_path_override: str | None = None, yaml_path_override: Path | None = None) -> Self
Tries to create an instance by looking at project's component preferences, either from YAML or from the factory. Takes optional overrides for both, which takes a higher precedence.
PARAMETER | DESCRIPTION |
---|---|
config |
The CoreConfig instance containing preferred factory and configuration details.
TYPE:
|
factory_path_override |
A string representing the path to the factory function in the format of "module.submodule:factory_name".
TYPE:
|
yaml_path_override |
A string representing the path to the YAML file containing the Ragstack instance configuration.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
If the default factory or configuration can't be found. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
from_config
classmethod
#
Initializes the class with the provided configuration.
PARAMETER | DESCRIPTION |
---|---|
config |
A dictionary containing configuration details for the class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided configuration. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
enrich
abstractmethod
async
#
Enrich elements.
PARAMETER | DESCRIPTION |
---|---|
elements |
The elements to be enriched.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[ElementT]
|
The list of enriched elements. |
RAISES | DESCRIPTION |
---|---|
EnricherError
|
If the enrichment of the elements failed. |
Source code in packages/ragbits-document-search/src/ragbits/document_search/ingestion/enrichers/base.py
validate_element_type
classmethod
#
validate_element_type(element_type: type[Element]) -> None
Check if the enricher supports the element type.
PARAMETER | DESCRIPTION |
---|---|
element_type |
The element type to validate against the enricher.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
EnricherElementNotSupportedError
|
If the element type is not supported. |
Source code in packages/ragbits-document-search/src/ragbits/document_search/ingestion/enrichers/base.py
ragbits.document_search.ingestion.enrichers.image.ImageElementEnricher
#
ImageElementEnricher(llm: LLM | None = None, prompt: type[Prompt[ImageDescriberInput, ImageDescriberOutput]] | None = None)
Bases: ElementEnricher[ImageElement]
Enricher that describes image elements using LLM.
Initialize the ImageElementEnricher instance.
PARAMETER | DESCRIPTION |
---|---|
llm |
The language model to use for describing images.
TYPE:
|
prompt |
The prompt class to use.
TYPE:
|
Source code in packages/ragbits-document-search/src/ragbits/document_search/ingestion/enrichers/image.py
subclass_from_config
classmethod
#
Initializes the class with the provided configuration. May return a subclass of the class, if requested by the configuration.
PARAMETER | DESCRIPTION |
---|---|
config |
A model containing configuration details for the class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided configuration. |
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
The class can't be found or is not a subclass of the current class. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
subclass_from_factory
classmethod
#
Creates the class using the provided factory function. May return a subclass of the class, if requested by the factory.
PARAMETER | DESCRIPTION |
---|---|
factory_path |
A string representing the path to the factory function in the format of "module.submodule:factory_name".
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
An instance of the class initialized with the provided factory function. |
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
The factory can't be found or the object returned is not a subclass of the current class. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
preferred_subclass
classmethod
#
preferred_subclass(config: CoreConfig, factory_path_override: str | None = None, yaml_path_override: Path | None = None) -> Self
Tries to create an instance by looking at project's component preferences, either from YAML or from the factory. Takes optional overrides for both, which takes a higher precedence.
PARAMETER | DESCRIPTION |
---|---|
config |
The CoreConfig instance containing preferred factory and configuration details.
TYPE:
|
factory_path_override |
A string representing the path to the factory function in the format of "module.submodule:factory_name".
TYPE:
|
yaml_path_override |
A string representing the path to the YAML file containing the Ragstack instance configuration.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
InvalidConfigError
|
If the default factory or configuration can't be found. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
validate_element_type
classmethod
#
validate_element_type(element_type: type[Element]) -> None
Check if the enricher supports the element type.
PARAMETER | DESCRIPTION |
---|---|
element_type |
The element type to validate against the enricher.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
EnricherElementNotSupportedError
|
If the element type is not supported. |
Source code in packages/ragbits-document-search/src/ragbits/document_search/ingestion/enrichers/base.py
enrich
async
#
Enrich image elements with additional description of the image.
PARAMETER | DESCRIPTION |
---|---|
elements |
The elements to be enriched.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[ImageElement]
|
The list of enriched elements. |
RAISES | DESCRIPTION |
---|---|
EnricherElementNotSupportedError
|
If the element type is not supported. |
LLMError
|
If LLM generation fails. |
Source code in packages/ragbits-document-search/src/ragbits/document_search/ingestion/enrichers/image.py
from_config
classmethod
#
from_config(config: dict) -> ImageElementEnricher
Create an ImageElementEnricher
instance from a configuration dictionary.
PARAMETER | DESCRIPTION |
---|---|
config |
The dictionary containing the configuration settings.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ImageElementEnricher
|
The initialized instance of |
RAISES | DESCRIPTION |
---|---|
ValidationError
|
If the configuration doesn't follow the expected format. |
InvalidConfigError
|
If llm or prompt can't be found or are not the correct type. |