> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mixpeek.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Visual document retrieval

> Upload PDFs and search their pages by what they look like: maps, charts, tables and forms, with no OCR.

Upload PDFs and search their pages by what they look like: maps, charts, tables and forms, with no OCR. Each page becomes its own document with a page number, and a ColQwen2 late-interaction index is one uncomment away.

> [card] [Jump to the manifest](#the-manifest)
>
> `colpali-visual-document-retrieval.namespace.yaml`: apply it with one API call, then read the walkthrough below to change it.

## At a glance

| | |
| - | - |
| **Creates** | 1 namespace, 1 bucket, 1 collection, 2 retrievers |
| **Extractors** | [`image_extractor`](https://docs.mixpeek.com/docs/extract/extractors#image) v1 |
| **Daily spend budget** | 1 USD, set on the namespace. Queries are not capped. |
| **Sample data** | 4 objects, uploaded to `documents` when you apply |

## How the pieces connect

Buckets hold what you upload, collections turn it into searchable documents, and retrievers answer queries over the collections.

```mermaid theme={null}
flowchart LR
  b0[("documents")]
  c1["pages<br/>image_extractor v1"]
  r2{{"find-pages"}}
  r3{{"find-pages-like"}}
  b0 --> c1
  c1 --> r2
  c1 --> r3
```

## Deploy it

**1. Get the manifest**

```bash theme={null}
# Copy the manifest from the bottom of this page into colpali-visual-document-retrieval.namespace.yaml
```

**2. Validate it**

Validate runs every check apply runs and creates nothing. Fix each entry in `errors`, then run it again.

```bash theme={null}
curl -X POST https://api.mixpeek.com/v1/manifest/validate \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -F "manifest_file=@colpali-visual-document-retrieval.namespace.yaml"
```

**3. Apply it**

Apply creates every resource in one call. `wait_for_seed=true` also waits until the sample objects are processed, so the first query below has documents to return.

```bash theme={null}
curl -X POST "https://api.mixpeek.com/v1/manifest/apply?wait_for_seed=true" \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -F "manifest_file=@colpali-visual-document-retrieval.namespace.yaml"
```

The response lists each resource with its outcome in `resources`. Apply refuses a resource that already exists and rolls the whole apply back, so to apply the file again over this namespace add `?mode=create_missing`, which creates only what is missing.

## Run the first query

Look up the namespace id by name, then run `find-pages`. Check `status` and `warnings` along with `documents`: a run that times out still answers 200, with `status` `degraded`.

```bash cURL theme={null}
NAMESPACE_ID=$(curl -s https://api.mixpeek.com/v1/namespaces/colpali-visual-document-retrieval \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" | jq -r .namespace_id)

curl -X POST https://api.mixpeek.com/v1/retrievers/find-pages/execute \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "X-Namespace: $NAMESPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{"inputs": {"query": "a colored map with a legend"}}' \
  | jq '{status, warnings, documents: [.documents[] | {document_id, score}]}'
```

```python Python theme={null}
import os, requests

AUTH = {"Authorization": f"Bearer {os.environ['MIXPEEK_API_KEY']}"}
ns = requests.get("https://api.mixpeek.com/v1/namespaces/colpali-visual-document-retrieval", headers=AUTH).json()

run = requests.post(
    "https://api.mixpeek.com/v1/retrievers/find-pages/execute",
    headers={**AUTH, "X-Namespace": ns["namespace_id"]},
    json={"inputs": {"query": "a colored map with a legend"}},
).json()

print(run["status"], run["warnings"])  # "completed" on a clean run
for doc in run["documents"]:
    print(doc["document_id"], doc["score"])
```

```javascript JavaScript theme={null}
const auth = { Authorization: `Bearer ${process.env.MIXPEEK_API_KEY}` };
const ns = await fetch("https://api.mixpeek.com/v1/namespaces/colpali-visual-document-retrieval", { headers: auth }).then((r) => r.json());

const run = await fetch("https://api.mixpeek.com/v1/retrievers/find-pages/execute", {
  method: "POST",
  headers: { ...auth, "X-Namespace": ns.namespace_id, "Content-Type": "application/json" },
  body: JSON.stringify({"inputs": {"query": "a colored map with a legend"}}),
}).then((r) => r.json());

console.log(run.status, run.warnings); // "completed" on a clean run
for (const doc of run.documents) console.log(doc.document_id, doc.score);
```

## Add your own data

Each object you add to a bucket is processed by every collection that reads it. This adds one object to `documents`. `NAMESPACE_ID` is the id from the namespace lookup above.

```bash cURL theme={null}
curl -X POST "https://api.mixpeek.com/v1/buckets/documents/objects?auto_process=true" \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "X-Namespace: $NAMESPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{"title": "example", "doc_type": "example", "blobs": [{"property": "file", "type": "pdf", "data": "https://example.com/report.pdf"}]}'
```

```python Python theme={null}
import os, requests

HEADERS = {"Authorization": f"Bearer {os.environ['MIXPEEK_API_KEY']}", "X-Namespace": os.environ["NAMESPACE_ID"]}

obj = requests.post(
    "https://api.mixpeek.com/v1/buckets/documents/objects",
    params={"auto_process": "true"},
    headers=HEADERS,
    json={
        "title": "example",
        "doc_type": "example",
        "blobs": [
            {
                "property": "file",
                "type": "pdf",
                "data": "https://example.com/report.pdf"
            }
        ]
    },
).json()
print(obj["object_id"], obj["status"])  # PENDING until processing finishes
```

```javascript JavaScript theme={null}
const headers = {
  Authorization: `Bearer ${process.env.MIXPEEK_API_KEY}`,
  "X-Namespace": process.env.NAMESPACE_ID,
  "Content-Type": "application/json",
};

const obj = await fetch("https://api.mixpeek.com/v1/buckets/documents/objects?auto_process=true", {
  method: "POST",
  headers,
  body: JSON.stringify({
    "title": "example",
    "doc_type": "example",
    "blobs": [
      {
        "property": "file",
        "type": "pdf",
        "data": "https://example.com/report.pdf"
      }
    ]
  }),
}).then((r) => r.json());
console.log(obj.object_id, obj.status); // PENDING until processing finishes
```

The object is `PENDING` until processing finishes, then `COMPLETED` or `FAILED`. [Buckets and objects](https://docs.mixpeek.com/docs/ingest/buckets.md) covers object states, retries and duplicates.

## Retrievers

### `find-pages`

Describe what a page shows (a map, a chart, a form, a table) and get back the pages that look like it, each with its title and page\_number.

**Stages:** [`feature_search`](https://docs.mixpeek.com/docs/retrieve/stages#feature-search)

**Searches:** `pages`

| Input | Type | Required | Description |
| - | - | - | - |
| `query` | text | yes | What the page shows, in plain words |

### `find-pages-like`

Pass an image of a page and get back the pages with the closest layout and content, across every PDF.

**Stages:** [`feature_search`](https://docs.mixpeek.com/docs/retrieve/stages#feature-search)

**Searches:** `pages`

| Input | Type | Required | Description |
| - | - | - | - |
| `query` | text | yes | The query page: a public https URL of a page image, or a base64 data URI (data:image/png;base64,...) |

## Collections

Each collection runs one extractor over a bucket, or over another collection's documents.

> [accordion] pages
>
> image\_extractor\@v1 over bucket documents: one document per PDF page, with page\_number, total\_pages and a page thumbnail, embedded by SigLIP.
>
> **Reads** bucket `documents` with [`image_extractor`](https://docs.mixpeek.com/docs/extract/extractors#image) v1.
>
> **Inputs:** `image` ← `file`
>
> **Copied onto each document:** `title`, `doc_type`

## The manifest

Every resource above comes from this file. Change it and apply it again with `?mode=upsert` to update what exists. [Manifests](https://docs.mixpeek.com/docs/manage/manifests.md) documents each field.

```yaml colpali-visual-document-retrieval.namespace.yaml expandable theme={null}
# colpali-visual-document-retrieval: one manifest spins up a namespace that searches
# document pages by what they look like.
# Platform manifest schema (GET /v1/discovery/schema). Validate with POST /v1/manifest/validate,
# apply with POST /v1/manifest/apply. You upload whole PDFs; image_extractor splits each one
# into pages and embeds every page as an image with SigLIP (768 dimensions), so a text query
# or a page image finds maps, charts, tables and forms without OCR.
# Applying a SECOND time, over a namespace this file already created: use
# POST /v1/manifest/apply?mode=create_missing, which creates what is missing and leaves
# what exists alone. The default, create_only, fails the WHOLE apply and rolls it back if
# any resource already exists. Use mode=upsert to also patch resources that exist but have
# drifted from this file.
version: '1.0'
metadata:
  name: colpali-visual-document-retrieval
  description: "Guide template colpali-visual-document-retrieval: text and image search over PDF pages, one document per page."
namespaces:
  - name: colpali-visual-document-retrieval
    description: "Everything below lives in this namespace."
    feature_extractors:
      - name: image_extractor
        version: v1
      # Uncomment with the page-tokens collection below for ColQwen2 late interaction.
      # - name: colqwen_extractor
      #   version: v1
    # Daily spend budget, in dollars of what you are charged (1,000 credits a dollar).
    # New batches pause once the namespace has spent this much today; queries are not capped.
    # Raise it later on the namespace: PATCH /v1/namespaces/<id> {"spend_budget": {"daily_usd": N}}.
    budget:
      daily_usd: 1

buckets:
  - name: documents
    namespace: colpali-visual-document-retrieval
    description: "Whole PDFs, one object per file. Pages are split out by the collection, so nothing is rendered client-side."
    schema:
      properties:
        file:
          type: pdf
          required: true
        title:
          type: string
        doc_type:
          type: string

collections:
  - name: pages
    namespace: colpali-visual-document-retrieval
    description: "image_extractor@v1 over bucket documents: one document per PDF page, with page_number, total_pages and a page thumbnail, embedded by SigLIP."
    source:
      type: bucket
      bucket: documents
    feature_extractor:
      name: image_extractor
      version: v1
      input_mappings:
        image: file
      field_passthrough:
        - source_path: title
        - source_path: doc_type
    enabled: true

# ColQwen2 late interaction: one 128-dimensional vector per image patch of each page,
# scored against the query's token vectors by MaxSim. A search over this feature runs only
# on a pinned namespace (PATCH /v1/namespaces/<id> {"pinned": true}), which a free
# organization cannot hold, so it is left out of the one-click apply. Uncomment it, the
# colqwen_extractor entry above and the find-pages-late-interaction retriever below, then
# apply again with ?mode=create_missing.
#  - name: page-tokens
#    namespace: colpali-visual-document-retrieval
#    description: "colqwen_extractor@v1 over bucket documents: one multi-vector document per PDF page."
#    source:
#      type: bucket
#      bucket: documents
#    feature_extractor:
#      name: colqwen_extractor
#      version: v1
#      input_mappings:
#        image: file
#      field_passthrough:
#        - source_path: title
#        - source_path: doc_type
#    enabled: true

retrievers:
  - name: find-pages
    namespace: colpali-visual-document-retrieval
    description: "Describe what a page shows (a map, a chart, a form, a table) and get back the pages that look like it, each with its title and page_number."
    collections:
      - pages
    input_schema:
      query:
        type: text
        required: true
        description: "What the page shows, in plain words"
    stages:
      - stage_name: search
        stage_id: feature_search
        parameters:
          searches:
            - feature_uri: "mixpeek://image_extractor@v1/google_siglip_base_v1"
              query:
                input_mode: text
                value: "{{INPUT.query}}"
              top_k: 50
          final_top_k: 10
    tags:
      - template:colpali-visual-document-retrieval
  - name: find-pages-like
    namespace: colpali-visual-document-retrieval
    description: "Pass an image of a page and get back the pages with the closest layout and content, across every PDF."
    collections:
      - pages
    input_schema:
      query:
        type: text
        required: true
        description: "The query page: a public https URL of a page image, or a base64 data URI (data:image/png;base64,...)"
    stages:
      - stage_name: search
        stage_id: feature_search
        parameters:
          searches:
            - feature_uri: "mixpeek://image_extractor@v1/google_siglip_base_v1"
              query:
                input_mode: content
                value: "{{INPUT.query}}"
              top_k: 50
          final_top_k: 10
    tags:
      - template:colpali-visual-document-retrieval
#  - name: find-pages-late-interaction
#    namespace: colpali-visual-document-retrieval
#    description: "Text query scored by ColQwen2 MaxSim against every page's patch vectors. Needs a pinned namespace."
#    collections:
#      - page-tokens
#    input_schema:
#      query:
#        type: text
#        required: true
#        description: "What the page shows or says, in plain words"
#    stages:
#      - stage_name: search
#        stage_id: feature_search
#        parameters:
#          searches:
#            - feature_uri: "mixpeek://colqwen_extractor@v1/colqwen2_v1"
#              query:
#                input_mode: text
#                value: "{{INPUT.query}}"
#              top_k: 20
#          final_top_k: 10
#    tags:
#      - template:colpali-visual-document-retrieval

# Four US federal government PDFs (public domain), 16 pages in all: two USGS fact sheets
# with maps, charts and photos, and two IRS forms. The seed reads them from the agencies'
# own sites.
seed:
  - bucket: documents
    max_objects: 4
    objects:
      - {blobs: {file: "https://pubs.usgs.gov/fs/2010/3050/fs2010-3050.pdf"}, title: "Breccia-Pipe Uranium Mining in Northern Arizona (USGS Fact Sheet 2010-3050)", doc_type: fact_sheet}
      - {blobs: {file: "https://pubs.usgs.gov/fs/2018/3007/fs20183007.pdf"}, title: "Groundwater Quality in the North San Francisco Bay Shallow Aquifer (USGS Fact Sheet 2018-3007)", doc_type: fact_sheet}
      - {blobs: {file: "https://www.irs.gov/pub/irs-pdf/fw9.pdf"}, title: "Form W-9, Request for Taxpayer Identification Number and Certification", doc_type: tax_form}
      - {blobs: {file: "https://www.irs.gov/pub/irs-pdf/f1040.pdf"}, title: "Form 1040, U.S. Individual Income Tax Return", doc_type: tax_form}
```

## Hand it to an agent

Paste this prompt into Claude Code, Cursor or another coding agent. To give the agent this whole page instead, use **Copy page** in the menu at the top of the page, or point it at the page's Markdown at `https://mixpeek.com/docs/templates/colpali-visual-document-retrieval.md`.

```text Prompt theme={null}
Set up the Mixpeek "Visual document retrieval" template in my organization. My API key is in MIXPEEK_API_KEY.
1. Save the manifest at the bottom of https://mixpeek.com/docs/templates/colpali-visual-document-retrieval as colpali-visual-document-retrieval.namespace.yaml.
2. POST it to https://api.mixpeek.com/v1/manifest/validate as the multipart field manifest_file, with the header Authorization: Bearer $MIXPEEK_API_KEY. Fix every entry in errors and validate again.
3. POST the same file to https://api.mixpeek.com/v1/manifest/apply?wait_for_seed=true. Every entry in resources should be created.
4. GET https://api.mixpeek.com/v1/namespaces/colpali-visual-document-retrieval and keep namespace_id. Send it as the X-Namespace header on every call below.
5. POST {"inputs": {"query": "a colored map with a legend"}} to https://api.mixpeek.com/v1/retrievers/find-pages/execute. Read documents, check that status is completed, and print warnings.
Reference for this template: https://mixpeek.com/docs/templates/colpali-visual-document-retrieval.md
```

## How it works

The `pages` collection runs `image_extractor`, which splits each uploaded PDF into one document per page. Every page carries `page_number` (from 1), `total_pages`, a `thumbnail_url`, and the object's `title` and `doc_type`.

Each page is embedded as an image with Google SigLIP (`google/siglip-base-patch16-224`, 768 dimensions). A sentence and a page that matches it land close together. No OCR runs: the page is matched by what it looks like, such as a map, a chart or a form with boxes.

SigLIP sees each page at 224 by 224 pixels. Layout, figures and large headings survive at that size; body text does not. For questions about the words on a page, see [ColQwen2 late interaction](#colqwen2-late-interaction) below, or index the text itself with the [universal extractor](https://docs.mixpeek.com/docs/extract/extractors.md#universal).

The two retrievers search the same feature, `mixpeek://image_extractor@v1/google_siglip_base_v1`, with different query modes:

| Retriever | `input_mode` | The query |
| - | - | - |
| `find-pages` | `text` | A description in words |
| `find-pages-like` | `content` | An image of a page, as a data URI or an https URL |

Use `title` and `page_number` to deep-link to a result page in your viewer. Each change below is an edit to the manifest; apply it again with `?mode=upsert`. Extractor parameters change only while a collection is empty, so to embed pages another way, add a collection and trigger it, as in the ColQwen2 steps.

## Search with a page image

`find-pages-like` finds pages that look like one you already have, such as a scan or a screenshot. Render it to PNG, then send it as a data URI.

```bash title="Render page 1 of report.pdf to page-1.png" theme={null}
pdftoppm -png -r 100 -f 1 -l 1 -singlefile report.pdf page-1
```

```bash cURL theme={null}
base64 < page-1.png | tr -d '\n' > page.b64
jq -n --rawfile b page.b64 '{inputs: {query: ("data:image/png;base64," + $b)}}' > body.json

curl -X POST https://api.mixpeek.com/v1/retrievers/find-pages-like/execute \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "X-Namespace: $NAMESPACE_ID" \
  -H "Content-Type: application/json" \
  -d @body.json \
  | jq '{status, warnings, documents: [.documents[] | {title, page_number, doc_type, score}]}'
```

## Filter by document type

Pass `filters` next to `inputs` to narrow a search per call. This searches the tax forms only:

```bash cURL theme={null}
curl -X POST https://api.mixpeek.com/v1/retrievers/find-pages/execute \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "X-Namespace: $NAMESPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{"inputs": {"query": "a signature box at the bottom of a form"}, "filters": {"AND": [{"field": "doc_type", "operator": "eq", "value": "tax_form"}]}}' \
  | jq '{status, documents: [.documents[] | {title, page_number, score}]}'
```

## Return the best page of each PDF

A long report can fill the list with its own pages. Add a [`group_by`](https://docs.mixpeek.com/docs/retrieve/stages#group-by) stage after the search in `find-pages` to keep the top page of each PDF:

```yaml title="colpali-visual-document-retrieval.namespace.yaml (find-pages stages)" theme={null}
    stages:
      - stage_name: search
        stage_id: feature_search
        parameters:
          searches:
            - feature_uri: "mixpeek://image_extractor@v1/google_siglip_base_v1"
              query:
                input_mode: text
                value: "{{INPUT.query}}"
              top_k: 50
          final_top_k: 10
      - stage_name: best_page_per_pdf
        stage_id: group_by
        parameters:
          group_by_field: source_object_id
          max_per_group: 1
```

Raise `max_per_group` to show the top 2 or 3 pages of each PDF.

## ColQwen2 late interaction

SigLIP gives each page one vector. ColQwen2 (`vidore/colqwen2-v1.0`, built on Qwen2-VL-2B) gives each page one 128-dimension vector per image patch. A text query is encoded into one vector per token, and a page scores by MaxSim: each query token takes its best-matching patch, and the scores add up. Small text, table cells and figure labels each get their own vectors, so a query about a specific value can find the page that shows it.

The manifest ships these blocks commented out. A ColQwen2 search runs only on a pinned namespace; on an unpinned one it refuses with an error that says how to pin.

**1. Pin the namespace**

A pin is billed by the hour, and a free organization cannot hold one. Each Mixpeek plane allows a fixed number of pinned namespaces; past that, the pin is refused with the cap named.

```bash cURL theme={null}
curl -X PATCH https://api.mixpeek.com/v1/namespaces/$NAMESPACE_ID \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"pinned": true}'
```

The ColQwen2 model scales to zero when idle, so the first query after a quiet spell waits for it to load. To keep one query encoder replica running, send `{"pinned": {"enabled": true, "warm_query_encoder": true}}` as the body. Each replica-hour is billed to the namespace as its own invoice line.

**2. Uncomment the ColQwen2 blocks**

Uncomment three blocks in the manifest: the `colqwen_extractor` entry under `feature_extractors`, the `page-tokens` collection, and the `find-pages-late-interaction` retriever. `find-pages-late-interaction` searches `mixpeek://colqwen_extractor@v1/colqwen2_v1`. Like `image_extractor`, `colqwen_extractor` splits a PDF into one document per page with `page_number`.

**3. Apply, then process the stored PDFs**

Apply the file with `?mode=create_missing`, which creates the new resources and leaves existing ones alone. Then process the PDFs already in the bucket through the new collection:

```bash cURL theme={null}
curl -X POST https://api.mixpeek.com/v1/collections/page-tokens/trigger \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "X-Namespace: $NAMESPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{}'
```

> [!NOTE]
>
> The [`maxsim_rerank`](https://docs.mixpeek.com/docs/retrieve/stages#maxsim-rerank) stage re-scores the candidates of an earlier search with a multi-vector feature, reading tokens for those candidates only. Across two collections it matches each candidate on `root_object_id`, which is the source PDF. Every page of one PDF then gets the same score, so this pairing ranks whole files. Use it when each bucket object is a single page image.

## Visual or text retrieval

> [card] Search pages by how they look
>
> Use this template when pages carry meaning in maps, charts, diagrams or form layout, or when OCR on scans is unreliable.

> [card] [Search the words](https://docs.mixpeek.com/docs/templates/document-intelligence.md)
>
> Use text extraction for born-digital, text-heavy PDFs, exact keywords, or extracted fields and summaries.

## Further reading

* [ColPali: Efficient Document Retrieval with Vision Language Models](https://arxiv.org/abs/2407.01449), the paper that introduced late interaction over page images.
* [ViDoRe leaderboard](https://huggingface.co/spaces/vidore/vidore-leaderboard), a benchmark for visual document retrieval.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.