Skip to content

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

refactor(parser): move native PDF/Office extraction into deepdoc facade (#20273)

xugangqiang25cd84732461
diff --git a/docker/nginx/ragflow.conf b/docker/nginx/ragflow.conf
index 51b0f7fa81..1e45825f99 100644
--- a/docker/nginx/ragflow.conf
+++ b/docker/nginx/ragflow.conf
@@ -31,4 +31,4 @@ server {
expires 10y;
access_log off;
}
-}
\ No newline at end of file
+}
diff --git a/internal/agent/templates/deep_research.json b/internal/agent/templates/deep_research.json
index 1b76fe7b48..59c35dcb52 100644
--- a/internal/agent/templates/deep_research.json
+++ b/internal/agent/templates/deep_research.json
@@ -864,4 +864,4 @@
"retrieval": []
},
"avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAABZmSURBVHgBbVoJjF3ldf7uf5e3LzPjWWyP7bEZFqekNoQEFBJSl0RJCQHU0ihN1CyNlLSqslRK1SaiAqSqJBUJTRuqpG1KwxIMNGCWhlAWm60gIHgIGBxsDzPG+4xn3szb37tLv3P+O8atYun3fe/e++4963e+c/5x8P/+7Xvx6d8p5JwrM653VeCbCcdPAGNgXE+vu66BYzw4jiyj5xyumP9HSJDEifxvz/GnPMFrcrSf7f1Gryf253oJSaIf7K/5SrxzLYriKX6aghtdP7D6vJnT5XVWPtx3387qYBXXlgPv65VMglJgkPF9eB5F8xzEgUs9jL7HqEJGlaA2fIjL5fCafX0ci0Kxvj2OYqTfrNhJkr7ZSV+fnC6G/Z44pz6HYgUxAn8Xy7OBf6BI1w9sPK92SoFbKHzec3aWPWzN5RIM+C7KVILKwPc9uH5sBfaoAJe1lMhOW1IBYxxrM7mUpNcpRBxH1rCp5eMk4rlUAd5s9BlU3llRLDnNW+/oqqKn56Ik5IOcKWPcbaKExkU9dK8N4Wzt8cbBtsunisWMHvNOH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ekBCZyV5ZW5kNJBjLXZiZhlOJTJ2g23UbZuT2A26dIKcJDZsZL9M+l3Z8JB2cZlI8qFLz8cN//IQIgp7ZmEEew6+juGREeTYJrpa5SMlhhs3nU1PjWNmelqHDH0iZbZc1o6w3+9//87tP9ouYYzPX/X7z2ez0cdygTvmy9apZ9s/5f+OjW89qCLOqe82UKygsre2suuugieyS2PzQa6J8MppeZ68Dh+//ELcdPM9GGdNmOs1cKK5gArnQTmOTLL5MhufruLCENnohslJTse5p0aW2yaEOkk45RecL+zdu7dz6q8sdt53S9XzkusCP/makDnhGMaxM1tPd+QtpBjHYozu3UoMxSvjdOsJ8UsUJ+muqHMqjHSnRvrbuKeDgbGRIj75he+gNTuHeQ7CGqTQk8Nj2HzOZoyuOUO7MEN0bJD49TmnyuayzBOOF5fr309a0XU7du145489Tv/33MO3TBDnr2MTsoXle6uXpATPpPtOjiV0Kz+NVxYFDLHSw6bbtPqHH5EqJPgapVtNYSxzH7vV9PUv3YAmhZW95QXuWm678ANYNbxGqXxtcQnN+pIMPWe4O3F/Lpfd8dCux3adLu//Al9o4L0Sc5y8AAAAAElFTkSuQmCC"
- }
\ No newline at end of file
+ }
diff --git a/internal/agent/templates/photo_text_translator.json b/internal/agent/templates/photo_text_translator.json
index 148c819467..f95734b864 100644
--- a/internal/agent/templates/photo_text_translator.json
+++ b/internal/agent/templates/photo_text_translator.json
@@ -266,4 +266,4 @@
"retrieval": []
},
"avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAABfmSURBVHgBdVoJeFTluX7PbJmZJLNlD9kXwhKQRTbDrhRc0VqLxbrUi7cVKWqr7VO1Sq331qtWBBUUKgJWLi6tuOCCCztY1kBYExISIGRPJsvsy7nv/89MMsHeeThM5uTMOd//Le/3vt8fBVe8unp7Zx5p7Z5v0mlu9YbUgjyTDilmI/p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Y1JHAz2QAdDU9hWAfEhxIRFILHCxYqHqhGNsP7SHPLcrKxZ9NbsJEtOvnwhvWvodBmw1Hu6tgYVbFXHNszE0wzlZQ6glgx81T5WSOFUkR5hft3BSOLCEXlGJ9fmZAQXCbOyQXM+sWjzu3Ll8+iBlsW6ut+GMJTcYOooBDYfPcSsYYNLYWnrYneDMJEiuzgBvbc667G/OlTUf/hZjR3tPDogL/lMmY+8RzrgbzH4+7ftUtgJC+2NhHJLEyRYFQ2Dmw9Cd0c/+pfg7hGbpQrK0yGwLKxY2c5Y9Ef9Dq//YuCFWveXLbu8x1XWRNNY5IMWiSxkB1sVBVsLufYuDpZtMXp3NgmrNpIvsryWfBEDYg5Ko0yczQ56sHfIkRYDgnSBbV/g0MkSBeFj41bU0lmkkhGVdKAK/7kJjaSjAr9eqbVx4qq2TJlyrQd8fb+H90isRVH8mIAAAAAAElFTkSuQmCC"
-}
\ No newline at end of file
+}
diff --git a/internal/deepdoc/parser/office/engine.go b/internal/deepdoc/parser/office/engine.go
new file mode 100644
index 0000000000..5aa6e96508
--- /dev/null
+++ b/internal/deepdoc/parser/office/engine.go
@@ -0,0 +1,23 @@
+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package office
+
+import "errors"
+
+// ErrOfficeCGORequired is returned by OpenAndExtract when the build has no
+// native office_oxide backend. The parser package wraps it into its own
+// ErrOfficeCGORequired so callers observe a stable sentinel regardless of
+// which layer reports the missing engine.
+var ErrOfficeCGORequired = errors.New("deepdoc/docx: cgo required")
diff --git a/internal/deepdoc/parser/office/engine_cgo.go b/internal/deepdoc/parser/office/engine_cgo.go
new file mode 100644
index 0000000000..138422b18f
--- /dev/null
+++ b/internal/deepdoc/parser/office/engine_cgo.go
@@ -0,0 +1,61 @@
+//go:build cgo
+
+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package office
+
+import (
+ "errors"
+ "fmt"
+
+ officeOxide "github.com/yfedoseev/office_oxide/go"
+)
+
+// OpenAndExtract opens an Office document with the native office_oxide
+// backend and returns its three text views: the structured IR JSON, the
+// Markdown rendering, and the raw plain text. The only place that depends on
+// office_oxide lives here, so the parser package can stay CGO-free and own
+// only the format-agnostic post-processing.
+//
+// A single failing view is non-fatal: the parser package salvages the
+// surviving views (e.g. the DOCX JSON path errors on empty IR, the Markdown
+// path prefers the Markdown view, the DOC path picks the longest view). mdErr
+// is returned separately so the Markdown path can fail loud when only the
+// Markdown view fails. If EVERY view fails there is nothing to recover, so err
+// is set to the joined view errors instead of three empty strings that
+// downstream code would silently treat as "empty document" (PR review
+// Finding 1).
+func OpenAndExtract(data []byte, format string) (irJSON, markdown, plainText string, mdErr error, err error) {
+ doc, openErr := officeOxide.OpenFromBytes(data, format)
+ if openErr != nil {
+ return "", "", "", nil, fmt.Errorf("office_oxide open %s: %w", format, openErr)
+ }
+ defer doc.Close()
+
+ irJSON, irErr := doc.ToIRJSON()
+ markdown, mdErr = doc.ToMarkdown()
+ plainText, ptErr := doc.PlainText()
+
+ // Every view failed: nothing to salvage, so report the combined failures
+ // rather than returning three empty strings that downstream code would
+ // silently treat as an empty document (PR review Finding 1).
+ if irJSON == "" && markdown == "" && plainText == "" {
+ return "", "", "", mdErr, fmt.Errorf(
+ "office_oxide %s: all text views failed: %w",
+ format, errors.Join(irErr, mdErr, ptErr),
+ )
+ }
+ return irJSON, markdown, plainText, mdErr, nil
+}
diff --git a/internal/deepdoc/parser/office/engine_cgo_test.go b/internal/deepdoc/parser/office/engine_cgo_test.go
new file mode 100644
index 0000000000..f3bec5789b
--- /dev/null
+++ b/internal/deepdoc/parser/office/engine_cgo_test.go
@@ -0,0 +1,90 @@
+//go:build cgo
+
+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package office
+
+import (
+ "archive/zip"
+ "bytes"
+ "strings"
+ "testing"
+)
+
+// TestOpenAndExtract_ValidDocReturnsViews locks the happy path of the
+// revised 5-value OpenAndExtract contract under cgo: a real document yields a
+// non-empty Markdown view and a nil error, and the Markdown error (mdErr) is
+// surfaced as a distinct return so callers can fail loud when only that view
+// fails (PR review Finding 1 + Finding 3). office_oxide always returns a
+// structured IR for an openable document, so the all-views-empty join branch
+// is exercised indirectly via the parser package's stub tests, not here.
+func TestOpenAndExtract_ValidDocReturnsViews(t *testing.T) {
+ data := minimalDOCX(t, "surviving content")
+ irJSON, markdown, plainText, mdErr, err := OpenAndExtract(data, "docx")
+ if err != nil {
+ t.Fatalf("expected success for a document with content, got err: %v", err)
+ }
+ if strings.TrimSpace(irJSON) == "" {
+ t.Error("expected non-empty IR for a document with content")
+ }
+ if strings.TrimSpace(markdown) == "" {
+ t.Error("expected non-empty markdown for a document with content")
+ }
+ if strings.TrimSpace(plainText) == "" {
+ t.Error("expected non-empty plain text for a document with content")
+ }
+ // A clean document has no Markdown render error to surface.
+ if mdErr != nil {
+ t.Errorf("expected nil mdErr for a clean document, got: %v", mdErr)
+ }
+ _ = plainText
+}
+
+func minimalDOCX(t *testing.T, text string) []byte {
+ t.Helper()
+ var buf bytes.Buffer
+ zw := zip.NewWriter(&buf)
+ writeZip(t, zw, "[Content_Types].xml", `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
+ <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
+ <Default Extension="xml" ContentType="application/xml"/>
+ <Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
+</Types>`)
+ writeZip(t, zw, "_rels/.rels", `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
+ <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
+</Relationships>`)
+ writeZip(t, zw, "word/document.xml", `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
+ <w:body>
+ <w:p><w:r><w:t>`+text+`</w:t></w:r></w:p>
+ </w:body>
+</w:document>`)
+ if err := zw.Close(); err != nil {
+ t.Fatalf("zip close: %v", err)
+ }
+ return buf.Bytes()
+}
+
+func writeZip(t *testing.T, zw *zip.Writer, name, body string) {
+ t.Helper()
+ w, err := zw.Create(name)
+ if err != nil {
+ t.Fatalf("create zip entry %s: %v", name, err)
+ }
+ if _, err := w.Write([]byte(body)); err != nil {
+ t.Fatalf("write zip entry %s: %v", name, err)
+ }
+}
diff --git a/internal/deepdoc/parser/office/engine_nocgo.go b/internal/deepdoc/parser/office/engine_nocgo.go
new file mode 100644
index 0000000000..dcc10048df
--- /dev/null
+++ b/internal/deepdoc/parser/office/engine_nocgo.go
@@ -0,0 +1,24 @@
+//go:build !cgo
+
+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package office
+
+import "fmt"
+
+// OpenAndExtract is unavailable without the native office_oxide backend.
+func OpenAndExtract(data []byte, format string) (irJSON, markdown, plainText string, mdErr error, err error) {
+ return "", "", "", nil, fmt.Errorf("%w", ErrOfficeCGORequired)
+}
diff --git a/internal/deepdoc/parser/office/engine_nocgo_test.go b/internal/deepdoc/parser/office/engine_nocgo_test.go
new file mode 100644
index 0000000000..9d9568f996
--- /dev/null
+++ b/internal/deepdoc/parser/office/engine_nocgo_test.go
@@ -0,0 +1,36 @@
+//go:build !cgo
+
+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package office
+
+import (
+ "errors"
+ "testing"
+)
+
+// TestOpenAndExtract_NoCGO locks the degrade contract: without the native
+// office_oxide backend, OpenAndExtract must report ErrOfficeCGORequired
+// (not attempt to link the C library or panic). This is the behavior the
+// parser package's facade relies on to wrap it into its own sentinel.
+func TestOpenAndExtract_NoCGO(t *testing.T) {
+ _, _, _, _, err := OpenAndExtract([]byte("PK\x03\x04"), "docx")
+ if err == nil {
+ t.Fatal("expected ErrOfficeCGORequired, got nil")
+ }
+ if !errors.Is(err, ErrOfficeCGORequired) {
+ t.Fatalf("err = %v, want ErrOfficeCGORequired", err)
+ }
+}
diff --git a/internal/deepdoc/parser/docx/parser.go b/internal/deepdoc/parser/office/parser.go
similarity index 99%
rename from internal/deepdoc/parser/docx/parser.go
rename to internal/deepdoc/parser/office/parser.go
index a13ed80cb4..b6120381f9 100644
--- a/internal/deepdoc/parser/docx/parser.go
+++ b/internal/deepdoc/parser/office/parser.go
@@ -1,4 +1,4 @@
-package docx
+package office
import (
"strings"
diff --git a/internal/deepdoc/parser/docx/parser_integration_test.go b/internal/deepdoc/parser/office/parser_integration_test.go
similarity index 99%
rename from internal/deepdoc/parser/docx/parser_integration_test.go
rename to internal/deepdoc/parser/office/parser_integration_test.go
index 675e2e196f..cc3e9fd121 100644
--- a/internal/deepdoc/parser/docx/parser_integration_test.go
+++ b/internal/deepdoc/parser/office/parser_integration_test.go
@@ -1,6 +1,6 @@
//go:build cgo && manual
-package docx
+package office
import (
"os"
diff --git a/internal/deepdoc/parser/docx/parser_test.go b/internal/deepdoc/parser/office/parser_test.go
similarity index 99%
rename from internal/deepdoc/parser/docx/parser_test.go
rename to internal/deepdoc/parser/office/parser_test.go
index 60dcf07473..16fdd906e0 100644
--- a/internal/deepdoc/parser/docx/parser_test.go
+++ b/internal/deepdoc/parser/office/parser_test.go
@@ -1,4 +1,4 @@
-package docx
+package office
import (
"testing"
diff --git a/internal/deepdoc/parser/docx/raw_blocks_test.go b/internal/deepdoc/parser/office/raw_blocks_test.go
similarity index 99%
rename from internal/deepdoc/parser/docx/raw_blocks_test.go
rename to internal/deepdoc/parser/office/raw_blocks_test.go
index c1174f7a21..955be405c2 100644
--- a/internal/deepdoc/parser/docx/raw_blocks_test.go
+++ b/internal/deepdoc/parser/office/raw_blocks_test.go
@@ -1,6 +1,6 @@
//go:build cgo && manual
-package docx
+package office
import (
"encoding/json"
diff --git a/internal/deepdoc/parser/docx/reader.go b/internal/deepdoc/parser/office/reader.go
similarity index 99%
rename from internal/deepdoc/parser/docx/reader.go
rename to internal/deepdoc/parser/office/reader.go
index b3a5c3677d..2fe32f0417 100644
--- a/internal/deepdoc/parser/docx/reader.go
+++ b/internal/deepdoc/parser/office/reader.go
@@ -1,6 +1,6 @@
//go:build cgo
-package docx
+package office
import (
"encoding/base64"
diff --git a/internal/deepdoc/parser/docx/reader_cell_test.go b/internal/deepdoc/parser/office/reader_cell_test.go
similarity index 98%
rename from internal/deepdoc/parser/docx/reader_cell_test.go
rename to internal/deepdoc/parser/office/reader_cell_test.go
index 4183cf378c..d7b6d4c2fe 100644
--- a/internal/deepdoc/parser/docx/reader_cell_test.go
+++ b/internal/deepdoc/parser/office/reader_cell_test.go
@@ -1,6 +1,6 @@
//go:build cgo
-package docx
+package office
import "testing"
diff --git a/internal/deepdoc/parser/docx/reader_stub.go b/internal/deepdoc/parser/office/reader_stub.go
similarity index 95%
rename from internal/deepdoc/parser/docx/reader_stub.go
rename to internal/deepdoc/parser/office/reader_stub.go
index ed7c993544..f8d4d65cb7 100644
--- a/internal/deepdoc/parser/docx/reader_stub.go
+++ b/internal/deepdoc/parser/office/reader_stub.go
@@ -1,6 +1,6 @@
//go:build !cgo
-package docx
+package office
import "errors"
diff --git a/internal/deepdoc/parser/docx/reader_style_test.go b/internal/deepdoc/parser/office/reader_style_test.go
similarity index 98%
rename from internal/deepdoc/parser/docx/reader_style_test.go
rename to internal/deepdoc/parser/office/reader_style_test.go
index dd7b054ff6..f02eaee998 100644
--- a/internal/deepdoc/parser/docx/reader_style_test.go
+++ b/internal/deepdoc/parser/office/reader_style_test.go
@@ -1,6 +1,6 @@
//go:build cgo
-package docx
+package office
import "testing"
diff --git a/internal/deepdoc/parser/docx/types.go b/internal/deepdoc/parser/office/types.go
similarity index 99%
rename from internal/deepdoc/parser/docx/types.go
rename to internal/deepdoc/parser/office/types.go
index 21c3c56959..448851e0af 100644
--- a/internal/deepdoc/parser/docx/types.go
+++ b/internal/deepdoc/parser/office/types.go
@@ -1,4 +1,4 @@
-package docx
+package office
// RawBlock represents a single block extracted from a DOCX file in document order.
// Type is one of "paragraph", "table", or "image". Headings are represented as
diff --git a/internal/deepdoc/parser/pdf/plaintext_cgo.go b/internal/deepdoc/parser/pdf/plaintext_cgo.go
new file mode 100644
index 0000000000..3539862af9
--- /dev/null
+++ b/internal/deepdoc/parser/pdf/plaintext_cgo.go
@@ -0,0 +1,56 @@
+//go:build cgo
+
+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package pdf
+
+import (
+ "fmt"
+
+ "ragflow/internal/deepdoc/parser/pdf/pdfoxide"
+)
+
+// PlainText extracts plain text per page using the pdf_oxide native engine.
+// It is the cgo implementation of the parser package's plain_text PDF
+// strategy. The returned items carry the keys text/doc_type_kwd/page_number
+// so the parser package can wrap them with pdfItemsToResult unchanged.
+func PlainText(data []byte) ([]map[string]any, int, error) {
+ if len(data) == 0 {
+ return nil, 0, nil
+ }
+ doc, err := pdfoxide.OpenBytes(data)
+ if err != nil {
+ return nil, 0, fmt.Errorf("deepdoc/pdf: plain_text open: %w", err)
+ }
+ defer doc.Close()
+
+ pageCount, err := doc.PageCount()
+ if err != nil {
+ return nil, 0, fmt.Errorf("deepdoc/pdf: plain_text page count: %w", err)
+ }
+ items := make([]map[string]any, 0, pageCount)
+ for page := 0; page < pageCount; page++ {
+ text, err := doc.GetPageText(page)
+ if err != nil {
+ return nil, 0, fmt.Errorf("deepdoc/pdf: plain_text page %d: %w", page+1, err)
+ }
+ items = append(items, map[string]any{
+ "text": text,
+ "doc_type_kwd": "text",
+ "page_number": page + 1,
+ })
+ }
+ return items, pageCount, nil
+}
diff --git a/internal/deepdoc/parser/pdf/plaintext_nocgo.go b/internal/deepdoc/parser/pdf/plaintext_nocgo.go
new file mode 100644
index 0000000000..9df397a7da
--- /dev/null
+++ b/internal/deepdoc/parser/pdf/plaintext_nocgo.go
@@ -0,0 +1,78 @@
+//go:build !cgo
+
+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package pdf
+
+import (
+ "bytes"
+ "fmt"
+ "strings"
+
+ "github.com/ledongthuc/pdf"
+)
+
+// maxPDFPageCount is the largest page count PlainText will accept. A corrupt
+// or malicious /Count in the catalog can claim billions of pages; honoring it
+// would either panic make (negative) or allocate/iterate without bound (huge).
+// One million pages is far beyond any real document RAGFlow ingests, so values
+// above it are treated as malformed (PR review Blocker).
+const maxPDFPageCount = 1_000_000
+
+// PlainText extracts plain text per page using the pure-Go ledongthuc/pdf
+// engine. It mirrors the cgo pdf_oxide implementation so the parser package's
+// plain_text strategy keeps working under !cgo builds without native
+// libraries. The returned items carry the keys text/doc_type_kwd/page_number
+// so the parser package can wrap them with pdfItemsToResult unchanged.
+func PlainText(data []byte) ([]map[string]any, int, error) {
+ if len(data) == 0 {
+ return nil, 0, nil
+ }
+ reader := bytes.NewReader(data)
+ pdfReader, err := pdf.NewReader(reader, int64(len(data)))
+ if err != nil {
+ return nil, 0, fmt.Errorf("deepdoc/pdf: plain_text open: %w", err)
+ }
+ pageCount := pdfReader.NumPage()
+ // ledongthuc/pdf reads the catalog /Count verbatim, so a malformed PDF
+ // can report a negative or absurd page count. Feeding that directly into
+ // make would panic ("makeslice: cap out of range") and a huge count would
+ // allocate a massive backing array or loop for billions of iterations,
+ // hanging the ingestor on one corrupt file. Reject implausible counts up
+ // front (PR review Blocker).
+ if pageCount < 0 {
+ return nil, 0, fmt.Errorf("deepdoc/pdf: plain_text: invalid negative page count %d", pageCount)
+ }
+ if pageCount > maxPDFPageCount {
+ return nil, 0, fmt.Errorf("deepdoc/pdf: plain_text: page count %d exceeds sane limit %d", pageCount, maxPDFPageCount)
+ }
+ items := make([]map[string]any, 0, pageCount)
+ for pageNum := 1; pageNum <= pageCount; pageNum++ {
+ p := pdfReader.Page(pageNum)
+ if p.V.IsNull() {
+ continue
+ }
+ text, err := p.GetPlainText(nil)
+ if err != nil {
+ return nil, 0, fmt.Errorf("deepdoc/pdf: plain_text page %d: %w", pageNum, err)
+ }
+ items = append(items, map[string]any{
+ "text": strings.TrimRight(text, "\n"),
+ "doc_type_kwd": "text",
+ "page_number": pageNum,
+ })
+ }
+ return items, pageCount, nil
+}
diff --git a/internal/deepdoc/parser/pdf/plaintext_nocgo_test.go b/internal/deepdoc/parser/pdf/plaintext_nocgo_test.go
new file mode 100644
index 0000000000..2d8695502d
--- /dev/null
+++ b/internal/deepdoc/parser/pdf/plaintext_nocgo_test.go
@@ -0,0 +1,108 @@
+//go:build !cgo
+
+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package pdf
+
+import (
+ "bytes"
+ "fmt"
+ "testing"
+)
+
+// TestPlainText_EmptyInput locks the empty-input contract: a nil/empty
+// payload yields (nil, 0, nil) rather than an error, so the caller's
+// empty-PDF short-circuit stays correct under the pure-Go engine.
+func TestPlainText_EmptyInput(t *testing.T) {
+ items, pageCount, err := PlainText(nil)
+ if err != nil {
+ t.Fatalf("err = %v, want nil", err)
+ }
+ if items != nil || pageCount != 0 {
+ t.Fatalf("got (items=%v, pageCount=%d), want (nil, 0)", items, pageCount)
+ }
+}
+
+// TestPlainText_GarbageReturnsError locks that non-PDF input fails loudly
+// instead of silently producing empty items — the pure-Go ledongthuc/pdf
+// path must surface a parse error, never a plausible empty success.
+func TestPlainText_GarbageReturnsError(t *testing.T) {
+ _, _, err := PlainText([]byte("this is not a pdf"))
+ if err == nil {
+ t.Fatal("expected error for non-PDF input, got nil")
+ }
+}
+
+// TestPlainText_NegativePageCountDoesNotPanic locks the Blocker from the PR
+// review: ledongthuc/pdf's NumPage() reads the catalog /Count verbatim, so a
+// malformed (negative) /Count yields a negative page count. The old code fed
+// that straight into make([]map[string]any, 0, pageCount), which panics with
+// "makeslice: cap out of range". PlainText must validate the page count and
+// fail loud instead of crashing the ingestor on a single corrupt PDF.
+func TestPlainText_NegativePageCountDoesNotPanic(t *testing.T) {
+ defer func() {
+ if r := recover(); r != nil {
+ t.Fatalf("PlainText panicked on a negative /Count: %v", r)
+ }
+ }()
+ data := buildPDFWithCount(t, -1)
+ _, _, err := PlainText(data)
+ if err == nil {
+ t.Fatal("expected error for a PDF with a negative /Count, got nil")
+ }
+}
+
+// TestPlainText_HugePageCountDoesNotHang locks the sibling failure mode of the
+// same Blocker: an absurd /Count must not allocate a gigantic slice or loop
+// for billions of iterations. We cap the page count and reject grossly
+// implausible values up front.
+func TestPlainText_HugePageCountDoesNotHang(t *testing.T) {
+ defer func() {
+ if r := recover(); r != nil {
+ t.Fatalf("PlainText panicked on a huge /Count: %v", r)
+ }
+ }()
+ data := buildPDFWithCount(t, 1<<30)
+ _, _, err := PlainText(data)
+ if err == nil {
+ t.Fatal("expected error for a PDF with a huge /Count, got nil")
+ }
+}
+
+// buildPDFWithCount emits a minimal but structurally valid PDF whose /Pages
+// /Count is set to the supplied value. Offsets are computed so the xref table
+// is self-consistent and ledongthuc/pdf can open it, letting NumPage() observe
+// the (possibly malformed) /Count.
+func buildPDFWithCount(t *testing.T, count int) []byte {
+ t.Helper()
+ var buf bytes.Buffer
+ buf.WriteString("%PDF-1.4\n")
+
+ off1 := buf.Len()
+ fmt.Fprintf(&buf, "1 0 obj\n<< /Type /Catalog /Pages 2 0 R >>\nendobj\n")
+ off2 := buf.Len()
+ fmt.Fprintf(&buf, "2 0 obj\n<< /Type /Pages /Kids [3 0 R] /Count %d >>\nendobj\n", count)
+ off3 := buf.Len()
+ fmt.Fprintf(&buf, "3 0 obj\n<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Resources << >> >>\nendobj\n")
+
+ xrefStart := buf.Len()
+ buf.WriteString("xref\n0 4\n")
+ buf.WriteString("0000000000 65535 f \n")
+ fmt.Fprintf(&buf, "%010d 00000 n \n", off1)
+ fmt.Fprintf(&buf, "%010d 00000 n \n", off2)
+ fmt.Fprintf(&buf, "%010d 00000 n \n", off3)
+ fmt.Fprintf(&buf, "trailer\n<< /Size 4 /Root 1 0 R >>\nstartxref\n%d\n%%%%EOF\n", xrefStart)
+ return buf.Bytes()
+}
diff --git a/internal/parser/parser/doc_parser.go b/internal/parser/parser/doc_parser.go
index 8bc8c4cdaa..295511eac4 100644
--- a/internal/parser/parser/doc_parser.go
+++ b/internal/parser/parser/doc_parser.go
@@ -1,5 +1,3 @@
-//go:build cgo
-
//
// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
//
@@ -7,25 +5,28 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
-//
package parser
import (
"context"
+ "errors"
"fmt"
"strings"
- officeOxide "github.com/yfedoseev/office_oxide/go"
+ deepdocoffice "ragflow/internal/deepdoc/parser/office"
)
+// docExtract is the native office_oxide extraction seam for the DOC family.
+var docExtract = deepdocoffice.OpenAndExtract
+
type DOCParser struct {
OutputFormat string
}
@@ -52,13 +53,15 @@ func (p *DOCParser) ConfigureFromSetup(setup map[string]any) {
// ParseWithResult extracts text for the DOC family and converts it to the
// requested output format (defaulting to "json" to match Python's default).
func (p *DOCParser) ParseWithResult(ctx context.Context, filename string, data []byte) ParseResult {
- doc, err := officeOxide.OpenFromBytes(data, "doc")
+ irJSON, mdText, plainText, _, err := docExtract(data, "doc")
if err != nil {
- return ParseResult{Err: fmt.Errorf("doc open: %w", err)}
+ if errors.Is(err, deepdocoffice.ErrOfficeCGORequired) {
+ return ParseResult{Err: fmt.Errorf("%w: %s", ErrOfficeCGORequired, filename)}
+ }
+ return ParseResult{Err: fmt.Errorf("doc extract: %w", err)}
}
- defer doc.Close()
- text, mdText, err := extractDocText(doc)
+ text, mdPayload, err := extractDocText(irJSON, mdText, plainText)
if err != nil {
return ParseResult{Err: fmt.Errorf("doc extract: %w", err)}
}
@@ -69,8 +72,8 @@ func (p *DOCParser) ParseWithResult(ctx context.Context, filename string, data [
}
markdownPayload := text
- if strings.TrimSpace(mdText) != "" {
- markdownPayload = mdText
+ if strings.TrimSpace(mdPayload) != "" {
+ markdownPayload = mdPayload
}
res := ParseResult{
@@ -93,7 +96,8 @@ func (p *DOCParser) ParseWithResult(ctx context.Context, filename string, data [
}
// extractDocText returns the best-effort plain text for a legacy .doc
-// document. office_oxide exposes three text views:
+// document. office_oxide exposes three text views (documented on the cgo
+// OpenAndExtract contract):
// - ToIRJSON: a structured DocumentIR, flattened to plain text via
// flattenDocIR. Recovers table structure (office_oxide/go v0.1.9, #116)
// and, when the reader surfaces them, list structure.
@@ -104,26 +108,24 @@ func (p *DOCParser) ParseWithResult(ctx context.Context, filename string, data [
// unique to the IR view and would be silently dropped under a pure length
// comparison — a prose-heavy document can make PlainText longer than the IR
// even though the IR is more complete). Otherwise the longest non-empty view
-// is chosen so a sparser view never shadows a more complete one. A failure at
-// every stage degrades to the PlainText error, preserving the original "no
-// text at all" failure semantics.
-func extractDocText(doc *officeOxide.Document) (string, string, error) {
- var irJSON, irText, mdText, plainText string
- if j, err := doc.ToIRJSON(); err == nil {
- irJSON = j
- irText = flattenDocIR(j)
- }
- if md, err := doc.ToMarkdown(); err == nil {
- mdText = md
- }
- if plain, err := doc.PlainText(); err == nil {
- plainText = plain
- } else if strings.TrimSpace(irText) == "" && strings.TrimSpace(mdText) == "" {
- // Every view failed (or produced nothing): keep the original
- // "no text at all" failure semantics.
- return "", "", err
- }
- return selectDocTextView(irJSON, irText, mdText, plainText), mdText, nil
+// is chosen so a sparser view never shadows a more complete one.
+func extractDocText(irJSON, mdText, plainText string) (string, string, error) {
+ var irText string
+ if irJSON != "" {
+ irText = flattenDocIR(irJSON)
+ }
+ text := selectDocTextView(irJSON, irText, mdText, plainText)
+ // Fail loud when the document yielded no usable text in any view. The
+ // OpenAndExtract contract swallows per-view errors, so an empty selected
+ // view plus an empty Markdown view is the only signal we get that the
+ // document has no extractable text — surfacing it avoids silently
+ // producing 0 chunks (Finding A). A legitimately empty payload (e.g. a
+ // scanned-image doc with OCR off) is rare and failing is safer than
+ // silent data loss.
+ if strings.TrimSpace(text) == "" && strings.TrimSpace(mdText) == "" {
+ return "", "", fmt.Errorf("doc extract: no text content")
+ }
+ return text, mdText, nil
}
// selectDocTextView chooses the best plain-text rendering from office_oxide's
diff --git a/internal/parser/parser/doc_text_empty_test.go b/internal/parser/parser/doc_text_empty_test.go
new file mode 100644
index 0000000000..ee6b4ee621
--- /dev/null
+++ b/internal/parser/parser/doc_text_empty_test.go
@@ -0,0 +1,33 @@
+package parser
+
+import (
+ "errors"
+ "testing"
+)
+
+// TestDOCParser_EmptyViewsReturnsError locks Finding A from the PR review:
+// when the native office backend opens the document but yields no text in any
+// of its three views (IR / Markdown / PlainText), ParseWithResult must surface
+// an error instead of silently returning empty content (which would produce 0
+// chunks with no signal). This restores the pre-PR "no text at all" fail-loud
+// semantics that the string-returning OpenAndExtract contract would otherwise
+// hide.
+func TestDOCParser_EmptyViewsReturnsError(t *testing.T) {
+ ctx := t.Context()
+ p := NewDOCParser()
+
+ orig := docExtract
+ defer func() { docExtract = orig }()
+ // Open succeeds, but all three views come back empty.
+ docExtract = func(data []byte, format string) (string, string, string, error, error) {
+ return "", "", "", nil, nil
+ }
+
+ res := p.ParseWithResult(ctx, "empty.doc", []byte("PK\x03\x04"))
+ if res.Err == nil {
+ t.Fatal("expected error for a document with no extractable text, got nil")
+ }
+ if errors.Is(res.Err, ErrOfficeCGORequired) {
+ t.Fatalf("got ErrOfficeCGORequired, want a content-extraction error: %v", res.Err)
+ }
+}
diff --git a/internal/parser/parser/docx_parser.go b/internal/parser/parser/docx_parser.go
index 77288fabb4..f691f653d4 100644
--- a/internal/parser/parser/docx_parser.go
+++ b/internal/parser/parser/docx_parser.go
@@ -1,5 +1,3 @@
-//go:build cgo
-
//
// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
//
@@ -7,36 +5,36 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
-//
package parser
import (
"context"
+ "errors"
"fmt"
"strings"
- officeOxide "github.com/yfedoseev/office_oxide/go"
+ deepdocoffice "ragflow/internal/deepdoc/parser/office"
)
-// docxOpenFromBytes is a test seam that mirrors officeOxide.OpenFromBytes.
-// Overridden in tests to capture the effective container format.
-// Not safe for concurrent use with t.Parallel() — tests must save/restore
-// it sequentially (see office_detect_cgo_test.go).
-var docxOpenFromBytes = officeOxide.OpenFromBytes
+// docxExtract is a test seam for the native office_oxide extraction. It
+// defaults to the deepdoc/docx backend (which is the only place that depends
+// on office_oxide) and is overridden in tests to capture the effective
+// container format passed to the engine.
+var docxExtract = deepdocoffice.OpenAndExtract
-// DOCXParser is the cgo-backed DOCX parser. It is the only DOCX
-// entrypoint that depends on office_oxide; the IR data model and
-// postprocessing live in cgo-free files (docx_ir.go, docx_postprocess.go)
-// so they compile and test without native libraries. The !cgo build
-// provides a stub DOCXParser in office_parsers_no_cgo.go.
+// DOCXParser is the DOCX/DOC parser. It is a CGO-free facade: magic-byte
+// sniffing and post-processing live here, while the native extraction lives
+// in internal/deepdoc/parser/office. The IR data model and postprocessing live
+// in cgo-free files (docx_ir.go, docx_postprocess.go, office_table_render.go)
+// so they compile and test without native libraries.
type DOCXParser struct {
libType string
outputFormat string // from DSL config; "json" or "markdown"
@@ -77,7 +75,7 @@ func (p *DOCXParser) ConfigureFromSetup(setup map[string]any) {
// File["format"] in the returned ParseResult reflects the effective
// container format after magic-byte sniffing (e.g. "doc" for an OLE
// payload uploaded as .docx), not merely the file extension. See
-// office_detect_cgo.go:officeContainer for the detection contract.
+// office_detect.go:officeContainer for the detection contract.
func (p *DOCXParser) ParseWithResult(ctx context.Context, filename string, data []byte) ParseResult {
// office_oxide's OpenFromBytes takes the container format as given
// and does no magic-byte detection, so a legacy .doc uploaded with a
@@ -94,11 +92,13 @@ func (p *DOCXParser) ParseWithResult(ctx context.Context, filename string, data
// opens the payload as ZIP and fails closed, so RemoveHeaderFooter becomes
// a no-op for legacy OLE inputs. This is acceptable — legacy DOC has no
// OOXML header/footer parts to strip.
- doc, err := docxOpenFromBytes(data, format)
+ irJSON, md, _, mdErr, err := docxExtract(data, format)
if err != nil {
- return ParseResult{Err: fmt.Errorf("docx open: %w", err)}
+ if errors.Is(err, deepdocoffice.ErrOfficeCGORequired) {
+ return ParseResult{Err: fmt.Errorf("%w: %s", ErrOfficeCGORequired, filename)}
+ }
+ return ParseResult{Err: fmt.Errorf("docx extract: %w", err)}
}
- defer doc.Close()
fileMeta := map[string]any{
"name": filename,
@@ -106,14 +106,27 @@ func (p *DOCXParser) ParseWithResult(ctx context.Context, filename string, data
}
// Extract IR JSON for section building (JSON path) and
- // embedded-image extraction on the Markdown path.
- irJSON, irErr := doc.ToIRJSON()
+ // embedded-image extraction (both paths). The budget bounds image
+ // payloads so the downstream VLM enhancement stays within limits.
+ budget := newEmbeddedMediaBudget()
+ if irJSON != "" {
+ figures := extractDOCXFiguresFromIR(irJSON, budget)
+ if len(figures) > 0 {
+ fileMeta["figures"] = buildFiguresMap(figures)
+ }
+ }
if p.outputFormat == "json" {
- if irErr != nil {
- return ParseResult{Err: fmt.Errorf("docx to-ir-json: %w", irErr)}
+ // The JSON path is built entirely from the structured IR, so an
+ // empty IR is a fatal parse error for this output format — the
+ // Markdown path below still has the plain-text fallback. The
+ // OpenAndExtract contract swallows per-view errors, so we cannot
+ // distinguish "IR failed" from "IR legitimately empty"; either way
+ // the JSON path has nothing to build from, so we fail loud
+ // (Finding B) rather than emit empty/garbage JSON sections.
+ if irJSON == "" {
+ return ParseResult{Err: fmt.Errorf("docx extract: empty IR, cannot build JSON output")}
}
- budget := newEmbeddedMediaBudget()
sections := buildDOCXJSONSections(irJSON, budget)
if err := ctx.Err(); err != nil {
return ParseResult{Err: err}
@@ -143,24 +156,20 @@ func (p *DOCXParser) ParseWithResult(ctx context.Context, filename string, data
}
}
- budget := newEmbeddedMediaBudget()
- if irErr == nil {
- figures := extractDOCXFiguresFromIR(irJSON, budget)
- if len(figures) > 0 {
- fileMeta["figures"] = buildFiguresMap(figures)
- }
- }
-
// Default / Markdown path.
- md, err := doc.ToMarkdown()
- if err != nil {
- return ParseResult{Err: fmt.Errorf("docx to-markdown: %w", err)}
+ if mdErr != nil {
+ // The Markdown view failed but other views survived. Surface the
+ // Markdown render error rather than silently emitting empty markdown
+ // (PR review Finding 3). The JSON path above is unaffected because it
+ // is built from the IR view.
+ return ParseResult{Err: fmt.Errorf("docx extract: markdown render failed: %w", mdErr)}
}
+ markdownPayload := md
// remove_header_footer on Markdown: filter lines by exact match
// (mirrors Python parser.py:923-926 split lines → filter → rejoin).
if p.RemoveHeaderFooter {
hfTexts := extractDOCXHeaderFooterTexts(data)
- lines := strings.Split(md, "\n")
+ lines := strings.Split(markdownPayload, "\n")
lineItems := make([]map[string]any, 0, len(lines))
for _, ln := range lines {
lineItems = append(lineItems, map[string]any{"text": ln})
@@ -170,13 +179,13 @@ func (p *DOCXParser) ParseWithResult(ctx context.Context, filename string, data
for _, item := range lineItems {
rebuilt = append(rebuilt, itemText(item))
}
- md = strings.Join(rebuilt, "\n")
+ markdownPayload = strings.Join(rebuilt, "\n")
}
// remove_toc on Markdown: split lines, filter, rejoin
// (mirrors Python parser.py:927-928 remove_toc_word on Markdown).
- if p.RemoveTOC && irErr == nil {
+ if p.RemoveTOC && irJSON != "" {
outlines := extractDOCXOutlines(irJSON)
- lines := strings.Split(md, "\n")
+ lines := strings.Split(markdownPayload, "\n")
lineItems := make([]map[string]any, 0, len(lines))
for _, ln := range lines {
lineItems = append(lineItems, map[string]any{"text": ln})
@@ -186,12 +195,12 @@ func (p *DOCXParser) ParseWithResult(ctx context.Context, filename string, data
for _, item := range filtered {
rebuilt = append(rebuilt, itemText(item))
}
- md = strings.Join(rebuilt, "\n")
+ markdownPayload = strings.Join(rebuilt, "\n")
}
return ParseResult{
OutputFormat: "markdown",
File: fileMeta,
- Markdown: md,
+ Markdown: markdownPayload,
Warnings: budget.warnings(),
}
}
diff --git a/internal/parser/parser/office_detect_cgo.go b/internal/parser/parser/office_detect.go
similarity index 69%
rename from internal/parser/parser/office_detect_cgo.go
rename to internal/parser/parser/office_detect.go
index 7e8a3cb47c..d310f10d7f 100644
--- a/internal/parser/parser/office_detect_cgo.go
+++ b/internal/parser/parser/office_detect.go
@@ -1,21 +1,3 @@
-//go:build cgo
-
-//
-// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
package parser
// officeContainer reports the on-disk container format of an Office
diff --git a/internal/parser/parser/office_detect_cgo_test.go b/internal/parser/parser/office_detect_test.go
similarity index 55%
rename from internal/parser/parser/office_detect_cgo_test.go
rename to internal/parser/parser/office_detect_test.go
index 73e0b0e810..ad2ea035ee 100644
--- a/internal/parser/parser/office_detect_cgo_test.go
+++ b/internal/parser/parser/office_detect_test.go
@@ -1,13 +1,8 @@
-//go:build cgo
-
package parser
import (
- "bytes"
"fmt"
"testing"
-
- officeOxide "github.com/yfedoseev/office_oxide/go"
)
// TestOfficeContainer verifies the magic-byte sniffing that lets the
@@ -51,13 +46,13 @@ func TestDOCXParser_FallsBackToDOCForOLEHeader(t *testing.T) {
ctx := t.Context()
p := NewDOCXParser()
- orig := docxOpenFromBytes
- defer func() { docxOpenFromBytes = orig }()
+ orig := docxExtract
+ defer func() { docxExtract = orig }()
var gotFormat string
- docxOpenFromBytes = func(data []byte, format string) (*officeOxide.Document, error) {
+ docxExtract = func(data []byte, format string) (string, string, string, error, error) {
gotFormat = format
- return nil, fmt.Errorf("stub doc open: %s", format)
+ return "", "", "", nil, fmt.Errorf("stub doc open: %s", format)
}
data := []byte{0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1}
@@ -66,7 +61,77 @@ func TestDOCXParser_FallsBackToDOCForOLEHeader(t *testing.T) {
t.Fatal("expected parse error for a non-document OLE header, got nil")
}
if gotFormat != "doc" {
- t.Fatalf("docxOpenFromBytes format = %q, want %q (OLE fallback not triggered)", gotFormat, "doc")
+ t.Fatalf("docxExtract format = %q, want %q (OLE fallback not triggered)", gotFormat, "doc")
+ }
+}
+
+// TestDOCXParser_JSONEmptyIRReturnsError locks Finding B: when the native
+// backend opens the document but returns an empty structured IR, the JSON
+// output path must fail loud (it is built entirely from the IR, which the
+// Markdown path can fall back from plain text). This guards against silently
+// emitting empty JSON sections.
+func TestDOCXParser_JSONEmptyIRReturnsError(t *testing.T) {
+ ctx := t.Context()
+ p := NewDOCXParser()
+ p.ConfigureFromSetup(map[string]any{"output_format": "json"})
+
+ orig := docxExtract
+ defer func() { docxExtract = orig }()
+ docxExtract = func(data []byte, format string) (string, string, string, error, error) {
+ // Open succeeds, but the IR view is empty.
+ return "", "", "", nil, nil
+ }
+
+ res := p.ParseWithResult(ctx, "empty.docx", []byte("PK\x03\x04"))
+ if res.Err == nil {
+ t.Fatal("expected error for JSON output with empty IR, got nil")
+ }
+}
+
+// TestDOCXParser_MarkdownViewErrorPropagated locks Finding 3: when the
+// native backend's Markdown view fails but the other views survive,
+// OpenAndExtract surfaces the Markdown error via mdErr and the Markdown output
+// path must fail loud instead of silently emitting empty markdown. The JSON
+// path is unaffected because it is built from the IR view.
+func TestDOCXParser_MarkdownViewErrorPropagated(t *testing.T) {
+ ctx := t.Context()
+ p := NewDOCXParser()
+ p.ConfigureFromSetup(map[string]any{"output_format": "markdown"})
+
+ orig := docxExtract
+ defer func() { docxExtract = orig }()
+ docxExtract = func(data []byte, format string) (string, string, string, error, error) {
+ // IR and plain text survive; only the Markdown view fails.
+ return "<ir/>", "", "plain text fallback", fmt.Errorf("markdown boom"), nil
+ }
+
+ res := p.ParseWithResult(ctx, "broken.docx", []byte("PK\x03\x04"))
+ if res.Err == nil {
+ t.Fatal("expected error when only the Markdown view fails, got nil")
+ }
+}
+
+// TestDOCXParser_AllViewsEmptyMarkdownReturnsError locks the engine-level
+// contract from Finding 1 at the parser boundary: when the native backend
+// opens the document but every view (IR / Markdown / PlainText) is empty,
+// OpenAndExtract reports a joined error, and the default Markdown output path
+// must fail loud rather than silently emit empty markdown. (office_oxide
+// always returns a structured IR for an openable doc, so this all-empty error
+// is simulated via the seam rather than a real fixture.)
+func TestDOCXParser_AllViewsEmptyMarkdownReturnsError(t *testing.T) {
+ ctx := t.Context()
+ p := NewDOCXParser()
+ p.ConfigureFromSetup(map[string]any{"output_format": "markdown"})
+
+ orig := docxExtract
+ defer func() { docxExtract = orig }()
+ docxExtract = func(data []byte, format string) (string, string, string, error, error) {
+ return "", "", "", nil, fmt.Errorf("office_oxide docx: all text views failed")
+ }
+
+ res := p.ParseWithResult(ctx, "empty.docx", []byte("PK\x03\x04"))
+ if res.Err == nil {
+ t.Fatal("expected error for a document with no extractable text in any view, got nil")
}
}
@@ -77,13 +142,13 @@ func TestDOCXParser_TruncatedOLENotFallback(t *testing.T) {
ctx := t.Context()
p := NewDOCXParser()
- orig := docxOpenFromBytes
- defer func() { docxOpenFromBytes = orig }()
+ orig := docxExtract
+ defer func() { docxExtract = orig }()
var gotFormat string
- docxOpenFromBytes = func(data []byte, format string) (*officeOxide.Document, error) {
+ docxExtract = func(data []byte, format string) (string, string, string, error, error) {
gotFormat = format
- return nil, fmt.Errorf("stub")
+ return "", "", "", nil, fmt.Errorf("stub")
}
data := []byte{0xD0, 0xCF, 0x11, 0xE0}
@@ -96,40 +161,19 @@ func TestDOCXParser_TruncatedOLENotFallback(t *testing.T) {
}
}
-// TestDOCXParser_OOXMLStillDOCX is the regression guard: a real OOXML
-// (ZIP) payload must still take the "docx" path and parse successfully.
-func TestDOCXParser_OOXMLStillDOCX(t *testing.T) {
- ctx := t.Context()
- p := NewDOCXParser()
- data := minimalDOCX(t, "round-trip OOXML")
- res := p.ParseWithResult(ctx, "real.docx", data)
- if res.Err != nil {
- t.Fatalf("ParseWithResult: %v", res.Err)
- }
- if res.OutputFormat != "markdown" {
- t.Fatalf("OutputFormat = %q, want %q", res.OutputFormat, "markdown")
- }
- if got := res.File["format"]; got != "docx" {
- t.Fatalf("File[format] = %v, want %q", got, "docx")
- }
- if !bytes.Contains([]byte(res.Markdown), []byte("round-trip OOXML")) {
- t.Fatalf("Markdown = %q, want it to contain the source text", res.Markdown)
- }
-}
-
// TestPPTXParser_FallsBackToPPTForOLEHeader ensures a legacy OLE .ppt
// payload routed to PPTXParser is opened with "ppt" rather than "pptx".
func TestPPTXParser_FallsBackToPPTForOLEHeader(t *testing.T) {
ctx := t.Context()
p := NewPPTXParser()
- orig := pptxOpenFromBytes
- defer func() { pptxOpenFromBytes = orig }()
+ orig := pptxExtract
+ defer func() { pptxExtract = orig }()
var gotFormat string
- pptxOpenFromBytes = func(data []byte, format string) (*officeOxide.Document, error) {
+ pptxExtract = func(data []byte, format string) (string, string, string, error, error) {
gotFormat = format
- return nil, fmt.Errorf("stub ppt open: %s", format)
+ return "", "", "", nil, fmt.Errorf("stub ppt open: %s", format)
}
data := []byte{0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1}
@@ -138,7 +182,7 @@ func TestPPTXParser_FallsBackToPPTForOLEHeader(t *testing.T) {
t.Fatal("expected parse error for OLE header, got nil")
}
if gotFormat != "ppt" {
- t.Fatalf("pptxOpenFromBytes format = %q, want %q", gotFormat, "ppt")
+ t.Fatalf("pptxExtract format = %q, want %q", gotFormat, "ppt")
}
if p.format != "pptx" {
t.Fatalf("PPTXParser.format mutated to %q, want %q (must use local effFormat)", p.format, "pptx")
@@ -152,13 +196,13 @@ func TestPPTParser_FallsBackToPPTXForOOXMLHeader(t *testing.T) {
ctx := t.Context()
p := NewPPTParser() // underlying PPTXParser{format:"ppt"}
- orig := pptxOpenFromBytes
- defer func() { pptxOpenFromBytes = orig }()
+ orig := pptxExtract
+ defer func() { pptxExtract = orig }()
var gotFormat string
- pptxOpenFromBytes = func(data []byte, format string) (*officeOxide.Document, error) {
+ pptxExtract = func(data []byte, format string) (string, string, string, error, error) {
gotFormat = format
- return nil, fmt.Errorf("stub ppt open: %s", format)
+ return "", "", "", nil, fmt.Errorf("stub ppt open: %s", format)
}
// Minimal OOXML ZIP local file header.
@@ -168,7 +212,7 @@ func TestPPTParser_FallsBackToPPTXForOOXMLHeader(t *testing.T) {
t.Fatal("expected parse error for OOXML header stub, got nil")
}
if gotFormat != "pptx" {
- t.Fatalf("pptxOpenFromBytes format = %q, want %q (OOXML fallback ppt->pptx)", gotFormat, "pptx")
+ t.Fatalf("pptxExtract format = %q, want %q (OOXML fallback ppt->pptx)", gotFormat, "pptx")
}
// Underlying PPTXParser must not be mutated permanently.
if p.pptx.format != "ppt" {
@@ -183,13 +227,13 @@ func TestPPTXParser_NoStatePollution(t *testing.T) {
ctx := t.Context()
p := NewPPTXParser()
- orig := pptxOpenFromBytes
- defer func() { pptxOpenFromBytes = orig }()
+ orig := pptxExtract
+ defer func() { pptxExtract = orig }()
calls := []string{}
- pptxOpenFromBytes = func(data []byte, format string) (*officeOxide.Document, error) {
+ pptxExtract = func(data []byte, format string) (string, string, string, error, error) {
calls = append(calls, format)
- return nil, fmt.Errorf("stub")
+ return "", "", "", nil, fmt.Errorf("stub")
}
oleData := []byte{0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1}
@@ -207,18 +251,3 @@ func TestPPTXParser_NoStatePollution(t *testing.T) {
t.Errorf("second call format = %q, want %q (state polluted)", calls[1], "pptx")
}
}
-
-// TestPPTXParser_OOXMLStillPPTX validates the effective format and File
-// metadata for a real OOXML presentation.
-func TestPPTXParser_OOXMLStillPPTX(t *testing.T) {
- ctx := t.Context()
- p := NewPPTXParser()
- data := buildPPTX(t, "pptx round-trip")
- res := p.ParseWithResult(ctx, "real.pptx", data)
- if res.Err != nil {
- t.Fatalf("ParseWithResult: %v", res.Err)
- }
- if got := res.File["format"]; got != "pptx" {
- t.Fatalf("File[format] = %v, want %q", got, "pptx")
- }
-}
diff --git a/internal/parser/parser/office_parsers.go b/internal/parser/parser/office_parsers.go
new file mode 100644
index 0000000000..fa5b8ac149
--- /dev/null
+++ b/internal/parser/parser/office_parsers.go
@@ -0,0 +1,11 @@
+package parser
+
+import "errors"
+
+// ErrOfficeCGORequired is returned by the office-family parsers
+// (DOC/DOCX/PPT/PPTX) when the build has no native office_oxide backend.
+// The native engine (internal/deepdoc/parser/office) reports its own
+// ErrOfficeCGORequired sentinel, which the facade wraps into this one so
+// callers see a stable, parser-package error regardless of which layer
+// reports the missing engine.
+var ErrOfficeCGORequired = errors.New("parser: office family requires CGO (office_oxide)")
diff --git a/internal/parser/parser/office_parsers_no_cgo.go b/internal/parser/parser/office_parsers_no_cgo.go
deleted file mode 100644
index b00d0c6f60..0000000000
--- a/internal/parser/parser/office_parsers_no_cgo.go
+++ /dev/null
@@ -1,87 +0,0 @@
-//go:build !cgo
-
-package parser
-
-import (
- "context"
- "errors"
- "fmt"
-)
-
-// ErrOfficeCGORequired is returned by ParseWithResult on every
-// office-parser family (DOC / DOCX / PPT / PPTX)
-// when the build is not CGO-enabled. The CGO build's
-// implementation captures the office_oxide PlainText / ToMarkdown
-// output; this stub mirrors that surface so the package compiles
-// and existing tests pass. The error is surfaced at parse time
-// rather than at construction time, matching the NewPDFParser
-// shape used by the rest of the package.
-var ErrOfficeCGORequired = errors.New("parser: office family requires CGO (office_oxide)")
-
-func (p *DOCXParser) ParseWithResult(_ context.Context, filename string, _ []byte) ParseResult {
- return ParseResult{
- File: map[string]any{"name": filename},
- Err: fmt.Errorf("%w: docx", ErrOfficeCGORequired),
- }
-}
-
-func (p *DOCParser) ParseWithResult(_ context.Context, filename string, _ []byte) ParseResult {
- return ParseResult{
- File: map[string]any{"name": filename},
- Err: fmt.Errorf("%w: doc", ErrOfficeCGORequired),
- }
-}
-
-func (p *PPTParser) ParseWithResult(_ context.Context, filename string, _ []byte) ParseResult {
- return ParseResult{
- File: map[string]any{"name": filename},
- Err: fmt.Errorf("%w: ppt", ErrOfficeCGORequired),
- }
-}
-
-func (p *PPTXParser) ParseWithResult(_ context.Context, filename string, _ []byte) ParseResult {
- return ParseResult{
- File: map[string]any{"name": filename},
- Err: fmt.Errorf("%w: pptx", ErrOfficeCGORequired),
- }
-}
-
-type DOCParser struct{}
-
-func NewDOCParser() *DOCParser {
- return &DOCParser{}
-}
-
-func (p *DOCParser) String() string {
- return "DOCParser(no-cgo)"
-}
-
-type DOCXParser struct{}
-
-func NewDOCXParser() *DOCXParser {
- return &DOCXParser{}
-}
-
-func (p *DOCXParser) String() string {
- return "DOCXParser(no-cgo)"
-}
-
-type PPTParser struct{}
-
-func NewPPTParser() *PPTParser {
- return &PPTParser{}
-}
-
-func (p *PPTParser) String() string {
- return "PPTParser(no-cgo)"
-}
-
-type PPTXParser struct{}
-
-func NewPPTXParser() *PPTXParser {
- return &PPTXParser{}
-}
-
-func (p *PPTXParser) String() string {
- return "PPTXParser(no-cgo)"
-}
diff --git a/internal/parser/parser/office_parsers_shared.go b/internal/parser/parser/office_parsers_shared.go
deleted file mode 100644
index 3f9e957761..0000000000
--- a/internal/parser/parser/office_parsers_shared.go
+++ /dev/null
@@ -1,6 +0,0 @@
-//go:build !cgo
-
-package parser
-
-// OfficeOxide is the lib_type identifier for office_oxide backend.
-const OfficeOxide = "office_oxide"
diff --git a/internal/parser/parser/pdf_parser_cgo.go b/internal/parser/parser/pdf_parser_cgo.go
deleted file mode 100644
index 959b275484..0000000000
--- a/internal/parser/parser/pdf_parser_cgo.go
+++ /dev/null
@@ -1,55 +0,0 @@
-//go:build cgo
-
-package parser
-
-import (
- "context"
- "errors"
- "fmt"
- "ragflow/internal/common"
-
- deepdocpdf "ragflow/internal/deepdoc/parser/pdf"
- deepdoctype "ragflow/internal/deepdoc/parser/type"
-)
-
-func (p *PDFParser) ParseWithResult(ctx context.Context, filename string, data []byte) ParseResult {
- if err := p.validateParseMethod(); err != nil {
- return ParseResult{Err: err}
- }
- common.Info(fmt.Sprintf("------------file: %s, parse_method: %s", filename, p.ParseMethod))
- switch normalizePDFParseMethod(p.ParseMethod) {
- case "plain_text":
- return parsePDFWithPlainText(filename, data, p)
- case "mineru":
- return parsePDFWithMinerU(ctx, filename, data, p)
- case "paddleocr":
- return parsePDFWithPaddleOCR(ctx, filename, data, p)
- case "docling":
- return parsePDFWithDocling(ctx, filename, data, p)
- case "opendataloader":
- return parsePDFWithOpenDataLoader(ctx, filename, data, p)
- case "somark":
- return parsePDFWithSoMark(filename, data, p)
- case "tcadp":
- return parsePDFWithTCADP(filename, data, p)
- }
- cfg := deepdoctype.DefaultParserConfig()
- cfg.Pages = p.Pages
- cfg.RemoveTOC = p.RemoveTOC
- cfg.RemoveHeaderFooter = p.RemoveHeaderFooter
- cfg.OnPageDone = p.OnPageDone
- parser := deepdocpdf.NewParser(cfg)
- res := parsePDFWithDeepDocOptions(ctx, filename, data, pdfPostProcessOptions{
- outputFormat: p.OutputFormat,
- zoom: cfg.Zoom,
- enableMultiColumn: p.EnableMultiColumn,
- flattenMediaToText: p.FlattenMediaToText,
- }, parser.Parse)
- if res.Err != nil && errors.Is(res.Err, deepdocpdf.ErrNoPDFData) {
- return ParseResult{Err: fmt.Errorf("%w: %s", ErrPDFEngineUnavailable, filename)}
- }
- if res.Err != nil && res.Err.Error() == "deepdoc/pdf: cgo required" {
- return ParseResult{Err: fmt.Errorf("%w: %s", ErrPDFEngineUnavailable, filename)}
- }
- return res
-}
diff --git a/internal/parser/parser/pdf_parser_common.go b/internal/parser/parser/pdf_parser_common.go
index f421c04888..f5e4201c07 100644
--- a/internal/parser/parser/pdf_parser_common.go
+++ b/internal/parser/parser/pdf_parser_common.go
@@ -334,6 +334,61 @@ func (p *PDFParser) validateParseMethod() error {
return fmt.Errorf("parser: unsupported PDF parse_method %q (Go currently supports: deepdoc, plain_text, mineru, paddleocr, docling, opendataloader, somark, tcadp; tenant-resolved custom IMAGE2TEXT/VLM model names are not supported in the Go parser layer)", p.ParseMethod)
}
+// ParseWithResult parses a PDF into a ParseResult, dispatching on the
+// configured ParseMethod. The native extraction — the deepdoc default and the
+// plain_text strategy — lives in the internal/deepdoc/parser/pdf engine; this
+// method is the facade that wires strategies and post-processing. It is
+// build-tag agnostic: under !cgo the deepdoc path transparently reports
+// ErrPDFEngineUnavailable while plain_text falls back to the pure-Go engine.
+func (p *PDFParser) ParseWithResult(ctx context.Context, filename string, data []byte) ParseResult {
+ if err := p.validateParseMethod(); err != nil {
+ return ParseResult{Err: err}
+ }
+ common.Info(fmt.Sprintf("------------file: %s, parse_method: %s", filename, p.ParseMethod))
+ switch normalizePDFParseMethod(p.ParseMethod) {
+ case "plain_text":
+ if len(data) == 0 {
+ return emptyPDFResult(filename)
+ }
+ items, pageCount, err := deepdocpdf.PlainText(data)
+ if err != nil {
+ return ParseResult{Err: fmt.Errorf("parser: plain_text: %w", err)}
+ }
+ return pdfItemsToResult(filename, items, p.OutputFormat, pageCount)
+ case "mineru":
+ return parsePDFWithMinerU(ctx, filename, data, p)
+ case "paddleocr":
+ return parsePDFWithPaddleOCR(ctx, filename, data, p)
+ case "docling":
+ return parsePDFWithDocling(ctx, filename, data, p)
+ case "opendataloader":
+ return parsePDFWithOpenDataLoader(ctx, filename, data, p)
+ case "somark":
+ return parsePDFWithSoMark(filename, data, p)
+ case "tcadp":
+ return parsePDFWithTCADP(filename, data, p)
+ }
+ cfg := deepdoctype.DefaultParserConfig()
+ cfg.Pages = p.Pages
+ cfg.RemoveTOC = p.RemoveTOC
+ cfg.RemoveHeaderFooter = p.RemoveHeaderFooter
+ cfg.OnPageDone = p.OnPageDone
+ res := parsePDFWithDeepDocOptions(ctx, filename, data, pdfPostProcessOptions{
+ outputFormat: p.OutputFormat,
+ zoom: cfg.Zoom,
+ enableMultiColumn: p.EnableMultiColumn,
+ flattenMediaToText: p.FlattenMediaToText,
+ }, deepdocpdf.NewParser(cfg).Parse)
+ if res.Err != nil {
+ if errors.Is(res.Err, deepdocpdf.ErrNoPDFData) ||
+ strings.Contains(res.Err.Error(), "deepdoc/pdf: cgo required") ||
+ strings.Contains(res.Err.Error(), "no in-process DeepDoc backend") {
+ return ParseResult{Err: fmt.Errorf("%w: %s", ErrPDFEngineUnavailable, filename)}
+ }
+ }
+ return res
+}
+
func emptyPDFResult(filename string) ParseResult {
return ParseResult{
OutputFormat: "json",
diff --git a/internal/parser/parser/pdf_parser_nocgo.go b/internal/parser/parser/pdf_parser_nocgo.go
deleted file mode 100644
index ad3a67d0ec..0000000000
--- a/internal/parser/parser/pdf_parser_nocgo.go
+++ /dev/null
@@ -1,36 +0,0 @@
-//go:build !cgo
-
-package parser
-
-import (
- "context"
- "fmt"
-)
-
-func (p *PDFParser) ParseWithResult(ctx context.Context, filename string, data []byte) ParseResult {
- if err := p.validateParseMethod(); err != nil {
- return ParseResult{Err: err}
- }
- switch normalizePDFParseMethod(p.ParseMethod) {
- case "plain_text":
- return parsePDFWithPlainText(filename, data, p)
- case "mineru":
- return parsePDFWithMinerU(ctx, filename, data, p)
- case "paddleocr":
- return parsePDFWithPaddleOCR(ctx, filename, data, p)
- case "docling":
- return parsePDFWithDocling(ctx, filename, data, p)
- case "opendataloader":
- return parsePDFWithOpenDataLoader(ctx, filename, data, p)
- case "somark":
- return parsePDFWithSoMark(filename, data, p)
- case "tcadp":
- return parsePDFWithTCADP(filename, data, p)
- }
- if len(data) == 0 {
- return emptyPDFResult(filename)
- }
- return ParseResult{
- Err: fmt.Errorf("%w: %s", ErrPDFEngineUnavailable, filename),
- }
-}
diff --git a/internal/parser/parser/pdf_parser_plaintext_cgo.go b/internal/parser/parser/pdf_parser_plaintext_cgo.go
deleted file mode 100644
index 52b2dfc5fa..0000000000
--- a/internal/parser/parser/pdf_parser_plaintext_cgo.go
+++ /dev/null
@@ -1,38 +0,0 @@
-//go:build cgo
-
-package parser
-
-import (
- "fmt"
-
- "ragflow/internal/deepdoc/parser/pdf/pdfoxide"
-)
-
-func parsePDFWithPlainText(filename string, data []byte, parser *PDFParser) ParseResult {
- if len(data) == 0 {
- return emptyPDFResult(filename)
- }
- doc, err := pdfoxide.OpenBytes(data)
- if err != nil {
- return ParseResult{Err: fmt.Errorf("parser: plain_text open: %w", err)}
- }
- defer doc.Close()
-
- pageCount, err := doc.PageCount()
- if err != nil {
- return ParseResult{Err: fmt.Errorf("parser: plain_text page count: %w", err)}
- }
- items := make([]map[string]any, 0, pageCount)
- for page := 0; page < pageCount; page++ {
- text, err := doc.GetPageText(page)
- if err != nil {
- return ParseResult{Err: fmt.Errorf("parser: plain_text page %d: %w", page+1, err)}
- }
- items = append(items, map[string]any{
- "text": text,
- "doc_type_kwd": "text",
- "page_number": page + 1,
- })
- }
- return pdfItemsToResult(filename, items, parser.OutputFormat, pageCount)
-}
diff --git a/internal/parser/parser/pdf_parser_plaintext_nocgo.go b/internal/parser/parser/pdf_parser_plaintext_nocgo.go
deleted file mode 100644
index efbc991469..0000000000
--- a/internal/parser/parser/pdf_parser_plaintext_nocgo.go
+++ /dev/null
@@ -1,42 +0,0 @@
-//go:build !cgo
-
-package parser
-
-import (
- "bytes"
- "fmt"
- "strings"
-
- "github.com/ledongthuc/pdf"
-)
-
-func parsePDFWithPlainText(filename string, data []byte, parser *PDFParser) ParseResult {
- if len(data) == 0 {
- return emptyPDFResult(filename)
- }
-
- reader := bytes.NewReader(data)
- pdfReader, err := pdf.NewReader(reader, int64(len(data)))
- if err != nil {
- return ParseResult{Err: fmt.Errorf("parser: plain_text open: %w", err)}
- }
-
- pageCount := pdfReader.NumPage()
- items := make([]map[string]any, 0, pageCount)
- for pageNum := 1; pageNum <= pageCount; pageNum++ {
- p := pdfReader.Page(pageNum)
- if p.V.IsNull() {
- continue
- }
- text, err := p.GetPlainText(nil)
- if err != nil {
- return ParseResult{Err: fmt.Errorf("parser: plain_text page %d: %w", pageNum, err)}
- }
- items = append(items, map[string]any{
- "text": strings.TrimRight(text, "\n"),
- "doc_type_kwd": "text",
- "page_number": pageNum,
- })
- }
- return pdfItemsToResult(filename, items, parser.OutputFormat, pageCount)
-}
diff --git a/internal/parser/parser/ppt_parser.go b/internal/parser/parser/ppt_parser.go
index d7e4b12a42..68658ee5ae 100644
--- a/internal/parser/parser/ppt_parser.go
+++ b/internal/parser/parser/ppt_parser.go
@@ -1,5 +1,3 @@
-//go:build cgo
-
//
// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
//
@@ -7,14 +5,13 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
-//
package parser
diff --git a/internal/parser/parser/pptx_parser.go b/internal/parser/parser/pptx_parser.go
index 8b7a6c9bb4..5a2420df7c 100644
--- a/internal/parser/parser/pptx_parser.go
+++ b/internal/parser/parser/pptx_parser.go
@@ -1,5 +1,3 @@
-//go:build cgo
-
//
// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
//
@@ -7,29 +5,29 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
-//
package parser
import (
"context"
+ "errors"
"fmt"
"strings"
- officeOxide "github.com/yfedoseev/office_oxide/go"
+ deepdocoffice "ragflow/internal/deepdoc/parser/office"
)
-// pptxOpenFromBytes is a test seam mirroring officeOxide.OpenFromBytes.
-// Not safe for concurrent use with t.Parallel() — tests must save/restore
-// it sequentially.
-var pptxOpenFromBytes = officeOxide.OpenFromBytes
+// pptxExtract is a test seam for the native office_oxide extraction. It
+// defaults to the deepdoc/docx backend and is overridden in tests to capture
+// the effective container format passed to the engine.
+var pptxExtract = deepdocoffice.OpenAndExtract
// PPTXParser parses both .pptx (OOXML) and .ppt (OLE binary)
// files via the office_oxide backend. The format field controls
@@ -118,6 +116,7 @@ func (p *PPTXParser) ParseWithResult(ctx context.Context, filename string, data
// PDF-specific methods like "paddleocr" / "mineru" are
// meaningless for PPTX; treat as default path.
}
+
// office_oxide's OpenFromBytes takes the container format as given
// and does no magic-byte detection, so a legacy .ppt uploaded with a
// .pptx extension would be parsed as ZIP/OOXML and fail. Sniff the
@@ -138,30 +137,28 @@ func (p *PPTXParser) ParseWithResult(ctx context.Context, filename string, data
effFormat = "pptx"
}
}
- doc, err := pptxOpenFromBytes(data, effFormat)
+ irJSON, _, plainText, _, err := pptxExtract(data, effFormat)
if err != nil {
- return ParseResult{Err: fmt.Errorf("presentation open: %w", err)}
+ if errors.Is(err, deepdocoffice.ErrOfficeCGORequired) {
+ return ParseResult{Err: fmt.Errorf("%w: %s", ErrOfficeCGORequired, filename)}
+ }
+ return ParseResult{Err: fmt.Errorf("presentation extract: %w", err)}
}
- defer doc.Close()
// office_oxide's PlainText renders slides back-to-back with no page
// delimiter, so per-slide splitting must go through the structured
- // IR, which carries one section per slide.
- irJSON, err := doc.ToIRJSON()
- if err != nil {
- // Salvage path: the document opened but its structured IR could
- // not be serialized. Fall back to whole-document plain text
- // (worst case: the entire deck as one chunk) so a still-readable
- // deck yields content instead of a hard parse error. The original
- // IR error is surfaced only when plain text fails too.
- text, perr := doc.PlainText()
- if perr != nil {
- return ParseResult{Err: fmt.Errorf("presentation ir-json: %w", err)}
+ // IR, which carries one section per slide. When the IR is empty, fall
+ // back to whole-document plain text (worst case: the entire deck as one
+ // chunk) so a still-readable deck yields content instead of a hard
+ // parse error.
+ if strings.TrimSpace(irJSON) == "" {
+ if strings.TrimSpace(plainText) == "" {
+ return ParseResult{Err: fmt.Errorf("presentation ir-json: empty result")}
}
return ParseResult{
OutputFormat: "json",
- File: map[string]any{"name": filename, "format": p.format},
- JSON: itemsFromPlainText(text),
+ File: map[string]any{"name": filename, "format": effFormat},
+ JSON: itemsFromPlainText(plainText),
}
}
budget := newEmbeddedMediaBudget()
@@ -179,11 +176,9 @@ func (p *PPTXParser) ParseWithResult(ctx context.Context, filename string, data
// still-readable file yields content instead of none. Without
// the all-empty check, empty items flow to the Tokenizer, which
// filters them as empty text, silently yielding 0 chunks.
- text, perr := doc.PlainText()
- if perr != nil {
- return ParseResult{Err: fmt.Errorf("presentation plain-text: %w", perr)}
+ if strings.TrimSpace(plainText) != "" {
+ items = itemsFromPlainText(plainText)
}
- items = itemsFromPlainText(text)
}
return ParseResult{
diff --git a/test/playwright/conftest.py b/test/playwright/conftest.py
index c2e3707127..e3bcbbdd67 100644
--- a/test/playwright/conftest.py
+++ b/test/playwright/conftest.py
@@ -113,7 +113,7 @@ def _playwright_auth_ready_timeout_ms() -> int | None:
def _playwright_hang_timeout_s() -> int:
raw = _env_int_with_fallback("PLAYWRIGHT_HANG_TIMEOUT_S", "HANG_TIMEOUT_S", DEFAULT_HANG_TIMEOUT_S)
- return raw if raw > 0 else 0
+ return max(0, raw)
def _failure_text(req) -> str:
@@ -400,8 +400,8 @@ def _rsa_encrypt_password(password: str) -> str:
global _PUBLIC_KEY_CACHE
global _RSA_CIPHER_CACHE
try:
- from Cryptodome.PublicKey import RSA
from Cryptodome.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5
+ from Cryptodome.PublicKey import RSA
except Exception as exc:
raise RuntimeError("Cryptodome is required to encrypt passwords for API seeding. Set RAGFLOW_SEEDING_MODE=ui to skip API seeding.") from exc
if _PUBLIC_KEY_CACHE is None:
diff --git a/test/testcases/configs.py b/test/testcases/configs.py
index b8331d979b..65b71ef5b9 100644
--- a/test/testcases/configs.py
+++ b/test/testcases/configs.py
@@ -19,7 +19,6 @@ from pathlib import Path
import pytest
-
_DOCKER_ENV = Path(__file__).resolve().parents[2] / "docker" / ".env"
diff --git a/test/testcases/restful_api/test_agents_go_mode.py b/test/testcases/restful_api/test_agents_go_mode.py
index 6ec00245dd..175f300ab4 100644
--- a/test/testcases/restful_api/test_agents_go_mode.py
+++ b/test/testcases/restful_api/test_agents_go_mode.py
@@ -1,5 +1,6 @@
import os
import uuid
+
import pytest
pytestmark = pytest.mark.skipif(
diff --git a/test/testcases/restful_api/test_chats.py b/test/testcases/restful_api/test_chats.py
index 6c14b76566..47cf7a1731 100644
--- a/test/testcases/restful_api/test_chats.py
+++ b/test/testcases/restful_api/test_chats.py
@@ -18,8 +18,8 @@ import asyncio
import importlib.util
import re
import sys
-from copy import deepcopy
from concurrent.futures import ThreadPoolExecutor
+from copy import deepcopy
from enum import Enum
from functools import wraps
from pathlib import Path
@@ -33,7 +33,6 @@ from test.testcases.restful_api.helpers.client import RestClient
from test.testcases.utils import encode_avatar
from test.testcases.utils.file_utils import create_image_file
-
DEFAULT_CHAT_EMPTY_RESPONSE = "Sorry! No relevant content was found in the knowledge base!"
DEFAULT_CHAT_PROLOGUE = "Hi! I'm your assistant. What can I do for you?"
DEFAULT_CHAT_SYSTEM_PROMPT = (
@@ -628,7 +627,8 @@ def _load_chat_routes_unit_module(monkeypatch):
common_constants_mod.LLMType = _StubLLMType
common_constants_mod.RetCode = _StubRetCode
common_constants_mod.StatusEnum = _StubStatusEnum
- from common.constants import MAXIMUM_PAGE_NUMBER as _MPN, MAXIMUM_TASK_PAGE_NUMBER as _MTPN
+ from common.constants import MAXIMUM_PAGE_NUMBER as _MPN
+ from common.constants import MAXIMUM_TASK_PAGE_NUMBER as _MTPN
common_constants_mod.MAXIMUM_PAGE_NUMBER = _MPN
common_constants_mod.MAXIMUM_TASK_PAGE_NUMBER = _MTPN
diff --git a/test/testcases/restful_api/test_search_datasets_consistency.py b/test/testcases/restful_api/test_search_datasets_consistency.py
index 4e47d5449c..3837e777e3 100644
--- a/test/testcases/restful_api/test_search_datasets_consistency.py
+++ b/test/testcases/restful_api/test_search_datasets_consistency.py
@@ -35,12 +35,13 @@ runs against the pre-built data. Cleanup happens automatically at module teardow
import logging
import os
import sys
-import pytest
-import requests
import tempfile
import time
import uuid
+import pytest
+import requests
+
# Logging setup
# Default is silent. Set LOG_LEVEL=INFO locally to see logger.info() messages.
_LOG_LEVEL = os.environ.get("LOG_LEVEL", "WARNING").upper()