File loaders load files from various sources into File objects that can be processed by document extractors.

Available file loaders

Available file loaders

LoaderSource
Filesystem File LoaderLocal filesystem
AWS S3 File LoaderAWS S3 (and S3-compatible: MinIO, Ceph)
Google Cloud Storage LoaderGoogle Cloud Storage
Azure Blob Storage LoaderAzure Blob Storage
Custom LoadersAny source
Filesystem file loader

Filesystem file loader

FilesystemFileLoader loads files from the local filesystem. It accepts a root parameter that restricts access. Any path resolving outside the root is rejected, preventing path traversal.

Installation: Core library (no extra required)

Example:

from pathlib import Path
from mistralai.search.toolkit.ingestion.loaders import FilesystemFileLoader

loader = FilesystemFileLoader(root="/data/documents")
file = await loader.load_file(Path("report.pdf"))

Limiting file size:

Use max_file_size to reject files that exceed a given size in bytes. The check is performed via a metadata lookup before loading, so oversized files are never read into memory:

from mistralai.search.toolkit.ingestion.loaders import FilesystemFileLoader

loader = FilesystemFileLoader(
    root="/data/documents",
    max_file_size=50 * 1024 * 1024,  # 50 MiB
)
file = await loader.load_file("report.pdf")

A FileSizeLimitExceededException is raised when a file exceeds the limit.

Parameters:

ParameterTypeDefaultDescription
rootPath | str"/"Root directory. Paths resolving outside this directory are rejected.
max_file_sizeint | NoneNoneMaximum file size in bytes. Files exceeding this limit are rejected before loading. None means no limit.

Security:

The root parameter prevents path traversal attacks. Any path resolving outside the root directory is rejected before attempting to open the file.

AWS S3 file loader

AWS S3 file loader

Load files from AWS S3 buckets (or S3-compatible services like MinIO, Ceph). S3FileLoader is a convenience wrapper around FileLoader backed by S3BlobStorage.

Installation:

uv add "mistralai-search-toolkit-storage-s3"

Example:

from mistralai.search.toolkit.plugins.storage.s3 import S3FileLoader

loader = S3FileLoader(
    bucket_name="my-bucket",
    region_name="us-east-1",
    endpoint_url="http://localhost:9000",  # optional, for MinIO / other S3-compatible backends
)

file = await loader.load_file("reports/example.pdf")

Parameters (S3FileLoader):

ParameterTypeDefaultDescription
bucket_namestr(required)S3 bucket name
region_namestr | NoneNoneAWS region (falls back to the SDK/env default)
endpoint_urlstr | NoneNoneCustom endpoint URL (for MinIO, Ceph, or other S3-compatible services)
aws_access_key_idstr | NoneNoneExplicit AWS access key (falls back to the credential chain)
aws_secret_access_keystr | NoneNoneExplicit AWS secret key
max_file_sizeint | NoneNoneReject files larger than this many bytes

Authentication:

Uses the default AWS credentials chain:

  • IAM role (recommended for production)
  • Environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
  • AWS credentials file: ~/.aws/credentials
Azure Blob Storage loader

Azure Blob Storage loader

Load files from Azure Blob Storage. AzureBlobFileLoader is a convenience wrapper around FileLoader backed by AzureBlobStorage.

Installation:

uv add "mistralai-search-toolkit-storage-azure"

Example:

from mistralai.search.toolkit.plugins.storage.azure import AzureBlobFileLoader

loader = AzureBlobFileLoader(
    container_name="my-container",
    account_url="https://myaccount.blob.core.windows.net",
    use_workload_identity=True,  # or pass azure_connection_string=... for connection-string auth
)

file = await loader.load_file("reports/example.pdf")

Parameters (AzureBlobFileLoader):

ParameterTypeDefaultDescription
container_namestr(required)Azure Blob Storage container name
azure_connection_stringstr | NoneNoneConnection string for authentication (required unless use_workload_identity is True)
account_urlstr | NoneNoneAzure storage account URL, e.g. https://myaccount.blob.core.windows.net (required when use_workload_identity is True)
use_workload_identityboolFalseUse workload identity for authentication (recommended for Azure VMs/Functions)
max_file_sizeint | NoneNoneReject files larger than this many bytes

Authentication:

  • Workload Identity (recommended for Azure VMs/Functions)
  • Connection string: Pass via azure_connection_string parameter or set AZURE_STORAGE_CONNECTION_STRING environment variable
  • SAS token: Time-limited access (configure via account credentials)
Google Cloud Storage loader

Google Cloud Storage loader

Load files from Google Cloud Storage (GCS). GCSFileLoader is a convenience wrapper around FileLoader backed by GCSBlobStorage.

Installation:

uv add "mistralai-search-toolkit-storage-gcs"

Example:

from mistralai.search.toolkit.plugins.storage.gcs import GCSFileLoader

loader = GCSFileLoader(
    bucket_name="my-bucket",
    service_account_file="/path/to/service-account.json",  # optional; falls back to ADC
)

file = await loader.load_file("reports/example.pdf")

Parameters (GCSFileLoader):

ParameterTypeDefaultDescription
bucket_namestr(required)GCS bucket name
service_account_filestr | NoneNonePath to service account JSON file. If not provided, uses Application Default Credentials (ADC)
api_rootstr | NoneNoneCustom API endpoint for a local emulator (e.g. fake-gcs-server); falls back to STORAGE_EMULATOR_HOST
max_file_sizeint | NoneNoneReject files larger than this many bytes

Authentication:

  • Application Default Credentials (ADC) (recommended): uses credentials from environment, metadata service, or gcloud CLI
  • Service account file: Pass via service_account_file parameter or set GOOGLE_APPLICATION_CREDENTIALS environment variable
Batch loading

Batch loading

Load multiple files with concurrency control:

import asyncio
from mistralai.search.toolkit.ingestion.loaders import FileLoader
from mistralai.search.toolkit.plugins.storage.s3 import S3FileLoader

async def load_files_batch(
    loader: FileLoader,
    paths: list[str],
    max_concurrent: int = 10,
) -> list:
    """Load multiple files concurrently with semaphore."""
    semaphore = asyncio.Semaphore(max_concurrent)

    async def load_with_semaphore(path: str):
        async with semaphore:
            try:
                return await loader.load_file(path)
            except Exception as e:
                print(f"Failed to load {path}: {e}")
                return None

    results = await asyncio.gather(
        *[load_with_semaphore(p) for p in paths],
        return_exceptions=False,
    )
    return [f for f in results if f is not None]

# Usage
loader = S3FileLoader(bucket_name="my-bucket")
files = await load_files_batch(
    loader,
    ["doc1.pdf", "doc2.pdf", "doc3.pdf"],
    max_concurrent=5,
)
i
Information

Advanced: each cloud loader wraps a generic FileLoader over an ObjectStorage backend. For full control (custom storage settings, a backend not covered by a wrapper), construct it directly: FileLoader(lambda: S3BlobStorage(...)).

Custom loaders

Custom loaders

Implement the FileLoader protocol for custom sources not covered above:

from pathlib import Path
from mistralai.search.toolkit.ingestion.loaders import FileLoader
from mistralai.search.toolkit.ingestion import File

class CustomFileLoader(FileLoader):
    """Load files from a custom source."""

    async def load_file(self, path: Path | str) -> File:
        # Implement your custom loading logic
        content = await self._fetch_from_custom_source(str(path))
        filename = Path(str(path)).name

        return File(
            path=str(path),
            name=filename,
            raw=content,
        )

    async def _fetch_from_custom_source(self, path: str) -> bytes:
        # Your implementation here
        ...