Skip to main content
The MistralOCR chef extracts text from images and PDF files using Mistral’s OCR API, returning structured MarkdownDocument objects for further processing.

Installation

You need a Mistral API key. Set the MISTRAL_API_KEY environment variable or pass it directly.

Initialization

Parameters

model
str
default:"mistral-ocr-latest"
The Mistral OCR model to use.
api_key
Optional[str]
default:"None"
Mistral API key. Falls back to the MISTRAL_API_KEY environment variable.

Methods

process()

Process an image or PDF file and return a MarkdownDocument.

Parameters

path
Union[str, Path]
required
Path to the image or PDF file.

Returns

MarkdownDocument containing the extracted text as markdown content.

process_batch()

Process multiple image or PDF files at once.

Parameters

paths
list[Union[str, Path]]
required
List of file paths to process.

Returns

list[MarkdownDocument] where each document contains extracted text from a file.

parse()

Parse raw text into a Document (wraps text as-is, since OCR operates on files).

Parameters

text
str
required
Raw text to wrap into a Document.

Returns

Document containing the provided text.

Supported File Types

TypeExtensions
Images.png, .jpg, .jpeg, .gif, .bmp, .webp, .tiff, .tif
Documents.pdf

Usage

Standalone

Pipeline

Use .process_with("mistral") to add OCR to a pipeline:

OCR + RAG Pipeline

Build a complete pipeline from scanned documents to vector database:

OCR + Semantic Chunking

Use semantic chunking on OCR output for intelligent retrieval boundaries:

Integration with Chunkers

MistralOCR returns a MarkdownDocument, making it compatible with any chunker:

Notes

  • OCR quality depends on image resolution and clarity
  • Large PDFs are processed page-by-page and concatenated with double newlines
  • The extracted text is returned as markdown, preserving structure from the source document
  • API calls are synchronous by default; use aprocess() for async execution