You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**`"base64"`** (default): Returns base64-encoded image data
88
+
-**`"url"`**: Returns presigned HTTPS URLs, convenient for LLMs and UIs that accept remote image URLs
89
+
-**`"text"`**: Converts page images to markdown text via OCR
90
+
91
+
### Choosing Between Formats
92
+
93
+
**base64 vs url**: Both formats pass images to LLMs for visual understanding and produce similar inference results. However, `url` is lighter on network transfer since only the URL is sent to your application (the LLM fetches the image directly). This can result in faster response times, especially when working with multiple images.
94
+
95
+
**When to use text**: Passing images to LLMs for inference can be slow and consume significant context tokens. Use `output_format="text"` when:
96
+
- You need **faster inference** speeds
97
+
- Your documents are **primarily text-based** (reports, articles, contracts)
98
+
- You're hitting **context length limits**
99
+
100
+
<Note>
101
+
If you're experiencing context limit issues with image-based retrieval, it may be because images aren't being passed correctly to the model. See [Generating Completions with Retrieved Chunks](/cookbooks/generating-completions-with-retrieved-chunks) for examples of properly passing images (both base64 and URLs) to vision-capable models like GPT-4o.
Copy file name to clipboardExpand all lines: python-sdk/retrieve_chunks.mdx
+24-4Lines changed: 24 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,7 +45,10 @@ description: "Retrieve relevant chunks from Morphik"
45
45
-`use_colpali` (bool, optional): Whether to use ColPali-style embedding model to retrieve the chunks (only works for documents ingested with`use_colpali=True`). Defaults to True.
46
46
-`folder_name` (str| List[str], optional): Optional folder scope. Accepts a single folder name or a list of folder names.
47
47
-`padding` (int, optional): Number of additional chunks/pages to retrieve before and after matched chunks (ColPali only). Defaults to 0.
48
-
-`output_format` (str, optional): Controls how image chunks are returned. Set to `"url"` to receive presigned URLs; omit orset to `"base64"` (default) to receive base64 content.
48
+
-`output_format` (str, optional): Controls how image chunks are returned:
49
+
-`"base64"` (default): Returns base64-encoded image data
50
+
-`"url"`: Returns presigned HTTPS URLs
51
+
-`"text"`: Converts images to markdown text via OCR
@@ -135,13 +138,30 @@ The `FinalChunkResult` objects returned by this method have the following proper
135
138
-`filename` (Optional[str]): Original filename
136
139
-`download_url` (Optional[str]): URL to download full document
137
140
138
-
## Image URL output
141
+
## Output Format Options
139
142
140
-
- When `output_format="url"`is provided, image chunks are returned as presigned HTTPS URLs in`content`. This is convenient for UIs and LLMs that accept remote image URLs (e.g., via `image_url`).
141
-
- When `output_format`is omitted orset to `"base64"` (default), image chunks are returned as base64 data (the SDK attempts to decode these into a `PIL.Image`for`FinalChunkResult.content`).
143
+
-**`"base64"` (default)**: Image chunks are returned as base64 data (the SDK attempts to decode these into a `PIL.Image`for`FinalChunkResult.content`).
144
+
-**`"url"`**: Image chunks are returned as presigned HTTPS URLs in`content`. This is convenient for UIs and LLMs that accept remote image URLs (e.g., via `image_url`).
145
+
-**`"text"`**: Image chunks are converted to markdown text via OCR. Use this when you need faster inference or when documents are mostly text-based.
142
146
- Text chunks are unaffected by `output_format`and are always returned as strings.
143
147
- The `download_url` field may be populated for image chunks. When using `output_format="url"`, it will typically match `content`for those chunks.
144
148
149
+
### When to Use Each Format
150
+
151
+
| Format | Best For |
152
+
|--------|----------|
153
+
|`base64`| Direct image processing, local applications |
154
+
|`url`| Web UIs, LLMs with vision capabilities (lighter on network) |
**base64 vs url**: Both formats pass images to LLMs for visual understanding and produce similar results. However, `url`is lighter on network transfer since only the URLis sent to your application (the LLM fetches the image directly). This can result in faster response times, especially with multiple images.
159
+
160
+
**When to use text**: Passing images to LLMs for inference can be slow and consume significant context tokens. Use `output_format="text"` when you need faster inference speeds or when your documents are primarily text-based.
161
+
162
+
If you're hitting context limits with images, it may be because they aren't being passed correctly to the model. See [Generating Completions with Retrieved Chunks](/cookbooks/generating-completions-with-retrieved-chunks) for examples of properly passing images (both base64 and URLs) to vision-capable models like GPT-4o.
163
+
</Note>
164
+
145
165
Tip: To download the original raw filefor a document, use [`get_document_download_url`](./get_document_download_url).
0 commit comments