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 'KeyError: "There is no item named 'word/NULL' in the archive"' (#9455)
Jay Xu6d1078b5385d
diff --git a/rag/app/naive.py b/rag/app/naive.pyindex 1a6c0b92b3..5e946d1c81 100644--- a/rag/app/naive.py+++ b/rag/app/naive.py@@ -22,6 +22,8 @@ from timeit import default_timer as timerfrom docx import Documentfrom docx.image.exceptions import InvalidImageStreamError, UnexpectedEndOfFileError, UnrecognizedImageError+from docx.opc.pkgreader import _SerializedRelationships, _SerializedRelationship+from docx.opc.oxml import parse_xmlfrom markdown import markdownfrom PIL import Imagefrom tika import parser@@ -47,8 +49,8 @@ class Docx(DocxParser):if not embed:return Noneembed = embed[0]- related_part = document.part.related_parts[embed]try:+ related_part = document.part.related_parts[embed]image_blob = related_part.image.blobexcept UnrecognizedImageError:logging.info("Unrecognized image format. Skipping image.")@@ -62,6 +64,9 @@ class Docx(DocxParser):except UnicodeDecodeError:logging.info("The recognized image stream appears to be corrupted. Skipping image.")return None+ except Exception:+ logging.info("The recognized image stream appears to be corrupted. Skipping image.")+ return Nonetry:image = Image.open(BytesIO(image_blob)).convert('RGB')return image@@ -360,6 +365,20 @@ class Markdown(MarkdownParser):tbls.append(((None, markdown(table, extensions=['markdown.extensions.tables'])), ""))return sections, tbls+def load_from_xml_v2(baseURI, rels_item_xml):+ """+ Return |_SerializedRelationships| instance loaded with the+ relationships contained in *rels_item_xml*. Returns an empty+ collection if *rels_item_xml* is |None|.+ """+ srels = _SerializedRelationships()+ if rels_item_xml is not None:+ rels_elm = parse_xml(rels_item_xml)+ for rel_elm in rels_elm.Relationship_lst:+ if rel_elm.target_ref in ('../NULL', 'NULL'):+ continue+ srels._srels.append(_SerializedRelationship(baseURI, rel_elm))+ return srelsdef chunk(filename, binary=None, from_page=0, to_page=100000,lang="Chinese", callback=None, **kwargs):@@ -391,6 +410,8 @@ def chunk(filename, binary=None, from_page=0, to_page=100000,except Exception:vision_model = None+ # fix "There is no item named 'word/NULL' in the archive", referring to https://github.com/python-openxml/python-docx/issues/1105#issuecomment-1298075246+ _SerializedRelationships.load_from_xml = load_from_xml_v2sections, tables = Docx()(filename, binary)if vision_model: