Query Rephrasers#
ragbits.document_search.retrieval.rephrasers.QueryRephraser
#
Bases: WithConstructionConfig
, ABC
Rephrases a query. Can provide multiple rephrased queries from one sentence / question.
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 prefferences, 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
rephrase
abstractmethod
async
#
Rephrase a query.
PARAMETER | DESCRIPTION |
---|---|
query |
The query to rephrase.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[str]
|
The rephrased queries. |
ragbits.document_search.retrieval.rephrasers.LLMQueryRephraser
#
Bases: QueryRephraser
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:
|
prompt |
The prompt to use for rephrasing queries.
TYPE:
|
Source code in packages/ragbits-document-search/src/ragbits/document_search/retrieval/rephrasers/llm.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 prefferences, 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
rephrase
async
#
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:
|
RETURNS | DESCRIPTION |
---|---|
list[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
from_config
classmethod
#
from_config(config: dict) -> LLMQueryRephraser
Create an instance of LLMQueryRephraser
from a configuration dictionary.
PARAMETER | DESCRIPTION |
---|---|
config |
A dictionary containing configuration settings for the rephraser.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
LLMQueryRephraser
|
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. |
ValueError
|
If the prompt class is not a subclass of |
Source code in packages/ragbits-document-search/src/ragbits/document_search/retrieval/rephrasers/llm.py
ragbits.document_search.retrieval.rephrasers.MultiQueryRephraser
#
MultiQueryRephraser(llm: LLM, n: int | None = None, prompt: type[Prompt[MultiQueryRephraserInput, Any]] | None = None)
Bases: QueryRephraser
A rephraser class that uses a LLM to generate reworded versions of input query.
Initialize the MultiQueryRephraser with a LLM.
PARAMETER | DESCRIPTION |
---|---|
llm |
A LLM instance to handle query rephrasing.
TYPE:
|
n |
The number of rephrasings to generate.
TYPE:
|
prompt |
The prompt to use for rephrasing queries.
TYPE:
|
Source code in packages/ragbits-document-search/src/ragbits/document_search/retrieval/rephrasers/multi.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 prefferences, 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
rephrase
async
#
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:
|
RETURNS | DESCRIPTION |
---|---|
list[str]
|
A list containing the reworded versions of input 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/multi.py
from_config
classmethod
#
from_config(config: dict) -> MultiQueryRephraser
Create an instance of MultiQueryRephraser
from a configuration dictionary.
PARAMETER | DESCRIPTION |
---|---|
config |
A dictionary containing configuration settings for the rephraser.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
MultiQueryRephraser
|
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. |
ValueError
|
If the prompt class is not a subclass of |
Source code in packages/ragbits-document-search/src/ragbits/document_search/retrieval/rephrasers/multi.py
ragbits.document_search.retrieval.rephrasers.NoopQueryRephraser
#
Bases: QueryRephraser
A no-op query paraphraser that does not change the query.
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 prefferences, 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
rephrase
async
#
Mock implementation which outputs the same query as in input.
PARAMETER | DESCRIPTION |
---|---|
query |
The query to rephrase.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[str]
|
The list with non-transformed query. |