Skip to content

qoolqit.embedding.base_embedder

source module qoolqit.embedding.base_embedder

Classes

  • EmbeddingConfig Base abstract dataclass for all embedding algorithm configurations.

  • BaseEmbedder Abstract base class for all embedders.

source dataclass EmbeddingConfig()

Bases : ABC

Base abstract dataclass for all embedding algorithm configurations.

Subclasses define parameters specific to their algorithms. Each config should define fields that directly translate to arguments in the respective embedding function it configures.

Methods

  • dict Returns the dataclass as a dictionary.

source method EmbeddingConfig.dict()dict

Returns the dataclass as a dictionary.

source class BaseEmbedder(algorithm: Callable, config: ConfigType)

Bases : ABC, Generic[InDataType, OutDataType, ConfigType]

Abstract base class for all embedders.

An embedder is a function that maps a InDataType to an OutDataType through an embedding algorithm. Parameters of the embedding algorithm can be customized through the EmbeddingConfig.

Default initializer for all embedders, taking an algorithm and a config.

An algorithm should be a standalone function that takes a piece of data of an InDataType and maps it to an OutDataType. Any extra configuration parameters taken as input by the algorithm function should be defined in the config dataclass, inheriting from EmbeddingConfig.

Parameters

  • algorithm : Callable a callable to the algorithm function.

  • config : ConfigType a config dataclass holding parameter values for the algorithm.

Attributes

  • config : ConfigType Returns the config for the embedding algorithm.

  • algorithm : Callable Returns the callable to the embedding algorithm.

  • info : str Prints info about the embedding algorithm.

Methods

  • validate_input Checks if the given data is compatible with the embedder.

  • validate_output Checks if the resulting output is expected by the embedder.

  • embed Validates the input, runs the embedding algorithm, and validates the output.

source property BaseEmbedder.config: ConfigType

Returns the config for the embedding algorithm.

source property BaseEmbedder.algorithm: Callable

Returns the callable to the embedding algorithm.

source property BaseEmbedder.info: str

Prints info about the embedding algorithm.

source method BaseEmbedder.validate_input(data: InDataType)None

Checks if the given data is compatible with the embedder.

Each embedder should write its own data validator. If the data is not of the supported type or in the specific supported format for that embedder, an error should be raised.

Parameters

  • data : InDataType the data to validate.

Raises

  • TypeError if the data is not of the supported type.

  • SomeError some other error if other constraints are not met.

source method BaseEmbedder.validate_output(result: OutDataType)None

Checks if the resulting output is expected by the embedder.

Each embedder should write its own output validator. If the result is not of the supported type or in the specific supported format for that embedder, an error should be raised.

Parameters

  • result : OutDataType the output to validate.

Raises

  • TypeError if the output is not of the supported type.

  • SomeError some other error if other constraints are not met.

source method BaseEmbedder.embed(data: InDataType)OutDataType

Validates the input, runs the embedding algorithm, and validates the output.

Parameters

  • data : InDataType the data to embed.