Rerankers#
ragbits.document_search.retrieval.rerankers.base.Reranker
#
Bases: ConfigurableComponent[RerankerOptionsT]
, ABC
Reranks elements retrieved from vector store.
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 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 |
---|---|
ConfigurableComponent
|
An instance of the class initialized with the provided configuration. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
rerank
abstractmethod
async
#
rerank(elements: Sequence[Sequence[Element]], query: str, options: RerankerOptionsT | None = None) -> Sequence[Element]
Rerank elements.
PARAMETER | DESCRIPTION |
---|---|
elements |
The elements to rerank.
TYPE:
|
query |
The query to rerank the elements against.
TYPE:
|
options |
The options for reranking.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Sequence[Element]
|
The reranked elements. |
Source code in packages/ragbits-document-search/src/ragbits/document_search/retrieval/rerankers/base.py
ragbits.document_search.retrieval.rerankers.litellm.LiteLLMReranker
#
Bases: Reranker[RerankerOptions]
A LiteLLM reranker for providers such as Cohere, Together AI, Azure AI.
Constructs a new LiteLLMReranker instance.
PARAMETER | DESCRIPTION |
---|---|
model |
The reranker model to use.
TYPE:
|
default_options |
The default options for reranking.
TYPE:
|
Source code in packages/ragbits-document-search/src/ragbits/document_search/retrieval/rerankers/litellm.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
from_config
classmethod
#
Initializes the class with the provided configuration.
PARAMETER | DESCRIPTION |
---|---|
config |
A dictionary containing configuration details for the class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ConfigurableComponent
|
An instance of the class initialized with the provided configuration. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
rerank
async
#
rerank(elements: Sequence[Sequence[Element]], query: str, options: RerankerOptions | None = None) -> Sequence[Element]
Rerank elements with LiteLLM API.
PARAMETER | DESCRIPTION |
---|---|
elements |
The elements to rerank.
TYPE:
|
query |
The query to rerank the elements against.
TYPE:
|
options |
The options for reranking.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Sequence[Element]
|
The reranked elements. |
Source code in packages/ragbits-document-search/src/ragbits/document_search/retrieval/rerankers/litellm.py
ragbits.document_search.retrieval.rerankers.noop.NoopReranker
#
Bases: Reranker[RerankerOptions]
A no-op reranker that does not change the order of the elements.
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 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 |
---|---|
ConfigurableComponent
|
An instance of the class initialized with the provided configuration. |
Source code in packages/ragbits-core/src/ragbits/core/utils/config_handling.py
rerank
async
#
rerank(elements: Sequence[Sequence[Element]], query: str, options: RerankerOptions | None = None) -> Sequence[Element]
No reranking, returning the elements in the same order.
PARAMETER | DESCRIPTION |
---|---|
elements |
The elements to rerank.
TYPE:
|
query |
The query to rerank the elements against.
TYPE:
|
options |
The options for reranking.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Sequence[Element]
|
The reranked elements. |