From 6c9ca45b30c53096d3ff960a1ea6da3156f917bc Mon Sep 17 00:00:00 2001 From: Stephen Hu Date: Tue, 3 Feb 2026 10:24:27 +0800 Subject: [PATCH] Refactor: improve close for presentation (#12957) ### What problem does this PR solve? improve close for presentation ### Type of change - [x] Refactoring --- rag/app/presentation.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rag/app/presentation.py b/rag/app/presentation.py index 5c8431af1..c6f922bf7 100644 --- a/rag/app/presentation.py +++ b/rag/app/presentation.py @@ -163,7 +163,11 @@ def chunk(filename, binary=None, from_page=0, to_page=100000, lang="Chinese", ca logging.warning(f"{error_msg} for {filename}.") raise NotImplementedError(error_msg) - binary_data = binary if binary else open(filename, 'rb').read() + if binary: + binary_data = binary + else: + with open(filename, 'rb') as f: + binary_data = f.read() doc_parsed = tika_parser.from_buffer(BytesIO(binary_data)) if doc_parsed.get("content", None) is not None: