haive.core.engine.embedding.base

Base embedding engine configuration and registry.

Classes

BaseEmbeddingConfig

Base configuration for all embedding implementations.

Module Contents

class haive.core.engine.embedding.base.BaseEmbeddingConfig[source]

Bases: haive.core.common.mixins.secure_config.SecureConfigMixin, haive.core.engine.base.InvokableEngine

Base configuration for all embedding implementations.

This class provides the foundation for all embedding provider configurations in the Haive framework. It includes registration capabilities, secure configuration management, and the required interface for creating embedding instances.

Examples

Basic usage with a provider:

from haive.core.engine.embedding.providers import OpenAIEmbeddingConfig

config = OpenAIEmbeddingConfig(
    name="my_embeddings",
    model="text-embedding-3-large",
    api_key="sk-..."
)

embeddings = config.instantiate()

Using with configuration discovery:

# List all available providers
providers = BaseEmbeddingConfig.list_registered_types()

# Get specific provider class
provider_class = BaseEmbeddingConfig.get_config_class(EmbeddingType.OPENAI)
embedding_type

The type of embedding provider

name

Human-readable name for this configuration

model

Model name/identifier for the embedding provider

dimensions

Optional output dimensions for the embeddings

create_runnable(runnable_config=None)[source]

Create a runnable embedding instance.

This method is required by the InvokableEngine interface and provides a standardized way to create embedding instances.

Parameters:

runnable_config (dict[str, Any] | None) – Optional configuration for the runnable

Returns:

The embedding instance

Return type:

Any

classmethod get_config_class(embedding_type)[source]

Get the configuration class for a specific embedding type.

Parameters:

embedding_type (str | haive.core.engine.embedding.types.EmbeddingType) – The embedding type to get the config class for

Returns:

The configuration class if found, None otherwise

Return type:

type[BaseEmbeddingConfig] | None

Examples

Getting a provider class:

config_class = BaseEmbeddingConfig.get_config_class(EmbeddingType.OPENAI)
if config_class:
    config = config_class(model="text-embedding-3-large")
get_input_fields()[source]

Define the input schema for this embedding configuration.

Returns:

Dictionary mapping field names to (type, Field) tuples

Return type:

dict[str, tuple]

get_output_fields()[source]

Define the output schema for this embedding configuration.

Returns:

Dictionary mapping field names to (type, Field) tuples

Return type:

dict[str, tuple]

get_provider_info()[source]

Get information about this embedding provider.

Returns:

Dictionary containing provider information

Return type:

dict[str, Any]

abstractmethod instantiate()[source]

Create an embedding instance from this configuration.

This method must be implemented by each provider-specific configuration class to create the actual embedding instance.

Returns:

The embedding instance (typically a LangChain embedding object)

Raises:
Return type:

Any

Examples

Implementing instantiate method:

def instantiate(self) -> OpenAIEmbeddings:
    try:
        from langchain_openai import OpenAIEmbeddings
    except ImportError:
        raise ImportError("Install: pip install langchain-openai")

    return OpenAIEmbeddings(
        model=self.model,
        api_key=self.get_api_key()
    )
classmethod list_registered_types()[source]

List all registered embedding configuration types.

Returns:

Dictionary mapping type names to configuration classes

Return type:

dict[str, type[BaseEmbeddingConfig]]

Examples

Listing all providers:

providers = BaseEmbeddingConfig.list_registered_types()
for name, config_class in providers.items():
    print(f"Available provider: {name}")
classmethod register(embedding_type)[source]

Register an embedding configuration class.

This decorator registers embedding configuration classes with the global registry, allowing them to be discovered and instantiated dynamically.

Parameters:

embedding_type (str | haive.core.engine.embedding.types.EmbeddingType) – The embedding type to register this class for

Returns:

The decorator function

Return type:

Any

Examples

Registering a new provider:

@BaseEmbeddingConfig.register(EmbeddingType.OPENAI)
class OpenAIEmbeddingConfig(BaseEmbeddingConfig):
    # Implementation here
    pass
validate_configuration()[source]

Validate the configuration before instantiation.

This method can be overridden by subclasses to add provider-specific validation logic.

Raises:

ValueError – If configuration is invalid

Return type:

None