Repository navigation
Studio: skip pymupdf4llm's table search on PDF pages that cannot hold a lined table - #16280
Conversation
… a lined table find_tables(strategy="lines_strict") only builds edges from vector line art, and pymupdf4llm keeps only tables with 2+ rows and 2+ columns, which need 3+ vertical and 3+ horizontal edges. Pages whose drawings bound those counts below 3 now go through to_markdown(table_strategy=None); everything else keeps the full search. Same Markdown, 21.5% less parse time on a 55-PDF corpus (books 3x).
…G imports (#16284) `Document upload compatibility` (`Uploads (macos-latest)`, `Uploads (windows-latest)`) has failed on every RAG PR since #16145, for example #16280 now: ``` ERROR collecting studio/backend/tests/test_rag_vec_ann.py studio/backend/tests/test_rag_vec_ann.py:13: in <module> import usearch # noqa: F401 E ModuleNotFoundError: No module named 'usearch' ERROR collecting studio/backend/tests/test_rag_vec_cache_ann.py ``` The workflow's run history: `perf/rag-hnsw-tier` (#16145 itself), `perf/r14-chat-search`, `dh/fix-engine-port-blocks-past-40-workers` and `perf/r14-rag-ingest` all failed there, while the `flows-*` branches it ran on passed. ### Why #16145 pinned `usearch==2.26.6` in `studio/backend/requirements/studio.txt` and the studio extra. Under `CI`, its ANN tests import usearch unconditionally, by design: a missing wheel where `studio.txt` was installed is a packaging failure, not a skip. `tests/studio/rag_upload_ci.py` runs every `studio/backend/tests/test_rag_*.py`, but in a venv built only from its own pinned `tests/studio/rag_upload_requirements.txt`, and that list never got usearch. The tests are right. The harness's requirements fell behind. ### Change - Pin `usearch==2.26.6` in `tests/studio/rag_upload_requirements.txt`, matching `studio.txt`. - New `tests/studio/test_rag_upload_requirements_cover_ci_imports.py`. It reads each `test_rag_*.py` for `import`s made only under a `CI` check, and requires each module to be pinned in `rag_upload_requirements.txt` at the same version as `studio.txt`. It has a control that the scan finds today's `usearch` import, so the reader cannot pass by seeing nothing. ### Verification - The new tests pass. - Sabotage: dropping the usearch pin fails with `['test_rag_vec_ann.py: usearch', 'test_rag_vec_cache_ann.py: usearch']`. Pinning `2.26.5` fails with `usearch: upload 2.26.5 vs studio.txt 2.26.6`. - The workflow's path filter includes `tests/studio/rag_upload*`, so `Document upload compatibility` runs on this PR on macOS and Windows. That run is the end-to-end check.
|
The three |
|
@codex review |
1 similar comment
|
@codex review |
Codex Review SummaryThis 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. |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
What changes
PDF ingestion spends most of its time in pymupdf4llm, and most of that in
page.find_tables(strategy="lines_strict"), which runs on every page and first builds a Python dict for every character on the page. On a text-only book page that is 77% of the parse.lines_strictonly builds table edges from vector line art: the line, rect and quad items of every path that is not a large fill, plus the border of each cluster of those paths. pymupdf4llm then drops any table with fewer than 2 rows or 2 columns. A table it keeps has cells at 2 or more distinct x0 and 2 or more distinct tops, so it needs at least 3 vertical and 3 horizontal edges._no_lined_table_possible(page)readspage.get_cdrawings()and counts an upper bound on those edges (each candidate line counted once for every orientation it could take). The cluster step is copied frommake_edgesso the cluster boxes match exactly. If either count is below 3, the page goes throughto_markdown(..., table_strategy=None); every other page keeps the full search.IdentifyHeadersbuilt at the point the single call built it, and the document is baked first under the same conditionto_markdownuses.table_strategydefaulting tolines_strict, PyMuPDF 1.27.2.3 or 1.28.2 (the two pinned versions), and no layout analyzer. In every other case the old code path runs unchanged.Results base vs head
55 public PDFs, 3590 pages: 20 arXiv papers, 6 Gutenberg books, 12 government reports, 7 IRS forms, 6 slide decks, 4 scans, plus rotated and annotated variants. Each file and arm ran in its own process, 3 rounds, with the arm order alternating each round. Parse time:
Per-round totals: 527.8 / 534.7 / 526.6 s on base and 412.7 / 419.8 / 413.3 s on head, so 21.5% to 21.8% saved in every round. The slowest case is a vector-heavy UN report at 0.97x (48.0 s to 49.5 s), where reading the drawings costs time and almost no page can be skipped.
Output identity:
in_bbox_using_cachedisabled in both arms, all 55 files are byte-identical in page texts, page fields, chunks and highlight regions. That cache is keyed onid(), so a freed rect's id can give a stale hit.to_markdowncalls in one process. This is existing upstream behavior and this PR does not change it.Tests
tests/test_rag_pdf_table_guard.py(7 tests):find_tablescall-count check. It fails on base, where the search runs on every page.lines_stricttable. Ten adversarial PDFs (a table from 2 rects plus lines, thin fill rules, touching cell fills, dashed and segmented lines, rejected 1x3 and 3x1 tables, a table off the page edge, a cropbox through a table, a mixed document with rotations, annotations, a widget and a scan page) and 15 real PDFs give identical Markdown on base and head.Not covered
test_rag_pdf_table_guard.py7/7 on ubuntu-latest, macos-15 (arm64) and windows-latest. The windows-11-arm leg could not install the Studio requirements (pyarrow has no win_arm64 wheel and fails to build from source), so it ran no tests.table.pyis pure Python and unchanged in every part the bound relies on (make_edges/clean_graphics, edge merging, intersections, row and column counts); it was not run on a real win-arm64 machine.make_charsthrows insidefind_tableson a page the guard skips, base sent the whole document to plain text. Head now keeps Markdown for that document. None of the corpus pages hit this.