Skip to main content
Search PDFs page by page, native or scanned, by what each page says. Every page becomes a document with its extracted text, a description and an embedding, and results can be gathered back under the file they came from.

Jump to the manifest

document-intelligence.namespace.yaml: apply it with one API call, then read the walkthrough below to change it.

At a glance

How the pieces connect

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

Deploy it

1

Get the manifest

2

Validate it

Validate runs every check apply runs and creates nothing. Fix each entry in errors, then run it again.
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.
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 document-search. Check status and warnings along with documents: a run that times out still answers 200, with status degraded.

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.
The object is PENDING until processing finishes, then COMPLETED or FAILED. Buckets and objects covers object states, retries and duplicates.

Retrievers

Describe what you are looking for and get back the pages closest in meaning, from any file, best first. Stages: feature_search Searches: document-pages

document-search-by-file

The same search, with matching pages gathered under the file they came from: at most 3 pages per file, files ordered by their best page. Stages: feature_search → group_by Searches: document-pages

Collections

Each collection runs one extractor over a bucket, or over another collection’s documents.
universal_extractor@v1 over bucket documents: one document per page, carrying the page’s text (its text layer, or OCR for a scan), a generated description and a Gemini Embedding 2 vector. Feeds document-search and document-search-by-file.Reads bucket documents with universal_extractor v1.Inputs: content ← documentCopied onto each document: title, document_type, issuer

The manifest

Every resource above comes from this file. Change it and apply it again with ?mode=upsert to update what exists. Manifests documents each field.
document-intelligence.namespace.yaml

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/document-intelligence.md.
Prompt

How it works

universal_extractor reads the bucket’s document property, detects that the file is a document, and works page by page. Each page becomes one document in document-pages with these fields: Each page also gets a 3072-dimension vector from Gemini Embedding 2, which both retrievers search as mixpeek://universal_extractor@v1/gemini-embedding-2. Gemini Embedding 2 puts text, images, audio, video and PDFs in one vector space, so a text query compares directly with a page. The parameters in the manifest:
  • extract_text: true writes text. Turn it off and pages are still searchable by their vector, but there is no text to read, filter on, rerank or match with BM25.
  • generate_description: true writes description.
  • max_document_pages: 10 caps the pages processed per file (default 50, ceiling 200). Raise it before you upload longer files.
The seed mixes native PDFs (IRS forms W-9, W-4 and 1040) with scans (three USDA Farm Broadcasters Letters from 1984 to 1986), so you see both text paths. Each change below is an edit to the manifest. Apply it again with ?mode=upsert.

Find pages, then files

document-search returns pages. Two pages from the same file come back as two documents, each with its own score. document-search-by-file adds a group_by stage on source_object_id, the bucket object each page came from:
  • max_per_group: 3 keeps the 3 best pages of each file.
  • output_mode: all returns each group with its pages. Use first for one page per file, the best match, or flatten for a plain list with at most 3 pages per file.
Files come back in the order of their best page. final_top_k: 50 on the search gives the grouping enough pages to fill several files. To trace any page back to its file and the collections that processed it, read its lineage. Each document carries collection_id and document_id:
cURL

Filter by document type

Every page carries its file’s document_type and issuer, both indexed as keyword. Send filters in the execute body to search one kind of file:
cURL
To fix the filter into a retriever instead, put pre_filters on the search stage, beside parameters:
document-search stages, IRS forms only

Match form numbers and exact terms

An embedding treats a form number like “1040” as a loose number. Add a BM25 search over the extracted page text, which the namespace already indexes as text, and fuse it with the dense search:
document-search stages, dense plus BM25
The entry with lexical: true searches no vector: it matches the query’s words against the text index, and its feature_uri only scopes it to this collection. rrf merges the two lists by rank.

Rerank pages

A cross-encoder orders pages more precisely than vector distance. Add a rerank stage after the search and point it at text:
document-search stages, with a rerank stage
The stage’s default document_field is content, which these pages do not have, and a document without the field is left out. max_candidates caps how many pages are scored; at 4 CPU, 10 documents take about 8 seconds with BAAI__bge_reranker_v2_m3.

Change what is extracted

Edit feature_extractor.parameters on document-pages:
document-pages feature_extractor.parameters
  • generate_description: false skips the Gemini call that writes description.
  • output_dimensionality (256 to 3072) shrinks the vectors. It resizes the vector index, so set it before the first upload: a collection that already holds documents refuses a change to it.
New settings apply to objects processed after the change. Pages already written keep what they were extracted with.
The collection reads one property per object. To also index phone photos of documents, add a bucket with an image property and a second collection with universal_extractor over it. Both collections share the Gemini Embedding 2 space, so list both in the retriever’s collections and one query searches PDFs and photos together.

Next steps

Universal extractor

Every parameter and output field, for documents, images, audio and video.

Group By

Grouping modes, ordering within a group and caps on group position.

Classify documents

Label each file by type (contract, invoice, form) with a taxonomy.

Text extractor

Run a second collection over the page text for chunking and structured extraction.