Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Refactor: improve close for presentation (#12957)

Stephen Hu6c9ca45b30c5
diff --git a/rag/app/presentation.py b/rag/app/presentation.py
index 5c8431af19..c6f922bf78 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: