From 61eb3a30d0c96db2e0157e35c730eda84b41d87c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Trevi=C3=B1o?= Date: Fri, 27 Nov 2026 22:29:23 -0600 Subject: [PATCH] Read works through files a batch at a time and keeps each batch --- models/graph.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/models/graph.py b/models/graph.py index 6fc4e80..baaeec6 100644 --- a/models/graph.py +++ b/models/graph.py @@ -47,6 +47,7 @@ from core.pipeline import ( from persistance import config_log, files, nodes, silver MIN_WORDS = 5 # fewer than this from a PDF page means it has no text layer +READ_BATCH = 32 # files read at a time (a read is kept as soon as its batch is done) READ_COLUMNS = { # declared, so a load where every file read cleanly still has `error` "text": {"data_type": "text", "nullable": True}, "ocr": {"data_type": "bool"}, @@ -145,11 +146,15 @@ def run_read(p: str, node: Read): found[k]["format"] = file_format(files.content(k) or b"") nodes.remember("read_cache", [{"key": k, **{c: found[k][c] for c in READ_COLUMNS}} for k in legacy], READ_COLUMNS) # fmt: skip - new = {k: files.content(k) for k in keys - set(found)} - with ProcessPoolExecutor() as pool: - read = dict(zip(new, pool.map(read_file, new.values()), strict=True)) - nodes.remember("read_cache", [{"key": k, **r} for k, r in read.items()], READ_COLUMNS) - found |= read + new = sorted(keys - set(found)) + with ProcessPoolExecutor() as pool: # a batch of files in memory at a time, each kept + for start in range(0, len(new), READ_BATCH): + batch = new[start : start + READ_BATCH] + read = dict(zip(batch, pool.map(read_file, (files.content(k) for k in batch)), + strict=True)) # fmt: skip + nodes.remember("read_cache", [{"key": k, **r} for k, r in read.items()], + READ_COLUMNS) # fmt: skip + found |= read for row in rows: result = found.get(row.pop("key"), {"text": None, "ocr": False, "error": "empty"}) row |= {k: result[k] for k in READ_COLUMNS}