Skip to content

Loader

Document Processing Orchestrator Loader Package.

Modules:

Name Description
BaseLoader

Abstract base class for document loader.

PipelineLoader

Module for loading document with several loaders using pipeline.

BaseLoader

Bases: ABC

An abstract base class for document loaders.

This class defines the structure for loading and processing documents to retrieve required values. Subclasses are expected to implement the 'load' method to handle document loading from a given source.

Attributes:

Name Type Description
CACHE_KEY_IGNORE_ATTRS frozenset[str]

Init attributes left out of the cache key. Use: settings that do not change the output, such as credentials. Type: ignore list. What is not listed counts. If forgotten: only an extra cache miss. Example: frozenset({"api_key"}). The same document loaded with a different api_key still uses the same cache entry.

CACHE_KEY_KWARGS frozenset[str] | None

The only load() kwargs that count in the cache key. Use: list every kwarg that load() reads. An empty set means no kwarg counts. None means the loader has not declared them, so every kwarg counts. Type: include list. Pipelines mix loaders and pass the same kwargs to all of them, so each loader lists only the ones it reads. If forgotten: the kwarg is ignored, which can return a wrong cached result. Example: frozenset({"model_id"}). load(model_id="a", request_id="1") puts only model_id in the key, so a different request_id does not cause a cache miss.

CACHE_KEY_IGNORE_ATTRS_AT_DEFAULT dict[str, Any]

Init attributes left out of the cache key while they still have the default value given here. Use: when you add a new optional init option, so old cache entries still match. Only do this if the default gives the same output as before the option existed. Example: you add dpi: int = 300. Old keys have no dpi, so every old entry would miss. 1. Set {"dpi": 300}: dpi is left out while it is 300, so old entries still hit. 2. Someone sets dpi=150: it counts and gets its own cache entry.

Methods:

Name Description
load

Abstract method to load a document.

load(source, loaded_elements=None, **kwargs) abstractmethod

Load and process a document.

This method is abstract and must be implemented in subclasses. It defines the process of loading a document using its source.

Parameters:

Name Type Description Default
source str

Might be file path, URL, the content itself.

required
loaded_elements Any

The loaded elements from previous loaders. ideally formatted as List[Dict].

None
**kwargs Any

Additional keyword arguments for customization.

{}

Returns:

Name Type Description
Any Any

The loaded document, ideally formatted as List[Dict]. Each dictionary within the list are recommended to follows the structure of model 'Element', to ensure consistency and ease of use across Document Processing Orchestrator.

PipelineLoader(cache_data_store=None)

A pipeline loader for loading documents.

This class serves as the pipeline loader for loading document. It defines the structure for loading document with several loaders using pipeline.

Methods:

Name Description
add_loader

Add loader to the pipeline loader.

load

Load the document from the given source.

Initialize the PipelineLoader.

Parameters:

Name Type Description Default
cache_data_store BaseHybridCache

The cache data store to be used. Defaults to None.

None

Raises:

Type Description
UnexpectedError

If initialization fails.

add_loader(loader)

Add loader to the pipeline loader.

This method defines the process of adding loader to the pipeline loader.

Parameters:

Name Type Description Default
loader BaseLoader

The loader to be added.

required

Raises:

Type Description
UnexpectedError

If adding the loader fails.

load(source, **kwargs)

Load the document from the given file path.

This method defines the process of loading the document using loaders.

Parameters:

Name Type Description Default
source str

Might be file path, URL, the content itself.

required
**kwargs Any

Additional keyword arguments.

{}
Kwargs

cache_data_store (BaseHybridCache, optional): Cache used for this call, overriding the one given at init. Defaults to None, which uses the one given at init. ttl (int, optional): The TTL of the cache. Defaults to None.

Returns:

Type Description
list[dict[str, Any]]

List[dict[str, Any]]: A list of dictionaries containing loaded content and metadata.

Raises:

Type Description
UnexpectedError

If a loader fails with an error that is not already a BaseError.