Query Rephrasers#
ragbits.document_search.retrieval.rephrasers.base.QueryRephraserOptions
#
Bases: Options
Object representing the options for the rephraser.
model_config
class-attribute
instance-attribute
#
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
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:
|
llm_options |
The options for the LLM.
TYPE:
|
model_config
class-attribute
instance-attribute
#
llm_options
class-attribute
instance-attribute
#
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
ragbits.document_search.retrieval.rephrasers.base.QueryRephraser
#
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:
|
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.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
#
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:
|
options |
The options for the rephraser.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Iterable[str]
|
The rephrased queries. |
Source code in packages/ragbits-document-search/src/ragbits/document_search/retrieval/rephrasers/base.py
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:
|
prompt |
The prompt to use for rephrasing queries.
TYPE:
|
default_options |
The default options for the rephraser.
TYPE:
|
Source code in packages/ragbits-document-search/src/ragbits/document_search/retrieval/rephrasers/llm.py
options_cls
class-attribute
instance-attribute
#
options_cls: type[LLMQueryRephraserOptions] = LLMQueryRephraserOptions
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
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:
|
options |
The options for the rephraser.
TYPE:
|
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
from_config
classmethod
#
Create an instance of LLMQueryRephraser
from a configuration dictionary.
PARAMETER | DESCRIPTION |
---|---|
config |
A dictionary containing configuration settings for the rephraser.
TYPE:
|
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
ragbits.document_search.retrieval.rephrasers.noop.NoopQueryRephraser
#
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:
|
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
options_cls
class-attribute
instance-attribute
#
options_cls: type[QueryRephraserOptions] = QueryRephraserOptions
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
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:
|
options |
The options for the rephraser.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Iterable[str]
|
The list with non-transformed query. |