Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

MistralOCRDocumentConverter

Extract text from documents using Mistral's OCR API, with optional structured annotations.

Key Features

  • Extracts text from documents using Mistral's OCR model.
  • Accepts local files, URLs, and Mistral file IDs as input.
  • Automatically uploads local files to Mistral's file storage.
  • Outputs one Haystack Document per source, with all pages concatenated using form feed characters for accurate page-wise splitting.
  • Supports optional structured annotations using Pydantic schemas for bounding box and document-level analysis.
  • Returns both Haystack Documents and raw Mistral OCR API responses.

Configuration

  1. Drag the MistralOCRDocumentConverter component onto the canvas from the Component Library.
  2. Click on the component to open the configuration panel.
  3. On the General tab:
    1. Create a secret with your Mistral API key. Use MISTRAL_API_KEY as the environment variable name. For instructions, see Create Secrets.
  4. Go to the Advanced tab to configure model, include_image_base64, pages, and cleanup_uploaded_files.

Connections

MistralOCRDocumentConverter receives a list of file sources. It outputs a list of Document objects containing the extracted text and a list of raw API responses.

Source Code

To check this component's source code, open ocr_document_converter.py in the Haystack Core Integrations repository.

Usage Examples

Basic Configuration

  MistralOCRDocumentConverter:
type: haystack_integrations.components.converters.mistral.ocr_document_converter.MistralOCRDocumentConverter
init_parameters:
api_key:
type: env_var
env_vars:
- MISTRAL_API_KEY
strict: false
model: mistral-ocr-2505
cleanup_uploaded_files: true

Using the Component in a Pipeline

# haystack-pipeline
components:
MistralOCRDocumentConverter:
type: haystack_integrations.components.converters.mistral.ocr_document_converter.MistralOCRDocumentConverter
init_parameters:
api_key:
type: env_var
env_vars:
- MISTRAL_API_KEY
strict: false
model: mistral-ocr-2505

document_splitter:
type: haystack.components.preprocessors.document_splitter.DocumentSplitter
init_parameters:
split_by: page
split_length: 1

connections:
- sender: MistralOCRDocumentConverter.documents
receiver: document_splitter.documents

max_runs_per_component: 100

metadata: {}

Parameters

Inputs

ParameterTypeDescription
sourcesList[Union[str, Path, ByteStream, ...]]A list of file paths, URLs, ByteStream objects, or Mistral file identifiers to convert. Local files are automatically uploaded.
metaOptional[Union[Dict[str, Any], List[Dict[str, Any]]]]Metadata to add to all documents, or a list of metadata dicts (one per source).
bbox_annotation_schemaOptional[Type[BaseModel]]A Pydantic model schema for structured bounding box region annotations.
document_annotation_schemaOptional[Type[BaseModel]]A Pydantic model schema for structured document-level annotations.

Outputs

ParameterTypeDescription
documentsList[Document]The extracted text as Haystack Documents. Pages are separated by form feed characters (\f).
raw_mistral_responseList[Dict[str, Any]]The raw API responses from the Mistral OCR service for each input file.

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
api_keySecretSecret.from_env_var("MISTRAL_API_KEY")The Mistral API key.
modelstrmistral-ocr-2505The Mistral OCR model to use.
include_image_base64boolFalseWhether to include base64-encoded images in the output.
pagesOptional[List[int]]NoneA list of specific page numbers (0-indexed) to extract from multi-page documents. If not set, all pages are extracted.
image_limitOptional[int]NoneThe maximum number of images to process per document.
image_min_sizeOptional[int]NoneThe minimum image size (in pixels) to include in processing.
cleanup_uploaded_filesboolTrueWhether to delete uploaded files from Mistral's storage after processing.

Run Method Parameters

These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.

ParameterTypeDefaultDescription
sourcesListA list of file paths or sources to convert.
metaOptional[Union[Dict, List[Dict]]]NoneMetadata to add to the resulting documents.
bbox_annotation_schemaOptional[Type[BaseModel]]NonePydantic schema for bounding box annotations.
document_annotation_schemaOptional[Type[BaseModel]]NonePydantic schema for document annotations.