Repository navigation
feat: the Page clients name a document, a collection and a folder as PageIndexClient does, by doc_id, collection_id and folder_id; the earlier names still work and warn - #735
Conversation
…PageIndexClient does, by doc_id, collection_id and folder_id; the earlier names still work and warn
PageSearchClient.search() and search_documents() take doc_id (one ID, or a list), collection_id and folder_id, and upload() takes collection_id, as chat() and submit_document() do. document, documents, document_ids, collection and folder are their earlier names: each still works and emits a DeprecationWarning that names the new one, and passing both raises. extract(), classify() and split() keep collection=, which takes a collection's name as well as its ID.
search() takes pages ("3-9", (3, 9), 3, or (30, None) for an open end), as extract(), classify() and get_page_content() do. start_page and end_page are its earlier names and warn. get_page_content() also takes 5 and (5, 7).
Aligned with it:
- upload() takes folder_id, as submit_document() does.
- get_collection_id(name) looks a collection up by its name, beside get_document_id() and get_folder_id().
- submit_document() takes timeout, the seconds wait=True waits, the outline included.
- A wait for an extract job, a classify job or an outline reads again after a failed read and raises on the third, as a wait for a split job or a document does. A 401, 403 or 404 raises at once.
- classify() refuses types written as {"name": ..., "description": ...}, which it read as two types named "name" and "description". split() already did.
- Docstrings: Classify and Split give their price per 1,000 pages, and the Page clients' and build_outline()'s no longer leave out Page Classify and Page Split.
…r a document, and delete_folder() deletes a folder as delete_collection() deletes a collection
build_outline(wait=False) was the one start-now call with no wait of its
own: wait_document(), wait_extract(), wait_classify() and wait_split() had
theirs. wait_outline(doc_id, timeout) returns what get_outline() returns,
and raises for a document that has no outline and none being built.
A folder could be created and listed, a collection also deleted.
delete_folder(folder_id) calls the server's DELETE /folder/{id}: the
documents and subfolders in it go too, and one still queued or processing
stays with its folder while the rest is deleted, with HTTP 409.
A file stored under another name: extract() warned at a line inside the
SDK, and classify() and split() did not warn, since a job's answer carries
no name. Extract's warning now points at the call that sent the file, and
Classify and Split read the document's name once the job has started and
give the same warning. A failed read gives no warning: the job is running
and its id must reach the caller.
extract(), classify() and split() say that a path whose file is stored
already and still processing is waited for with wait=False too. The
behavior is unchanged.
search(pages="3-") searched page 3 alone. It raises, as
get_page_content("3-") does and as the server does for Extract and
Classify.
…folder_id=, and what is not found answers 404 wherever the answer is made submit_document() and PageSearchClient.upload() place a file in a folder by folder_id; the three job clients could only name a collection, though the server takes a folder for their files too. folder_id= stands in place of collection: naming another collection with it raises. A document, a collection or a folder that is not found carried HTTP 404 only when the server said so. The answers the SDK makes itself now carry it too: a local document read or deleted, get_collection(), get_collection_id(), get_document_id(), get_folder_path() and get_folder_id(). The messages are unchanged. This is what ends a local wait_document() on a missing document at once: it waited 5 seconds and then said the processing continued in the cloud. A wait that cannot read three times in a row: the job waits raised PageIndexAPIError with the HTTP status, the document wait raised it without the status, and the outline wait raised the read's own error, so a dropped connection came out as requests.ConnectionError. All five now raise PageIndexAPIError with the status, and name what was waited for. A 401, 403 or 404 is still raised as it was read. PageSearchClient(), PageExtractClient(), PageClassifyClient() and PageSplitClient() without a key said that PageIndexCloudClient requires one. Each names itself. submit_document() and PageSearchClient.upload() annotate file_path as a str or a PathLike, as the job clients do; a Path worked already. Docstrings: create_folder(), list_folders() and create_metadata_schema() say what they return, as their collection counterparts do; build_outline() and upload() give timeout its own entry; classify() and split() say a stored file that failed is uploaded again under a suffixed name, as extract() says.
…utline() says of the outline it waited for submit_document(wait=True) and PageSearchClient.upload() returned the upload's own answer after the wait: 'status' said "queued" for a document that had completed. build_outline(wait=True) sets its 'index_status' to "completed" once it has waited. An upload's 'status' now says "completed" after a wait; an answer that carries no 'status', as a local one and an older server's, gains none. The Returns lines name the key. Seen in a live run on Dev.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…ng sent again, so delete_folder() and delete_collection() raise the 409 their docstrings name The cloud session sent a GET, PUT or DELETE again on a 409, up to twice over 1 to 3 seconds, by the rule the model calls follow. The cloud API's 409 is a state the caller acts on: a document still queued or processing, a metadata schema declared already. Sent again, it came 1 to 3 seconds late, or not at all: deleting a folder whose 40-page upload was still processing answered 409, the second try found the document finished and answered 200, and the counts returned were that try's (1 document and 1 folder, where 2 and 2 were deleted). 408, 429 and 5xx are sent again as before, and the model calls keep their rule. delete_document() says it raises 409 on a document still processing, as delete_folder() and delete_collection() do.
…rt is sent again with its counts added up over the tries The server deletes a folder's or a collection's documents one by one. A server error part-way leaves part of them deleted and asks for the DELETE again. The SDK sent it again, but returned only the last try's counts: 10 documents, a 500 after 6, then 4 on the retry, and the answer said 4. delete_folder() and delete_collection() now send the DELETE again themselves, up to twice, and add up deleted_documents (and deleted_folders) over the tries. When every try fails, the error says how many were deleted. A 409 still raises at once. cloud_session(server_errors=False) leaves a 5xx to its caller. urllib3 resends a 503 with Retry-After even when it is not listed; a 5xx now goes again only when listed, so the default session is unchanged.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a7fc808937
ℹ️ 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".
| self._wait_for_outline( | ||
| doc_id, None, timeout, self.get_outline(doc_id)["index_status"]) | ||
| return self.get_outline(doc_id) |
There was a problem hiding this comment.
Include all outline reads in the polling retry policy
If the first outline GET encounters a dropped connection or transient API error, wait_outline() raises immediately without entering the retry loop. The final GET is likewise unprotected, so a single transient failure can fail the wait even after polling has confirmed completion. For example, an initial requests.ConnectionError followed by a successful response produces only one read and leaks the connection error. Handle the initial read through the polling retry policy and return the successful terminal response instead of issuing another unprotected read.
Useful? React with 👍 / 👎.
… delete_collection() says the rest is deleted while a document still processing stays - wait_outline() in local mode raised "get_outline is cloud-only"; every other cloud-only call names itself. - delete_collection()'s docstring said the collection and the busy document stay, but not that the other documents are deleted, as delete_folder() and the API reference say (seen on Dev). - retry.py's module docstring said one rule for every model and cloud call; a cloud call is no longer sent again on a 409. - submit_document()'s Returns rewrapped.
… its cloud-only error, as every other cloud-only call does
Both handed the check to the targeting blocks chat() uses, whose error names
chat()'s parameter: "folder_id is cloud-only". The blocks now take the name to
give, chat() keeps its parameter's, and the two methods give their own. A local
folder_context("root") still returns "", the library itself.
…ses when the outline asked of it could not be built, and an upload's outline time-out names its timeout - A tuple of pages is (first, last). get_page_content(), search(), extract() and classify() read (5, 7, 9) as pages 5 to 7, without a word; (5,) raised an IndexError, and search() read () as the whole document. Any tuple of other than two items now raises PageIndexAPIError. - wait_outline(doc_id, timeout, outline_structure): given the structure asked of build_outline(), it raises when that outline could not be built and the document kept the one it had, as build_outline(wait=True) does; it returned the outline kept. - submit_document(wait=True, outline_structure=...) waits for the pages and the outline within one timeout; its time-out said the seconds left, such as "Timed out after -40s", and says the timeout given.
What changes
The five clients name a document, a collection and a folder the same way:
doc_id,collection_id,folder_id. The Page clients' earlier names (document,documents,document_ids,collection,folder,start_page,end_page) still work and emit aDeprecationWarningthat names the new one, so no caller breaks. Beside the names, the calls that had a counterpart in another client now behave as that counterpart does.PageSearchClient.search()andsearch_documents()takedoc_id(one ID, or a list),collection_idandfolder_id, andupload()takescollection_id, aschat()andsubmit_document()do. Passing a name and its earlier name together raises.extract(),classify()andsplit()keepcollection=: it takes a collection's name as well as its ID, and makes the collection.search()takespages:"3-9",(3, 9),3, or(30, None)and(None, 9)for an open end.get_page_content()also takes5and(5, 7). A tuple is a range,(first, last): one of other than two items raises, there and inextract()andclassify(), which read(5, 7, 9)as pages 5 to 7 (search()read()as the whole document).wait_outline(doc_id, timeout, outline_structure)besidewait_document()and the three job waits. Given theoutline_structureasked ofbuild_outline(wait=False), it raises when that outline could not be built and the document kept the one it had, asbuild_outline(wait=True)does.delete_folder(folder_id)besidedelete_collection().get_collection_id(name)besideget_document_id()andget_folder_id().folder_id=onPageSearchClient.upload(),extract(),classify()andsplit(), as onsubmit_document(). On the three job clients it stands in place ofcollection: naming another collection with it raises.submit_document(timeout=): the secondswait=Truewaits, the outline included.PageIndexAPIErrorwith the HTTP status; a 401, 403 or 404 is raised at once. The outline wait raised the read's own error, so a dropped connection came out asrequests.ConnectionError. A wait's first read, and the readwait_document()andwait_outline()return, go once, as before: the cloud session already sends a GET again after a dropped connection or a 5xx, twice.status_code == 404when the SDK makes the answer too: a local document read or deleted,get_collection(),get_collection_id(),get_document_id(),get_folder_path()andget_folder_id(). A localwait_document()on a missing document waited 5 seconds and then said the processing continued in the cloud; it raises at once.classify()refuses types written as{"name": ..., "description": ...}, which it read as two types named "name" and "description".split()already did.name_1.pdf):extract()warned at a line inside the SDK andclassify()andsplit()did not warn. All three warn at the call that sent the file. For it,classify()andsplit()read the document once more after the job starts (GET /doc/{id}/metadata/); a failed read gives no warning, and the job goes on.submit_document(wait=True)andupload()return'status': "completed"once they have waited; they returned the upload's"queued".build_outline(wait=True)already set its status.PageIndexCloudClient requires a PageIndex API key. In local mode,folder_context()andcollection_context()name themselves too; each saidfolder_id is cloud-onlyorcollection_id is cloud-only, whichchat(folder_id=)andchat(collection_id=)keep.delete_folder()on a folder whose 40-page upload was still processing got a 409, the second try found the document finished and answered 200, and the counts returned were that try's (1 document and 1 folder, where 2 and 2 were deleted).delete_folder()anddelete_collection()now raise the 409 their docstrings name, anddelete_document()says the same of a document still processing. 408, 429 and 5xx are sent again as before; the model calls keep their rule.delete_folder()anddelete_collection()add up their counts when a server error cut a delete short. The server deletes the documents one by one; a 5xx part-way leaves part of them deleted and asks for the DELETE again. The session sent it again but returned only the last try's counts: 10 documents, a 500 after 6, then 4, and the answer said 4. Both calls now send it again themselves, up to twice as before, and return the counts added up over the tries (10). When every try fails, the error message says how many were deleted.cloud_session(server_errors=False)leaves a 5xx to its caller; urllib3 sent a 503 withRetry-Afteragain even when not listed, so a 5xx now goes again only when listed, and the default session is unchanged.create_folder(),list_folders()andcreate_metadata_schema()say what they return, as their collection counterparts do.delete_collection()says that the other documents are deleted while one still processing stays, asdelete_folder()and the API reference say.extract(),classify()andsplit()say that a path whose file is stored and still processing is waited for withwait=Falsetoo, and that a stored file that failed is uploaded again.Compatibility
Callers that keep working unchanged: every earlier parameter name,
build_outline_index(),.pageindex. What a caller could notice:status_codeis 404 where it wasNoneon the SDK-made "not found" errors above; the messages are unchanged.PageIndexAPIErrorin place of the read's own error.classify()raises on a dict keyed bynameordescription.extract()andclassify()raise on a tuple of pages of other than two items, which they read as its first two.'status': "completed"in place of"queued".delete_document(),delete_folder()anddelete_collection()while a document is still processing,create_metadata_schema()on a schema declared already. Each waited 1 to 3 seconds first, and a delete went through when the document finished within that time.delete_folder()anddelete_collection()return the counts of every try, not of the last.Release
No server change is needed: the HTTP API takes all of this today. The docs site and the JS SDK still show the earlier names; both are follow-ups, and the earlier names keep working until then.
Test plan
tests/test_client.py: each earlier name warning at the caller's line and raising beside its new name;pagesin each form and the arguments it refuses; a tuple of pages of other than two items raising at all four calls;wait_outline(), and with theoutline_structureasked raising when the document kept its outline;delete_folder(),get_collection_id(); an upload's outline time-out naming the whole timeout; a job keeping its file in the folder named; the five waits on failed reads; the 404s; the stored-name warning at the call that sent the file; a client without a key, and a localfolder_context()orcollection_context(), naming itself; an upload's status after a wait; a 409 answered to a GET, PUT or DELETE sent once; a folder or collection delete cut short by a 500 or a 502 adding up its counts, raising with them after three 500s, and sent once on a 409; a session without server errors sending a 500 or a 503 once.upload(folder_id=);folder_id=onextract(),classify()andsplit()(each file lands in the folder, each job completes);delete_folder()on a folder with documents and on one with a subfolder, the documents then answering 404;create_folder()andlist_folders()returning the keys their docstrings name;delete_folder()anddelete_document()while a 200-page upload was still processing, each raising 409 after one DELETE on the wire (0.6 s and 0.3 s), the folder and the document staying, and both deleted once it had finished. Run again at a7fc808: the same 409s after one DELETE each, anddelete_folder()(1 document, 1 folder) anddelete_collection()(2 documents) returning the server's counts once the documents had finished. A server error part-way cannot be caused on Dev, so the added-up counts are tested only with mocked answers.