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
- Drag the
MistralOCRDocumentConvertercomponent onto the canvas from the Component Library. - Click on the component to open the configuration panel.
- On the General tab:
- Create a secret with your Mistral API key. Use
MISTRAL_API_KEYas the environment variable name. For instructions, see Create Secrets.
- Create a secret with your Mistral API key. Use
- Go to the Advanced tab to configure
model,include_image_base64,pages, andcleanup_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
| Parameter | Type | Description |
|---|---|---|
sources | List[Union[str, Path, ByteStream, ...]] | A list of file paths, URLs, ByteStream objects, or Mistral file identifiers to convert. Local files are automatically uploaded. |
meta | Optional[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_schema | Optional[Type[BaseModel]] | A Pydantic model schema for structured bounding box region annotations. |
document_annotation_schema | Optional[Type[BaseModel]] | A Pydantic model schema for structured document-level annotations. |
Outputs
| Parameter | Type | Description |
|---|---|---|
documents | List[Document] | The extracted text as Haystack Documents. Pages are separated by form feed characters (\f). |
raw_mistral_response | List[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:
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | Secret | Secret.from_env_var("MISTRAL_API_KEY") | The Mistral API key. |
model | str | mistral-ocr-2505 | The Mistral OCR model to use. |
include_image_base64 | bool | False | Whether to include base64-encoded images in the output. |
pages | Optional[List[int]] | None | A list of specific page numbers (0-indexed) to extract from multi-page documents. If not set, all pages are extracted. |
image_limit | Optional[int] | None | The maximum number of images to process per document. |
image_min_size | Optional[int] | None | The minimum image size (in pixels) to include in processing. |
cleanup_uploaded_files | bool | True | Whether 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.
| Parameter | Type | Default | Description |
|---|---|---|---|
sources | List | A list of file paths or sources to convert. | |
meta | Optional[Union[Dict, List[Dict]]] | None | Metadata to add to the resulting documents. |
bbox_annotation_schema | Optional[Type[BaseModel]] | None | Pydantic schema for bounding box annotations. |
document_annotation_schema | Optional[Type[BaseModel]] | None | Pydantic schema for document annotations. |
Related Information
Was this page helpful?