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
Add `.doc` file parser. (#497)
chrysanthemum-boy72384b191def
diff --git a/api/utils/file_utils.py b/api/utils/file_utils.pyindex e5979b6114..a5af89ca9c 100644--- a/api/utils/file_utils.py+++ b/api/utils/file_utils.py@@ -147,7 +147,7 @@ def filename_type(filename):return FileType.PDF.valueif re.match(- r".*\.(docx|ppt|pptx|yml|xml|htm|json|csv|txt|ini|xls|xlsx|wps|rtf|hlp|pages|numbers|key|md)$", filename):+ r".*\.(doc|docx|ppt|pptx|yml|xml|htm|json|csv|txt|ini|xls|xlsx|wps|rtf|hlp|pages|numbers|key|md)$", filename):return FileType.DOC.valueif re.match(diff --git a/rag/app/book.py b/rag/app/book.pyindex 3c46b68a4a..613c1f2cae 100644--- a/rag/app/book.py+++ b/rag/app/book.py@@ -11,6 +11,7 @@# limitations under the License.#import copy+from tika import parserimport refrom io import BytesIO@@ -103,9 +104,19 @@ def chunk(filename, binary=None, from_page=0, to_page=100000,random_choices([t for t, _ in sections], k=200)))callback(0.8, "Finish parsing.")+ elif re.search(r"\.doc$", filename, re.IGNORECASE):+ callback(0.1, "Start to parse.")+ binary = BytesIO(binary)+ doc_parsed = parser.from_buffer(binary)+ sections = doc_parsed['content'].split('\n')+ sections = [(l, "") for l in sections if l]+ remove_contents_table(sections, eng=is_english(+ random_choices([t for t, _ in sections], k=200)))+ callback(0.8, "Finish parsing.")+else:raise NotImplementedError(- "file type not supported yet(docx, pdf, txt supported)")+ "file type not supported yet(doc, docx, pdf, txt supported)")make_colon_as_title(sections)bull = bullets_category(diff --git a/rag/app/laws.py b/rag/app/laws.pyindex acb96692ff..7242b893ce 100644--- a/rag/app/laws.py+++ b/rag/app/laws.py@@ -11,6 +11,7 @@# limitations under the License.#import copy+from tika import parserimport refrom io import BytesIOfrom docx import Document@@ -123,9 +124,18 @@ def chunk(filename, binary=None, from_page=0, to_page=100000,sections = txt.split("\n")sections = [l for l in sections if l]callback(0.8, "Finish parsing.")++ elif re.search(r"\.doc$", filename, re.IGNORECASE):+ callback(0.1, "Start to parse.")+ binary = BytesIO(binary)+ doc_parsed = parser.from_buffer(binary)+ sections = doc_parsed['content'].split('\n')+ sections = [l for l in sections if l]+ callback(0.8, "Finish parsing.")+else:raise NotImplementedError(- "file type not supported yet(docx, pdf, txt supported)")+ "file type not supported yet(doc, docx, pdf, txt supported)")# is it Englisheng = lang.lower() == "english" # is_english(sections)diff --git a/rag/app/naive.py b/rag/app/naive.pyindex 82618b1560..cd77cdc485 100644--- a/rag/app/naive.py+++ b/rag/app/naive.py@@ -10,6 +10,7 @@# See the License for the specific language governing permissions and# limitations under the License.#+from tika import parserfrom io import BytesIOfrom docx import Documentimport re@@ -154,9 +155,17 @@ def chunk(filename, binary=None, from_page=0, to_page=100000,sections = [(l, "") for l in sections if l]callback(0.8, "Finish parsing.")+ elif re.search(r"\.doc$", filename, re.IGNORECASE):+ callback(0.1, "Start to parse.")+ binary = BytesIO(binary)+ doc_parsed = parser.from_buffer(binary)+ sections = doc_parsed['content'].split('\n')+ sections = [(l, "") for l in sections if l]+ callback(0.8, "Finish parsing.")+else:raise NotImplementedError(- "file type not supported yet(docx, pdf, txt supported)")+ "file type not supported yet(doc, docx, pdf, txt supported)")chunks = naive_merge(sections, parser_config.get(diff --git a/rag/app/one.py b/rag/app/one.pyindex 430958d25e..dfcc44f576 100644--- a/rag/app/one.py+++ b/rag/app/one.py@@ -10,6 +10,8 @@# See the License for the specific language governing permissions and# limitations under the License.#+from tika import parser+from io import BytesIOimport refrom rag.app import lawsfrom rag.nlp import huqie, tokenize, find_codec@@ -95,9 +97,17 @@ def chunk(filename, binary=None, from_page=0, to_page=100000,sections = [s for s in sections if s]callback(0.8, "Finish parsing.")+ elif re.search(r"\.doc$", filename, re.IGNORECASE):+ callback(0.1, "Start to parse.")+ binary = BytesIO(binary)+ doc_parsed = parser.from_buffer(binary)+ sections = doc_parsed['content'].split('\n')+ sections = [l for l in sections if l]+ callback(0.8, "Finish parsing.")+else:raise NotImplementedError(- "file type not supported yet(docx, pdf, txt supported)")+ "file type not supported yet(doc, docx, pdf, txt supported)")doc = {"docnm_kwd": filename,diff --git a/requirements.txt b/requirements.txtindex f9ca516fe6..419e2f6c55 100644--- a/requirements.txt+++ b/requirements.txt@@ -116,6 +116,7 @@ sniffio==1.3.1StrEnum==0.4.15sympy==1.12threadpoolctl==3.3.0+tika==2.6.0tiktoken==0.6.0tokenizers==0.15.2torch==2.2.1@@ -133,4 +134,4 @@ xxhash==3.4.1yarl==1.9.4zhipuai==2.0.1BCEmbedding-loguru==0.7.2+loguru==0.7.2\ No newline at end of file