Embeddings#
ragbits.core.embeddings.Embeddings
#
Bases: ConfigurableComponent[EmbeddingsOptionsT]
, 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
subclass_from_defaults
classmethod
#
subclass_from_defaults(defaults: CoreConfig, factory_path_override: str | None = None, yaml_path_override: Path | None = None) -> Self
Tries to create an instance by looking at default configuration file, and default factory function. Takes optional overrides for both, which takes a higher precedence.
PARAMETER | DESCRIPTION |
---|---|
defaults |
The CoreConfig instance containing default 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
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 Embeddings 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 Embeddings 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.LocalEmbeddings
#
LocalEmbeddings(model_name: str, api_key: str | None = None, default_options: LocalEmbeddingsOptions | None = None)
Bases: Embeddings[LocalEmbeddingsOptions]
Class for interaction with any encoder available in HuggingFace.
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
subclass_from_defaults
classmethod
#
subclass_from_defaults(defaults: CoreConfig, factory_path_override: str | None = None, yaml_path_override: Path | None = None) -> Self
Tries to create an instance by looking at default configuration file, and default factory function. Takes optional overrides for both, which takes a higher precedence.
PARAMETER | DESCRIPTION |
---|---|
defaults |
The CoreConfig instance containing default 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
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 Embeddings 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.LiteLLMEmbeddings
#
LiteLLMEmbeddings(model: str = 'text-embedding-3-small', default_options: LiteLLMEmbeddingsOptions | None = None, api_base: str | None = None, api_key: str | None = None, api_version: str | None = None)
Bases: Embeddings[LiteLLMEmbeddingsOptions]
Client for creating text embeddings using LiteLLM API.
Constructs the LiteLLMEmbeddingClient.
PARAMETER | DESCRIPTION |
---|---|
model |
Name of the LiteLLM supported model to be used. Default is "text-embedding-3-small".
TYPE:
|
default_options |
Defualt options to pass to the LiteLLM API.
TYPE:
|
api_base |
The API endpoint you want to call the model with.
TYPE:
|
api_key |
API key to be used. 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:
|
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
subclass_from_defaults
classmethod
#
subclass_from_defaults(defaults: CoreConfig, factory_path_override: str | None = None, yaml_path_override: Path | None = None) -> Self
Tries to create an instance by looking at default configuration file, and default factory function. Takes optional overrides for both, which takes a higher precedence.
PARAMETER | DESCRIPTION |
---|---|
defaults |
The CoreConfig instance containing default 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
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 Embeddings 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. |