Skip to content

feat: PageSplitClient.split() cuts a PDF that bundles several documents into those documents, each with its pages and its type among the types given; a PDF given by its path is kept in the "Page Split" collection - #725

Merged
rejojer merged 6 commits into
mainfrom
feat/page-split
Nov 30, 2026

Conversation

@rejojer

@rejojer rejojer commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

What changes

PageSplitClient is Page Split's client, beside PageSearchClient, PageExtractClient and PageClassifyClient, and works the way PageClassifyClient does. Page Split cuts a PDF that bundles several documents, such as a scanned stack or a tax return with its schedules, into those documents.

from pageindex import PageSplitClient

client = PageSplitClient()  # reads PAGEINDEX_API_KEY
job = client.split("returns.pdf", [
    {"name": "Form 1040", "description": "An individual return"},
    {"name": "Schedule K-1", "description": "A partner's share",
     "identifier_key": "the partner the K-1 is for"},
], rules="Keep each state's forms with its return.")
job["documents"]
# [{"start_page": 1, "end_page": 3, "type": "Form 1040"},
#  {"start_page": 4, "end_page": 5, "type": "Schedule K-1", "identifier": "ABC Partners LP"},
#  {"start_page": 6, "end_page": 7, "type": None}]
  • split(document, types=None, *, rules=None, wait=True, timeout=3600, collection="Page Split").
    • A PDF's path is sent with the job (POST /split, file) and kept as a document in collection. A file stored already whose document is still processing (HTTP 409 naming its doc_id) is waited for, then split by its doc_id, as classify() does.
    • Any other string is a doc_id. A document still processing is waited for, or raises with wait=False.
    • types is optional: {name: description} (a description may be None), a list of names, one name, or a list of {"name", "description", "identifier_key"}. A dict alone, without a list, raises before any request when one of its keys is name, description, identifier_key or identifier: it could be one type, or the {name: description} shorthand with types of those names, which go in the list form. Without types the PDF is split and every document's type is None, as is the type of a document none of the types fits.
    • identifier_key says what tells two documents of a type apart; such a document carries its identifier when one is read. A field Page Split does not know in a listed type, such as identifier for identifier_key, gets a 422 before anything is charged.
    • rules is free text: how the caller wants their documents split.
    • It waits for the job, polling GET /split/{id} every 2 s, growing to 15 s, and raises PageIndexAPIError on the third failed read in a row (at once on 401, 403 or 404), if the job fails, or if it is not done within timeout. The default is an hour: a long PDF is read in order and can take most of one.
  • wait_split(job_id) and get_split(job_id) read a job started with wait=False.
  • CloudAPI.create_split() and get_split() are the two requests.

Release

The server side is VectifyAI/pageindex-compute#1013 (POST /split, GET /split/{id}). Release this once that is on Prod. split()'s docstring states the price, $0.005 a page ($5 per 1,000 pages); that PR must charge the same before this is released.

Test plan

  • New tests in tests/test_client.py:
    • a file sent with its job, its configuration, and the polling;
    • a file stored already, waited for and split by doc_id;
    • a failed job raising with its message;
    • types given as one name and as {name: description}, a dict keyed by name, description, identifier_key or identifier (one type alone, a misspelt field, or a type named "name" among others) raises and sends nothing;
    • a wait that reads the job again after two failed reads, backing off, and raises on the third or on a 404;
    • the client being cloud-only.
  • The suite locally, with no API key set: 1301 passed, 3 skipped. Two litellm-version tests are left out: they fail on main too with the litellm installed here.

…ts into those documents, each with its pages and its type among the types given; a PDF given by its path is kept in the "Page Split" collection

PageSplitClient.split(document, types=None, rules=None) takes a path or a doc_id and waits for the job; wait_split() and get_split() read it later. types is {name: description}, a list of names, one name, or a list of {"name", "description", "identifier_key"}; rules is free text. CloudAPI.create_split() and get_split() are the REST calls.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-30T02:53:34.051924Z a1c2ce0 New commits
🔒 Security Review ✅ Completed 2026-11-30T02:55:01.338449Z a1c2ce0 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Comment thread tests/test_client.py Fixed
… failed reads of its job, and says a document's type is None when none fits

- One type given as a dict without a list around it, such as {"name": "Schedule K-1", "identifier_key": "the partner"}, was read as {name: description}: types named "name" and "identifier_key" were sent, the job ran and was charged, and nothing raised. A dict whose keys are "name" and any of "description" and "identifier_key" is now that one type.
- Waiting on a job read it every second and raised on the first failed read. A split runs up to about 45 minutes, so one short outage ended split() while the job ran on and was charged, and running it again paid twice; a few waits at once also spent much of the per-user rate limit. It now reads every 2 s, growing to 15 s, and raises on the third failed read in a row, or at once on 401, 403 or 404, as waiting on a document does.
- A document none of the types fits has 'type' None, as Page Classify answers, and its 'identifier' is left out when none is read; the docstrings said the type was left out and the identifier always there.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 24b6559536

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pageindex/page_split.py Resolved
…of being guessed as one type

A dict whose keys are only "name", "description" and "identifier_key" reads two ways: one type ({"name": "Schedule K-1", "identifier_key": "the partner"}) or the {name: description} shorthand with a type named "name" ({"name": "A legal-name record"}). Reading it as one type relabelled the second silently; reading it as the shorthand relabelled the first. split() now raises PageIndexAPIError for it before any request and says to put one type in a list. A mapping with other type names beside "name" is the shorthand, as before.

The upload test pops the configuration before asserting on it, so the pop does not live inside an assert.
…stead of becoming types named after its keys

{"name": "Schedule K-1", "identifier": ...} (identifier for identifier_key)
and {"Schedule K-1": ..., "identifier_key": ...} got past the guard, which
raised only when every key was name, description or identifier_key. They were
sent as types named "name", "identifier" or "identifier_key", and the job ran
and was charged; in a list the same dict gets the server's 422. A bare dict
with a key named name, description, identifier_key or identifier now raises
before anything is sent; a type with such a name goes in the list form.
@rejojer
rejojer merged commit 41869f4 into main Nov 30, 2026
10 checks passed
rejojer added a commit that referenced this pull request Nov 30, 2026
pageindex 0.8.3 adds PageSplitClient, Page Split's client (#725).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant