Skip to content
Pasqal Documentation

qoolqit.embedding.base_embedder

module
qoolqit.embedding.base_embedder

Classes

  • EmbeddingConfig Base abstract dataclass for all embedding algorithm configurations.

  • BaseEmbedder Abstract base class for all embedders.

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 configurates.

Methods

  • dict Returns the dataclass as a dictionary.

method
dict () → dict

Returns the dataclass as a dictionary.

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.

property
config : ConfigType

Returns the config for the embedding algorithm.

property
algorithm : Callable

Returns the callable to the embedding algorithm.

property
info : str

Prints info about the embedding algorithm.

method
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.

method
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.

method
embed (data: InDataType) → OutDataType

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

Parameters

  • data : InDataType the data to embed.