From f58b563a133a63b4328802eed14c0ff1a3479fed Mon Sep 17 00:00:00 2001 From: Pier-Jean Malandrino Date: Tue, 7 Apr 2026 14:40:11 +0200 Subject: [PATCH] fix: make default table_mode configurable via DEFAULT_TABLE_MODE (H1) TableFormerMode.ACCURATE is very expensive on CPU (~3-5x slower). The default can now be set to "fast" on resource-constrained environments (HF Spaces) via the DEFAULT_TABLE_MODE env var. User-specified table_mode in the request still takes precedence. Ref #57 (H1) --- document-parser/infra/settings.py | 2 ++ document-parser/services/analysis_service.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/document-parser/infra/settings.py b/document-parser/infra/settings.py index 92c68b0..ebb596c 100644 --- a/document-parser/infra/settings.py +++ b/document-parser/infra/settings.py @@ -16,6 +16,7 @@ class Settings: conversion_timeout: int = 900 document_timeout: float = 120.0 # Docling-level per-document timeout (seconds) max_concurrent_analyses: int = 3 + default_table_mode: str = "accurate" # "accurate" or "fast" max_page_count: int = 0 # 0 = unlimited (upload validation) max_file_size: int = 0 # 0 = unlimited (Docling-level, bytes) upload_dir: str = "./uploads" @@ -37,6 +38,7 @@ class Settings: conversion_timeout=int(os.environ.get("CONVERSION_TIMEOUT", "900")), document_timeout=float(os.environ.get("DOCUMENT_TIMEOUT", "120.0")), max_concurrent_analyses=int(os.environ.get("MAX_CONCURRENT_ANALYSES", "3")), + default_table_mode=os.environ.get("DEFAULT_TABLE_MODE", "accurate"), max_page_count=int(os.environ.get("MAX_PAGE_COUNT", "0")), max_file_size=int(os.environ.get("MAX_FILE_SIZE", "0")), upload_dir=os.environ.get("UPLOAD_DIR", "./uploads"), diff --git a/document-parser/services/analysis_service.py b/document-parser/services/analysis_service.py index 93c556f..4b62eaa 100644 --- a/document-parser/services/analysis_service.py +++ b/document-parser/services/analysis_service.py @@ -15,6 +15,7 @@ from typing import TYPE_CHECKING from domain.models import AnalysisJob, AnalysisStatus from domain.value_objects import ChunkingOptions, ChunkResult, ConversionOptions, ConversionResult +from infra.settings import settings if TYPE_CHECKING: from domain.ports import DocumentChunker, DocumentConverter @@ -151,7 +152,10 @@ class AnalysisService: await analysis_repo.update_status(job) logger.info("Analysis started: %s (file: %s)", job_id, filename) - options = ConversionOptions(**(pipeline_options or {})) + opts_dict = pipeline_options or {} + if "table_mode" not in opts_dict: + opts_dict = {**opts_dict, "table_mode": settings.default_table_mode} + options = ConversionOptions(**opts_dict) result: ConversionResult = await asyncio.wait_for( self._converter.convert(file_path, options),