orka.registry module
Resource Registry
The Resource Registry is a central dependency injection and resource management system for the OrKa framework. It provides a consistent interface for initializing, accessing, and managing shared resources such as language models, embedding models, databases, and custom tools.
Key responsibilities:
Lazy initialization of resources based on configuration
Centralized access to shared dependencies
Resource lifecycle management (initialization and cleanup)
Consistent error handling for resource failures
Support for custom resource types through dynamic imports
Supported resource types:
sentence_transformer: Text embedding models
redis: Redis database client
openai: OpenAI API client
custom: Dynamically loaded custom resources
The registry pattern helps maintain clean separation of concerns by isolating resource initialization logic and providing a single source of truth for shared dependencies across the framework.
- class orka.registry.ResourceRegistry(config: Dict[str, ResourceConfig])[source]
Bases:
object
Manages resource initialization, access, and lifecycle.
The ResourceRegistry is responsible for lazily initializing resources when needed, providing access to them via a simple interface, and ensuring proper cleanup when the application shuts down. It acts as a central dependency provider for all OrKa components.
- __init__(config: Dict[str, ResourceConfig])[source]
Initialize the registry with resource configurations.
- Parameters:
config – Dictionary mapping resource names to their configurations
- async initialize() None [source]
Initialize all resources based on their configurations.
This method lazily initializes all configured resources, handling any initialization errors and ensuring resources are only initialized once.
- Raises:
Exception – If any resource fails to initialize
- orka.registry.init_registry(config: Dict[str, ResourceConfig]) ResourceRegistry [source]
Create and initialize a new resource registry.
- Parameters:
config – Dictionary mapping resource names to their configurations
- Returns:
Initialized ResourceRegistry instance