RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
fix(pdf): make _table_transformer_job honor TABLE_AUTO_ROTATE by default (#16079)
helloxjade6ed4970d6d07
diff --git a/deepdoc/parser/pdf_parser.py b/deepdoc/parser/pdf_parser.pyindex 6d4be6127d..26d779ff9b 100644--- a/deepdoc/parser/pdf_parser.py+++ b/deepdoc/parser/pdf_parser.py@@ -467,7 +467,7 @@ class RAGFlowPdfParser:return width - y, xreturn x, y- def _table_transformer_job(self, ZM, auto_rotate=True):+ def _table_transformer_job(self, ZM, auto_rotate=None):"""Process table structure recognition.@@ -479,8 +479,12 @@ class RAGFlowPdfParser:Args:ZM: Zoom factor- auto_rotate: Whether to enable auto orientation correction+ auto_rotate: Whether to enable auto orientation correction.+ None means reading TABLE_AUTO_ROTATE from the environment."""+ if auto_rotate is None:+ auto_rotate = os.getenv("TABLE_AUTO_ROTATE", "true").lower() in ("true", "1", "yes")+logging.debug("Table processing...")imgs, pos = [], []tbcnt = [0]@@ -1755,9 +1759,6 @@ class RAGFlowPdfParser:True: Enable auto orientation correctionFalse: Disable auto orientation correction"""- if auto_rotate_tables is None:- auto_rotate_tables = os.getenv("TABLE_AUTO_ROTATE", "true").lower() in ("true", "1", "yes")-self.outlines = extract_pdf_outlines(fnm)self.__images__(fnm, zoomin)self._layouts_rec(zoomin)@@ -1814,10 +1815,8 @@ class RAGFlowPdfParser:if callback:callback(0.63, "Layout analysis ({:.2f}s)".format(timer() - start))- auto_rotate_tables = os.getenv("TABLE_AUTO_ROTATE", "true").lower() in ("true", "1", "yes")-start = timer()- self._table_transformer_job(zoomin, auto_rotate=auto_rotate_tables)+ self._table_transformer_job(zoomin)if callback:callback(0.83, "Table analysis ({:.2f}s)".format(timer() - start))diff --git a/test/unit_test/deepdoc/parser/test_pdf_parser_table_coordinates.py b/test/unit_test/deepdoc/parser/test_pdf_parser_table_coordinates.pyindex e0a3ab2d3a..7b0edf1552 100644--- a/test/unit_test/deepdoc/parser/test_pdf_parser_table_coordinates.py+++ b/test/unit_test/deepdoc/parser/test_pdf_parser_table_coordinates.py@@ -215,6 +215,47 @@ def _rotate_point_clockwise(x, y, angle, width, height):raise ValueError(f"unsupported angle: {angle}")+ ("env_value", "explicit_value", "expected_orientation_calls"),+ [+ (None, None, 1),+ ("false", None, 0),+ ("true", None, 1),+ ("1", None, 1),+ ("yes", None, 1),+ ("true", False, 0),+ ("false", True, 1),+ ],+)+def test_table_transformer_resolves_auto_rotate_from_argument_or_environment(monkeypatch, env_value, explicit_value, expected_orientation_calls):+ module = _load_pdf_parser(monkeypatch)+ parser = module.RAGFlowPdfParser.__new__(module.RAGFlowPdfParser)+ parser.page_layout = [[{"type": "table", "x0": 0, "top": 0, "x1": 10, "bottom": 10}]]+ parser.page_images = [_FakeImage()]+ parser.boxes = []+ parser.tbl_det = lambda imgs: [[] for _ in imgs]+ parser._ocr_rotated_tables = lambda *_args, **_kwargs: None++ orientation_calls = []++ def evaluate_orientation(table_img):+ orientation_calls.append(table_img)+ return 0, table_img, {}++ parser._evaluate_table_orientation = evaluate_orientation++ if env_value is None:+ monkeypatch.delenv("TABLE_AUTO_ROTATE", raising=False)+ else:+ monkeypatch.setenv("TABLE_AUTO_ROTATE", env_value)++ kwargs = {} if explicit_value is None else {"auto_rotate": explicit_value}+ parser._table_transformer_job(1, **kwargs)++ assert len(orientation_calls) == expected_orientation_calls++@pytest.mark.p1@pytest.mark.parametrize(("page_index", "page_offset", "zoom"), [(0, 0, 1), (1, 500, 2)])def test_table_transformer_maps_tsr_crop_coordinates_to_page_coordinates(monkeypatch, page_index, page_offset, zoom):