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(parser): make IsPDFParseMethod recognize registered external analyzer methods (#21383)
xugangqiangfced7746a32d
diff --git a/internal/parser/parser/pdf_parser_common.go b/internal/parser/parser/pdf_parser_common.goindex 7ab8d5c55e..bc7b775582 100644--- a/internal/parser/parser/pdf_parser_common.go+++ b/internal/parser/parser/pdf_parser_common.go@@ -299,9 +299,26 @@ var pdfParseMethodSpellings = map[string]string{// IsPDFParseMethod reports whether raw names a PDF parse method rather than// a VLM model selector. "@"-suffixed spellings such as "foo@mineru" are// layout_recognizer selectors resolved separately, so they report false.+//+// A method backed by a registered external analyzer factory (see+// RegisterAnalyzerFactory — e.g. "deepdoc_ee" in the EE build) is a real PDF+// parse method even though it is absent from the built-in whitelist: it is+// routed to the DeepDoc dispatch path. Recognizing it here keeps+// IsPDFParseMethod consistent with validateParseMethod and stops the routing+// code (pdf_vision_dispatch.go and the ingestion config migration) from+// misclassifying a registered method as a VLM model selector.func IsPDFParseMethod(raw string) bool {- _, ok := pdfParseMethodSpellings[strings.ToLower(strings.TrimSpace(raw))]- return ok+ key := strings.ToLower(strings.TrimSpace(raw))+ if _, ok := pdfParseMethodSpellings[key]; ok {+ return true+ }+ // Registered external methods are keyed by their normalized token (see+ // RegisterAnalyzerFactory / resolveDocAnalyzerForMethod), so look them up+ // via normalizePDFParseMethod rather than the raw key.+ if _, ok := analyzerFactories[normalizePDFParseMethod(raw)]; ok {+ return true+ }+ return false}func normalizePDFParseMethod(raw string) string {diff --git a/internal/parser/parser/pdf_parser_is_method_test.go b/internal/parser/parser/pdf_parser_is_method_test.gonew file mode 100644index 0000000000..2ae3b4dc56--- /dev/null+++ b/internal/parser/parser/pdf_parser_is_method_test.go@@ -0,0 +1,64 @@+package parser++import (+ "testing"++ deepdoctype "ragflow/internal/deepdoc/parser/type"+)++// TestIsPDFParseMethod_RecognizesRegisteredExternalAnalyzer covers the gap that+// the EE build surfaced: a parse method backed by a registered external+// analyzer factory (RegisterAnalyzerFactory) must be reported as a PDF parse+// method, consistent with validateParseMethod. Without this, routing code such+// as pdf_vision_dispatch.go and the ingestion config migration would+// misclassify a registered method (e.g. "deepdoc_ee") as a VLM model selector.+func TestIsPDFParseMethod_RecognizesRegisteredExternalAnalyzer(t *testing.T) {+ const method = "ext_is_pdf_parse_method_fix"+ factory := func(u string) (deepdoctype.DocAnalyzer, error) {+ return &stubDispatchAnalyzer{tag: method}, nil+ }+ // "ext_is_pdf_parse_method_fix" is a non-built-in custom method, so+ // RegisterAnalyzerFactory accepts it (it only panics for built-ins and the+ // empty method).+ RegisterAnalyzerFactory(method, factory)+ // The registry persists across tests in this package; remove our entry so+ // other tests (and re-runs) see a clean global state.+ t.Cleanup(func() { delete(analyzerFactories, normalizePDFParseMethod(method)) })++ // Registered method is recognized as a PDF parse method.+ if !IsPDFParseMethod(method) {+ t.Errorf("IsPDFParseMethod(%q) = false, want true for a registered external analyzer method", method)+ }+ // Recognition survives the same normalization IsPDFParseMethod applies+ // internally (case-fold + trim), because the lookup uses the normalized key.+ if !IsPDFParseMethod(" EXT_IS_PDF_PARSE_METHOD_FIX ") {+ t.Errorf("IsPDFParseMethod(<case/space variant of %q>) = false, want true", method)+ }+}++// TestIsPDFParseMethod_BuiltinAndSelectorBehavior documents the contract that+// must NOT change when external methods are recognized:+// - built-in whitelist spellings still report true;+// - unknown methods report false;+// - "@"-suffixed layout_recognizer selectors report false (resolved separately).+func TestIsPDFParseMethod_BuiltinAndSelectorBehavior(t *testing.T) {+ cases := []struct {+ raw string+ want bool+ }{+ {"deepdoc", true},+ {"plain_text", true},+ {"plaintext", true},+ {"mineru", true},+ {"paddleocr", true},+ {"somark", true},+ {"unknown_method_xyz", false},+ {"foo@mineru", false},+ {"bar @paddleocr", false},+ }+ for _, c := range cases {+ if got := IsPDFParseMethod(c.raw); got != c.want {+ t.Errorf("IsPDFParseMethod(%q) = %v, want %v", c.raw, got, c.want)+ }+ }+}