Skip to content

Query Rephrasers#

ragbits.document_search.retrieval.rephrasers.base.QueryRephraserOptions #

Bases: Options

Object representing the options for the rephraser.

model_config class-attribute instance-attribute #

model_config = ConfigDict(extra='allow', arbitrary_types_allowed=True)

dict #

dict() -> dict[str, Any]

Creates a dictionary representation of the Options instance. If a value is None, it will be replaced with a provider-specific not-given sentinel.

RETURNS DESCRIPTION
dict[str, Any]

A dictionary representation of the Options instance.

Source code in packages/ragbits-core/src/ragbits/core/options.py
def dict(self) -> dict[str, Any]:  # type: ignore # mypy complains about overriding BaseModel.dict
    """
    Creates a dictionary representation of the Options instance.
    If a value is None, it will be replaced with a provider-specific not-given sentinel.

    Returns:
        A dictionary representation of the Options instance.
    """
    options = self.model_dump()

    return {
        key: self._not_given if value is None or isinstance(value, NotGiven) else value
        for key, value in options.items()
    }

ragbits.document_search.retrieval.rephrasers.llm.LLMQueryRephraserOptions #

Bases: QueryRephraserOptions, Generic[LLMClientOptionsT]

Object representing the options for the LLM query rephraser.

ATTRIBUTE DESCRIPTION
n

The number of rephrasings to generate. Any number below 2 will generate only one rephrasing.

TYPE: int | None | NotGiven

llm_options

The options for the LLM.

TYPE: LLMClientOptionsT | None | NotGiven

model_config class-attribute instance-attribute #

model_config = ConfigDict(extra='allow', arbitrary_types_allowed=True)

n class-attribute instance-attribute #

n: int | None | NotGiven = NOT_GIVEN

llm_options class-attribute instance-attribute #

llm_options: LLMClientOptionsT | None | NotGiven = NOT_GIVEN

dict #

dict() -> dict[str, Any]

Creates a dictionary representation of the Options instance. If a value is None, it will be replaced with a provider-specific not-given sentinel.

RETURNS DESCRIPTION
dict[str, Any]

A dictionary representation of the Options instance.

Source code in packages/ragbits-core/src/ragbits/core/options.py
def dict(self) -> dict[str, Any]:  # type: ignore # mypy complains about overriding BaseModel.dict
    """
    Creates a dictionary representation of the Options instance.
    If a value is None, it will be replaced with a provider-specific not-given sentinel.

    Returns:
        A dictionary representation of the Options instance.
    """
    options = self.model_dump()

    return {
        key: self._not_given if value is None or isinstance(value, NotGiven) else value
        for key, value in options.items()
    }

ragbits.document_search.retrieval.rephrasers.base.QueryRephraser #

QueryRephraser(default_options: OptionsT | None = None)

Bases: ConfigurableComponent[QueryRephraserOptionsT], ABC

Rephrases a query. Can provide multiple rephrased queries from one sentence / question.

Constructs a new ConfigurableComponent instance.

PARAMETER DESCRIPTION
default_options

The default options for the component.

TYPE: OptionsT | None DEFAULT: None

Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
def __init__(self, default_options: OptionsT | None = None) -> None:
    """
    Constructs a new ConfigurableComponent instance.

    Args:
        default_options: The default options for the component.
    """
    self.default_options: OptionsT = default_options or self.options_cls()

default_options instance-attribute #

default_options: OptionsT = default_options or options_cls()

options_cls instance-attribute #

options_cls: type[QueryRephraserOptionsT]

default_module class-attribute instance-attribute #

default_module: ClassVar = rephrasers

configuration_key class-attribute instance-attribute #

configuration_key: ClassVar = 'rephraser'

subclass_from_config classmethod #

subclass_from_config(config: ObjectConstructionConfig) -> Self

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: ObjectConstructionConfig

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
@classmethod
def subclass_from_config(cls, config: ObjectConstructionConfig) -> Self:
    """
    Initializes the class with the provided configuration. May return a subclass of the class,
    if requested by the configuration.

    Args:
        config: A model containing configuration details for the class.

    Returns:
        An instance of the class initialized with the provided configuration.

    Raises:
        InvalidConfigError: The class can't be found or is not a subclass of the current class.
    """
    subclass = import_by_path(config.type, cls.default_module)
    if not issubclass(subclass, cls):
        raise InvalidConfigError(f"{subclass} is not a subclass of {cls}")

    return subclass.from_config(config.config)

subclass_from_factory classmethod #

subclass_from_factory(factory_path: str) -> Self

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: str

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
@classmethod
def subclass_from_factory(cls, factory_path: str) -> Self:
    """
    Creates the class using the provided factory function. May return a subclass of the class,
    if requested by the factory.

    Args:
        factory_path: A string representing the path to the factory function
            in the format of "module.submodule:factory_name".

    Returns:
        An instance of the class initialized with the provided factory function.

    Raises:
        InvalidConfigError: The factory can't be found or the object returned
            is not a subclass of the current class.
    """
    factory = import_by_path(factory_path, cls.default_module)
    obj = factory()
    if not isinstance(obj, cls):
        raise InvalidConfigError(f"The object returned by factory {factory_path} is not an instance of {cls}")
    return obj

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: CoreConfig

factory_path_override

A string representing the path to the factory function in the format of "module.submodule:factory_name".

TYPE: str | None DEFAULT: None

yaml_path_override

A string representing the path to the YAML file containing the Ragstack instance configuration.

TYPE: Path | None DEFAULT: None

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
@classmethod
def preferred_subclass(
    cls, 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.

    Args:
        config: The CoreConfig instance containing preferred factory and configuration details.
        factory_path_override: A string representing the path to the factory function
            in the format of "module.submodule:factory_name".
        yaml_path_override: A string representing the path to the YAML file containing
            the Ragstack instance configuration.

    Raises:
        InvalidConfigError: If the default factory or configuration can't be found.
    """
    if yaml_path_override:
        preferences = get_config_from_yaml(yaml_path_override)
        if type_config := preferences.get(cls.configuration_key):
            return cls.subclass_from_config(ObjectConstructionConfig.model_validate(type_config))

    if factory_path_override:
        return cls.subclass_from_factory(factory_path_override)

    if preferred_factory := config.component_preference_factories.get(cls.configuration_key):
        return cls.subclass_from_factory(preferred_factory)

    if preferred_config := config.preferred_instances_config.get(cls.configuration_key):
        return cls.subclass_from_config(ObjectConstructionConfig.model_validate(preferred_config))

    raise NoPreferredConfigError(f"Could not find preferred factory or configuration for {cls.configuration_key}")

from_config classmethod #

from_config(config: dict[str, Any]) -> Self

Initializes the class with the provided configuration.

PARAMETER DESCRIPTION
config

A dictionary containing configuration details for the class.

TYPE: dict[str, Any]

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
@classmethod
def from_config(cls, config: dict[str, Any]) -> Self:
    """
    Initializes the class with the provided configuration.

    Args:
        config: A dictionary containing configuration details for the class.

    Returns:
        An instance of the class initialized with the provided configuration.
    """
    default_options = config.pop("default_options", None)
    options = cls.options_cls(**default_options) if default_options else None
    return cls(**config, default_options=options)

rephrase abstractmethod async #

rephrase(query: str, options: QueryRephraserOptionsT | None = None) -> Iterable[str]

Rephrase a query.

PARAMETER DESCRIPTION
query

The query to rephrase.

TYPE: str

options

The options for the rephraser.

TYPE: QueryRephraserOptionsT | None DEFAULT: None

RETURNS DESCRIPTION
Iterable[str]

The rephrased queries.

Source code in packages/ragbits-document-search/src/ragbits/document_search/retrieval/rephrasers/base.py
@abstractmethod
async def rephrase(self, query: str, options: QueryRephraserOptionsT | None = None) -> Iterable[str]:
    """
    Rephrase a query.

    Args:
        query: The query to rephrase.
        options: The options for the rephraser.

    Returns:
        The rephrased queries.
    """

ragbits.document_search.retrieval.rephrasers.llm.LLMQueryRephraser #

LLMQueryRephraser(llm: LLM[LLMClientOptionsT], prompt: type[Prompt[LLMQueryRephraserPromptInput, list[str]]] | None = None, default_options: LLMQueryRephraserOptions[LLMClientOptionsT] | None = None)

Bases: QueryRephraser[LLMQueryRephraserOptions[LLMClientOptionsT]]

A rephraser class that uses a LLM to rephrase queries.

Initialize the LLMQueryRephraser with a LLM.

PARAMETER DESCRIPTION
llm

A LLM instance to handle query rephrasing.

TYPE: LLM[LLMClientOptionsT]

prompt

The prompt to use for rephrasing queries.

TYPE: type[Prompt[LLMQueryRephraserPromptInput, list[str]]] | None DEFAULT: None

default_options

The default options for the rephraser.

TYPE: LLMQueryRephraserOptions[LLMClientOptionsT] | None DEFAULT: None

Source code in packages/ragbits-document-search/src/ragbits/document_search/retrieval/rephrasers/llm.py
def __init__(
    self,
    llm: LLM[LLMClientOptionsT],
    prompt: type[Prompt[LLMQueryRephraserPromptInput, list[str]]] | None = None,
    default_options: LLMQueryRephraserOptions[LLMClientOptionsT] | None = None,
) -> None:
    """
    Initialize the LLMQueryRephraser with a LLM.

    Args:
        llm: A LLM instance to handle query rephrasing.
        prompt: The prompt to use for rephrasing queries.
        default_options: The default options for the rephraser.
    """
    super().__init__(default_options=default_options)
    self._llm = llm
    self._prompt = prompt or LLMQueryRephraserPrompt

default_module class-attribute instance-attribute #

default_module: ClassVar = rephrasers

configuration_key class-attribute instance-attribute #

configuration_key: ClassVar = 'rephraser'

default_options instance-attribute #

default_options: OptionsT = default_options or options_cls()

options_cls class-attribute instance-attribute #

subclass_from_config classmethod #

subclass_from_config(config: ObjectConstructionConfig) -> Self

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: ObjectConstructionConfig

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
@classmethod
def subclass_from_config(cls, config: ObjectConstructionConfig) -> Self:
    """
    Initializes the class with the provided configuration. May return a subclass of the class,
    if requested by the configuration.

    Args:
        config: A model containing configuration details for the class.

    Returns:
        An instance of the class initialized with the provided configuration.

    Raises:
        InvalidConfigError: The class can't be found or is not a subclass of the current class.
    """
    subclass = import_by_path(config.type, cls.default_module)
    if not issubclass(subclass, cls):
        raise InvalidConfigError(f"{subclass} is not a subclass of {cls}")

    return subclass.from_config(config.config)

subclass_from_factory classmethod #

subclass_from_factory(factory_path: str) -> Self

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: str

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
@classmethod
def subclass_from_factory(cls, factory_path: str) -> Self:
    """
    Creates the class using the provided factory function. May return a subclass of the class,
    if requested by the factory.

    Args:
        factory_path: A string representing the path to the factory function
            in the format of "module.submodule:factory_name".

    Returns:
        An instance of the class initialized with the provided factory function.

    Raises:
        InvalidConfigError: The factory can't be found or the object returned
            is not a subclass of the current class.
    """
    factory = import_by_path(factory_path, cls.default_module)
    obj = factory()
    if not isinstance(obj, cls):
        raise InvalidConfigError(f"The object returned by factory {factory_path} is not an instance of {cls}")
    return obj

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: CoreConfig

factory_path_override

A string representing the path to the factory function in the format of "module.submodule:factory_name".

TYPE: str | None DEFAULT: None

yaml_path_override

A string representing the path to the YAML file containing the Ragstack instance configuration.

TYPE: Path | None DEFAULT: None

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
@classmethod
def preferred_subclass(
    cls, 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.

    Args:
        config: The CoreConfig instance containing preferred factory and configuration details.
        factory_path_override: A string representing the path to the factory function
            in the format of "module.submodule:factory_name".
        yaml_path_override: A string representing the path to the YAML file containing
            the Ragstack instance configuration.

    Raises:
        InvalidConfigError: If the default factory or configuration can't be found.
    """
    if yaml_path_override:
        preferences = get_config_from_yaml(yaml_path_override)
        if type_config := preferences.get(cls.configuration_key):
            return cls.subclass_from_config(ObjectConstructionConfig.model_validate(type_config))

    if factory_path_override:
        return cls.subclass_from_factory(factory_path_override)

    if preferred_factory := config.component_preference_factories.get(cls.configuration_key):
        return cls.subclass_from_factory(preferred_factory)

    if preferred_config := config.preferred_instances_config.get(cls.configuration_key):
        return cls.subclass_from_config(ObjectConstructionConfig.model_validate(preferred_config))

    raise NoPreferredConfigError(f"Could not find preferred factory or configuration for {cls.configuration_key}")

rephrase async #

rephrase(query: str, options: LLMQueryRephraserOptions[LLMClientOptionsT] | None = None) -> Iterable[str]

Rephrase a given query using the LLM.

PARAMETER DESCRIPTION
query

The query to be rephrased. If not provided, a custom prompt must be given.

TYPE: str

options

The options for the rephraser.

TYPE: LLMQueryRephraserOptions[LLMClientOptionsT] | None DEFAULT: None

RETURNS DESCRIPTION
Iterable[str]

A list containing the rephrased query.

RAISES DESCRIPTION
LLMConnectionError

If there is a connection error with the LLM API.

LLMStatusError

If the LLM API returns an error status code.

LLMResponseError

If the LLM API response is invalid.

Source code in packages/ragbits-document-search/src/ragbits/document_search/retrieval/rephrasers/llm.py
@traceable
async def rephrase(
    self,
    query: str,
    options: LLMQueryRephraserOptions[LLMClientOptionsT] | None = None,
) -> Iterable[str]:
    """
    Rephrase a given query using the LLM.

    Args:
        query: The query to be rephrased. If not provided, a custom prompt must be given.
        options: The options for the rephraser.

    Returns:
        A list containing the rephrased query.

    Raises:
        LLMConnectionError: If there is a connection error with the LLM API.
        LLMStatusError: If the LLM API returns an error status code.
        LLMResponseError: If the LLM API response is invalid.
    """
    merged_options = (self.default_options | options) if options else self.default_options
    llm_options = merged_options.llm_options or None
    prompt = self._prompt(LLMQueryRephraserPromptInput(query=query, n=merged_options.n or None))
    return await self._llm.generate(prompt, options=llm_options)

from_config classmethod #

from_config(config: dict) -> Self

Create an instance of LLMQueryRephraser from a configuration dictionary.

PARAMETER DESCRIPTION
config

A dictionary containing configuration settings for the rephraser.

TYPE: dict

RETURNS DESCRIPTION
Self

An instance of the rephraser class initialized with the provided configuration.

RAISES DESCRIPTION
ValidationError

If the LLM or prompt configuration doesn't follow the expected format.

InvalidConfigError

If an LLM or prompt class can't be found or is not the correct type.

Source code in packages/ragbits-document-search/src/ragbits/document_search/retrieval/rephrasers/llm.py
@classmethod
def from_config(cls, config: dict) -> Self:
    """
    Create an instance of `LLMQueryRephraser` from a configuration dictionary.

    Args:
        config: A dictionary containing configuration settings for the rephraser.

    Returns:
        An instance of the rephraser class initialized with the provided configuration.

    Raises:
       ValidationError: If the LLM or prompt configuration doesn't follow the expected format.
       InvalidConfigError: If an LLM or prompt class can't be found or is not the correct type.
    """
    config["llm"] = LLM.subclass_from_config(ObjectConstructionConfig.model_validate(config["llm"]))
    config["prompt"] = (
        import_by_path(ObjectConstructionConfig.model_validate(config["prompt"]).type)
        if "prompt" in config
        else None
    )
    return super().from_config(config)

ragbits.document_search.retrieval.rephrasers.noop.NoopQueryRephraser #

NoopQueryRephraser(default_options: OptionsT | None = None)

Bases: QueryRephraser[QueryRephraserOptions]

A no-op query paraphraser that does not change the query.

Constructs a new ConfigurableComponent instance.

PARAMETER DESCRIPTION
default_options

The default options for the component.

TYPE: OptionsT | None DEFAULT: None

Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
def __init__(self, default_options: OptionsT | None = None) -> None:
    """
    Constructs a new ConfigurableComponent instance.

    Args:
        default_options: The default options for the component.
    """
    self.default_options: OptionsT = default_options or self.options_cls()

default_module class-attribute instance-attribute #

default_module: ClassVar = rephrasers

configuration_key class-attribute instance-attribute #

configuration_key: ClassVar = 'rephraser'

default_options instance-attribute #

default_options: OptionsT = default_options or options_cls()

options_cls class-attribute instance-attribute #

subclass_from_config classmethod #

subclass_from_config(config: ObjectConstructionConfig) -> Self

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: ObjectConstructionConfig

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
@classmethod
def subclass_from_config(cls, config: ObjectConstructionConfig) -> Self:
    """
    Initializes the class with the provided configuration. May return a subclass of the class,
    if requested by the configuration.

    Args:
        config: A model containing configuration details for the class.

    Returns:
        An instance of the class initialized with the provided configuration.

    Raises:
        InvalidConfigError: The class can't be found or is not a subclass of the current class.
    """
    subclass = import_by_path(config.type, cls.default_module)
    if not issubclass(subclass, cls):
        raise InvalidConfigError(f"{subclass} is not a subclass of {cls}")

    return subclass.from_config(config.config)

subclass_from_factory classmethod #

subclass_from_factory(factory_path: str) -> Self

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: str

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
@classmethod
def subclass_from_factory(cls, factory_path: str) -> Self:
    """
    Creates the class using the provided factory function. May return a subclass of the class,
    if requested by the factory.

    Args:
        factory_path: A string representing the path to the factory function
            in the format of "module.submodule:factory_name".

    Returns:
        An instance of the class initialized with the provided factory function.

    Raises:
        InvalidConfigError: The factory can't be found or the object returned
            is not a subclass of the current class.
    """
    factory = import_by_path(factory_path, cls.default_module)
    obj = factory()
    if not isinstance(obj, cls):
        raise InvalidConfigError(f"The object returned by factory {factory_path} is not an instance of {cls}")
    return obj

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: CoreConfig

factory_path_override

A string representing the path to the factory function in the format of "module.submodule:factory_name".

TYPE: str | None DEFAULT: None

yaml_path_override

A string representing the path to the YAML file containing the Ragstack instance configuration.

TYPE: Path | None DEFAULT: None

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
@classmethod
def preferred_subclass(
    cls, 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.

    Args:
        config: The CoreConfig instance containing preferred factory and configuration details.
        factory_path_override: A string representing the path to the factory function
            in the format of "module.submodule:factory_name".
        yaml_path_override: A string representing the path to the YAML file containing
            the Ragstack instance configuration.

    Raises:
        InvalidConfigError: If the default factory or configuration can't be found.
    """
    if yaml_path_override:
        preferences = get_config_from_yaml(yaml_path_override)
        if type_config := preferences.get(cls.configuration_key):
            return cls.subclass_from_config(ObjectConstructionConfig.model_validate(type_config))

    if factory_path_override:
        return cls.subclass_from_factory(factory_path_override)

    if preferred_factory := config.component_preference_factories.get(cls.configuration_key):
        return cls.subclass_from_factory(preferred_factory)

    if preferred_config := config.preferred_instances_config.get(cls.configuration_key):
        return cls.subclass_from_config(ObjectConstructionConfig.model_validate(preferred_config))

    raise NoPreferredConfigError(f"Could not find preferred factory or configuration for {cls.configuration_key}")

from_config classmethod #

from_config(config: dict[str, Any]) -> Self

Initializes the class with the provided configuration.

PARAMETER DESCRIPTION
config

A dictionary containing configuration details for the class.

TYPE: dict[str, Any]

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
@classmethod
def from_config(cls, config: dict[str, Any]) -> Self:
    """
    Initializes the class with the provided configuration.

    Args:
        config: A dictionary containing configuration details for the class.

    Returns:
        An instance of the class initialized with the provided configuration.
    """
    default_options = config.pop("default_options", None)
    options = cls.options_cls(**default_options) if default_options else None
    return cls(**config, default_options=options)

rephrase async #

rephrase(query: str, options: QueryRephraserOptions | None = None) -> Iterable[str]

Mock implementation which outputs the same query as in input.

PARAMETER DESCRIPTION
query

The query to rephrase.

TYPE: str

options

The options for the rephraser.

TYPE: QueryRephraserOptions | None DEFAULT: None

RETURNS DESCRIPTION
Iterable[str]

The list with non-transformed query.

Source code in packages/ragbits-document-search/src/ragbits/document_search/retrieval/rephrasers/noop.py
@traceable
async def rephrase(self, query: str, options: QueryRephraserOptions | None = None) -> Iterable[str]:  # noqa: PLR6301
    """
    Mock implementation which outputs the same query as in input.

    Args:
        query: The query to rephrase.
        options: The options for the rephraser.

    Returns:
        The list with non-transformed query.
    """
    return [query]