Embedders#
ragbits.core.embeddings.Embedder
#
Bases: ConfigurableComponent[EmbedderOptionsT]
, ABC
Abstract client for communication with embedding models.
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
embed_text
abstractmethod
async
#
Creates embeddings for the given strings.
PARAMETER | DESCRIPTION |
---|---|
data |
List of strings to get embeddings for.
TYPE:
|
options |
Additional settings used by the Embedder model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[list[float]]
|
List of embeddings for the given strings. |
Source code in packages/ragbits-core/src/ragbits/core/embeddings/base.py
image_support
#
Check if the model supports image embeddings.
RETURNS | DESCRIPTION |
---|---|
bool
|
True if the model supports image embeddings, False otherwise. |
embed_image
async
#
Creates embeddings for the given images.
PARAMETER | DESCRIPTION |
---|---|
images |
List of images to get embeddings for.
TYPE:
|
options |
Additional settings used by the Embedder model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[list[float]]
|
List of embeddings for the given images. |
Source code in packages/ragbits-core/src/ragbits/core/embeddings/base.py
ragbits.core.embeddings.local.LocalEmbedder
#
LocalEmbedder(model_name: str, api_key: str | None = None, default_options: LocalEmbedderOptions | None = None)
Bases: Embedder[LocalEmbedderOptions]
Class for interaction with any encoder available in HuggingFace.
Note: Local implementation is not dedicated for production. Use it only in experiments / evaluation
Constructs a new local LLM instance.
PARAMETER | DESCRIPTION |
---|---|
model_name |
Name of the model to use.
TYPE:
|
api_key |
The API key for Hugging Face authentication.
TYPE:
|
default_options |
Default options for the embedding model.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ImportError
|
If the 'local' extra requirements are not installed. |
Source code in packages/ragbits-core/src/ragbits/core/embeddings/local.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
image_support
#
Check if the model supports image embeddings.
RETURNS | DESCRIPTION |
---|---|
bool
|
True if the model supports image embeddings, False otherwise. |
embed_image
async
#
Creates embeddings for the given images.
PARAMETER | DESCRIPTION |
---|---|
images |
List of images to get embeddings for.
TYPE:
|
options |
Additional settings used by the Embedder model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[list[float]]
|
List of embeddings for the given images. |
Source code in packages/ragbits-core/src/ragbits/core/embeddings/base.py
embed_text
async
#
Calls the appropriate encoder endpoint with the given data and options.
PARAMETER | DESCRIPTION |
---|---|
data |
List of strings to get embeddings for.
TYPE:
|
options |
Additional options to pass to the embedding model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[list[float]]
|
List of embeddings for the given strings. |
Source code in packages/ragbits-core/src/ragbits/core/embeddings/local.py
ragbits.core.embeddings.litellm.LiteLLMEmbedder
#
LiteLLMEmbedder(model_name: str = 'text-embedding-3-small', default_options: LiteLLMEmbedderOptions | None = None, *, api_base: str | None = None, base_url: str | None = None, api_key: str | None = None, api_version: str | None = None, router: Router | None = None)
Bases: Embedder[LiteLLMEmbedderOptions]
Client for creating text embeddings using LiteLLM API.
Constructs the LiteLLMEmbeddingClient.
PARAMETER | DESCRIPTION |
---|---|
model_name |
Name of the LiteLLM supported model to be used. Default is "text-embedding-3-small".
TYPE:
|
default_options |
Default options to pass to the LiteLLM API.
TYPE:
|
api_base |
The API endpoint you want to call the model with.
TYPE:
|
base_url |
Alias for api_base. If both are provided, api_base takes precedence.
TYPE:
|
api_key |
API key to be used. If not specified, an environment variable will be used, for more information, follow the instructions for your specific vendor in the LiteLLM documentation.
TYPE:
|
api_version |
The API version for the call.
TYPE:
|
router |
Router to be used to route requests to different models.
TYPE:
|
Source code in packages/ragbits-core/src/ragbits/core/embeddings/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 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
image_support
#
Check if the model supports image embeddings.
RETURNS | DESCRIPTION |
---|---|
bool
|
True if the model supports image embeddings, False otherwise. |
embed_image
async
#
Creates embeddings for the given images.
PARAMETER | DESCRIPTION |
---|---|
images |
List of images to get embeddings for.
TYPE:
|
options |
Additional settings used by the Embedder model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[list[float]]
|
List of embeddings for the given images. |
Source code in packages/ragbits-core/src/ragbits/core/embeddings/base.py
embed_text
async
#
Creates embeddings for the given strings.
PARAMETER | DESCRIPTION |
---|---|
data |
List of strings to get embeddings for.
TYPE:
|
options |
Additional options to pass to the Lite LLM API.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[list[float]]
|
List of embeddings for the given strings. |
RAISES | DESCRIPTION |
---|---|
EmbeddingConnectionError
|
If there is a connection error with the embedding API. |
EmbeddingEmptyResponseError
|
If the embedding API returns an empty response. |
EmbeddingStatusError
|
If the embedding API returns an error status code. |
EmbeddingResponseError
|
If the embedding API response is invalid. |
Source code in packages/ragbits-core/src/ragbits/core/embeddings/litellm.py
from_config
classmethod
#
Creates and returns a LiteLLMEmbedder instance.
PARAMETER | DESCRIPTION |
---|---|
config |
A configuration object containing the configuration for initializing the LiteLLMEmbedder instance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
LiteLLMEmbedder
|
An initialized LiteLLMEmbedder instance.
TYPE:
|
Source code in packages/ragbits-core/src/ragbits/core/embeddings/litellm.py
ragbits.core.embeddings.fastembed.FastEmbedEmbedder
#
FastEmbedEmbedder(model_name: str, use_gpu: bool = False, default_options: FastEmbedOptions | None = None)
Bases: Embedder[FastEmbedOptions]
Class for creating dense text embeddings using FastEmbed library. For more information, see the FastEmbed GitHub.
Source code in packages/ragbits-core/src/ragbits/core/embeddings/fastembed.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
image_support
#
Check if the model supports image embeddings.
RETURNS | DESCRIPTION |
---|---|
bool
|
True if the model supports image embeddings, False otherwise. |
embed_image
async
#
Creates embeddings for the given images.
PARAMETER | DESCRIPTION |
---|---|
images |
List of images to get embeddings for.
TYPE:
|
options |
Additional settings used by the Embedder model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[list[float]]
|
List of embeddings for the given images. |
Source code in packages/ragbits-core/src/ragbits/core/embeddings/base.py
embed_text
async
#
Embeds a list of strings into a list of embeddings.
PARAMETER | DESCRIPTION |
---|---|
data |
List of strings to get embeddings for.
TYPE:
|
options |
Additional options to pass to the embedding model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[list[float]]
|
List of embeddings for the given strings. |
Source code in packages/ragbits-core/src/ragbits/core/embeddings/fastembed.py
ragbits.core.embeddings.fastembed.FastEmbedSparseEmbedder
#
FastEmbedSparseEmbedder(model_name: str, use_gpu: bool = False, default_options: FastEmbedOptions | None = None)
Bases: SparseEmbedder[FastEmbedOptions]
Class for creating sparse text embeddings using FastEmbed library. For more information, see the FastEmbed GitHub.
Source code in packages/ragbits-core/src/ragbits/core/embeddings/fastembed.py
configuration_key
class-attribute
instance-attribute
#
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
embed_text
async
#
Embeds a list of strings into a list of sparse embeddings.
PARAMETER | DESCRIPTION |
---|---|
data |
List of strings to get embeddings for.
TYPE:
|
options |
Additional options to pass to the embedding model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[SparseVector]
|
List of embeddings for the given strings. |