MCPcopy Create free account
hub / github.com/VectifyAI/OpenKB / _fetch_cloud_pages

Function _fetch_cloud_pages

openkb/indexer.py:262–287  ·  view source on GitHub ↗

Fetch all OCR pages of a cloud doc, windowing around the 1000-page cap. ``get_page_content`` returns the whole document and uses its ``pages`` arg only as a client-side filter that ``parse_pages`` caps at 1000 pages — so a single ``"1- "`` request fails for any doc over 1000 pages. Re

(col, doc_id: str)

Source from the content-addressed store, hash-verified

260
261
262def _fetch_cloud_pages(col, doc_id: str) -> list[dict[str, Any]]:
263 """Fetch all OCR pages of a cloud doc, windowing around the 1000-page cap.
264
265 ``get_page_content`` returns the whole document and uses its ``pages`` arg
266 only as a client-side filter that ``parse_pages`` caps at 1000 pages — so a
267 single ``"1-<N>"`` request fails for any doc over 1000 pages. Request fixed
268 ``1000``-page windows and stop as soon as a window comes back SHORT (fewer
269 than a full window): PageIndex page numbers are sequential, so a short window
270 means we&#x27;ve passed the last page. This is what makes the common (≤1000-page)
271 doc a single request, while still fetching every page of a larger one — and,
272 unlike bounding the loop by the tree&#x27;s max page index, it never truncates a
273 doc whose tree under-reports its page count (a real case: a paper whose tree
274 stops a couple pages short of the references). A wide safety bound guards
275 against a backend that never narrows the window.
276 """
277 pages: list[dict[str, Any]] = []
278 start = 1
279 while start <= _CLOUD_PAGE_MAX:
280 window = _normalize_page_content(
281 col.get_page_content(doc_id, f"{start}-{start + _CLOUD_PAGE_WINDOW - 1}")
282 )
283 pages.extend(window)
284 if len(window) < _CLOUD_PAGE_WINDOW:
285 break
286 start += _CLOUD_PAGE_WINDOW
287 return pages
288
289
290def prepare_cloud_import(doc_id: str, kb_dir: Path, path_key: str) -> CloudImportData:

Calls 1

_normalize_page_contentFunction · 0.85