Prerequisites
- Install the Morphik SDK:
pip install morphik
- Provide credentials via Morphik URI
- For the optional OpenAI example, set
OPENAI_API_KEY
Note on Async Support This guide uses the synchronousMorphik
client. An async versionAsyncMorphik
is also available for async workflows with the same API.
Note on Streaming Response streaming is not currently available in the Python SDK as of version 0.2.12. This feature will be added in a future release.
1. Initialize the Morphik client
2. Multimodal ingestion (ColPali)
This path indexes the original file contents directly, yielding higher accuracy for scanned pages, tables, and images.Wait for processing to complete
3. Text ingestion (OCR + chunking)
This path OCRs the document before chunking it, making the text immediately available for retrieval.4. Query with Morphik completion
Generate a completion directly using Morphik’s configured LLM.Multimodal query (ColPali)
Text query (standard)
5. Query with system prompt override
Override the default system prompt to customize the LLM’s behavior and response style.Legal expert example
Custom prompt template
You can also override the prompt template that formats the context and question:6. Retrieve chunks for your own LLM
For production workloads, retrieve Morphik’s curated chunks and forward them to your preferred LLM. This gives you full control over prompts, orchestration, and rate limits.Step 1: Retrieve relevant chunks
Step 2: Forward to your LLM (OpenAI example)
Text-only chunks with OpenAI
Multimodal chunks with OpenAI (vision)
Step 3: Using other LLM providers
The same pattern works with any LLM provider. Morphik handles retrieval and chunking; you control the completion.Anthropic Claude
Google Gemini
7. Working with folders and user scopes
Morphik supports organizing documents into folders and scoping queries by end users.8. Additional features
Chat history
Maintain conversation context across queries:Structured output
Extract structured data using Pydantic models:Custom LLM configuration
Use a different LLM for specific queries:Summary
The Morphik Python SDK provides flexible integration options:- Managed completions: Use Morphik’s configured LLM with optional system prompt overrides
- Bring your own LLM: Retrieve curated chunks and forward to any LLM provider
- Multimodal support: Handle both text and visual content seamlessly
- Full control: Override system prompts, prompt templates, and completion parameters
- Organization: Folder and user-based scoping for multi-tenant applications