Prerequisites
- Install the Morphik SDK:
pip install morphik- Install OpenAI SDK:
pip install openai- Provide credentials via
MORPHIK_URIandOPENAI_API_KEY- Documents ingested with multimodal support (
use_colpali=True)
1. Ingest Documents with Multimodal Support
First, ingest your documents with multimodal retrieval enabled:2. Retrieve Chunks as Presigned URLs
Get chunks as URLs that can be sent directly to vision models:3. Send URLs to OpenAI
Send the presigned URLs to OpenAI’s vision model:4. Retrieve Chunks as Base64 Images
For cases where you need base64-encoded images:5. Send Base64 Images to OpenAI
Important Notes
Multimodal Ingestion and Retrieval
When you ingest withuse_colpali=True, you must retrieve with use_colpali=True:
Content Type Handling
Chunks from PDFs ingested with multimodal support will have:chunk.content_type="application/pdf"(original document type)chunk.content= PIL Image object (actual content)
"image/png" as the MIME type:
Output Format Comparison
| Format | When to Use | Pros | Cons |
|---|---|---|---|
output_format="url" | Production, large images | No encoding overhead, faster | URLs expire after some time |
output_format=None (base64) | Small images, offline processing | Always available | Larger payload size |
Use Cases
This pattern is ideal for:- Document Q&A over visual documents (PDFs, scans, diagrams)
- Report generation from technical documentation with charts and tables
- Visual data analysis combining text and image understanding
- Multi-document synthesis aggregating information across documents
- Chart and diagram interpretation using vision-capable models
- Technical specification review analyzing mixed text-visual content
Best Practices
1. Choose the Right Output Format
Use URLs for production workloads with large images:2. Handle Chunk Padding
Usepadding to include adjacent chunks/pages for better context:
3. Filter with Metadata
Combine retrieval with metadata filtering for precise results:Running the Example
Related Cookbooks
- Complex Metadata Filtering - Advanced document filtering with dates, arrays, and more
- Python SDK Basic Operations - Core Morphik operations

