Skip to content

feat: parser component param check and family mapping fixes - #17312

Merged
yingfeng merged 1 commit into
infiniflow:mainfrom
xugangqiang:feat/parser-file-type-family
Jul 23, 2026
Merged

yingfeng merged 1 commit into
infiniflow:mainfrom
xugangqiang:feat/parser-file-type-family

Conversation

@xugangqiang

Copy link
Copy Markdown
Contributor

Summary

Adds construction-time parameter validation to the ingestion ParserComponent (mirroring the applicable subset of Python ParserParam.check()), fixes a family-mapping mismatch that silently skipped output_format validation and setup configuration for image/audio files, and aligns the no-CGO parser stubs with the CGO variants by threading context.Context through ParseWithResult.

What changed

Parser component param check (internal/ingestion/component/parser.go)

  • New (*ParserComponent).Check() method mirrors the applicable subset of Python ParserParam.check() (rag/flow/parser/parser.py:251-321):
    • PDF family: rejects empty parse_method; non-whitelist values are treated as VLM methods and require lang.
    • Image family: non-ocr parse_method requires lang.
  • NewParserComponent now runs Check() at construction time, so a malformed DSL surfaces as a canvas compile failure rather than a mid-run error.
  • Audio output_format default changed from text to json to match the other media families.
  • Intentionally not covered:
    • output_format whitelist — already enforced at Invoke time by resolveOutputFormat.
    • audio/video vlm.llm_id — Go media_dispatch resolves tenant default models via resolveTenantModelByType, not setup["vlm"]["llm_id"]. Validating it would block every valid audio/video pipeline.

Family mapping fix (internal/ingestion/component/parser_dispatch.go)

  • pythonFamilyName now maps the semantic FileType constants to the actual setups keys:
    • visual/picture → image (was picture, mismatching the defaultSetups key, so output_format validation and configureParserFromSetups were silently skipped for image files)
    • aural → audio (previously matched no case at all)
    • video → video and email → email now also match the FileTypeVIDEO/FileTypeEMAIL constants directly.

context.Context threading for no-CGO stubs

  • ParseWithResult on DOCXParser, DOCParser, PPTParser, PPTXParser, PDFParser (no-CGO variants) now accepts context.Context, aligning with the CGO variants.
  • PDFParser threads ctx into parsePDFWithMinerU / parsePDFWithPaddleOCR / parsePDFWithDocling / parsePDFWithOpenDataLoader.

Tests

  • parser_check_test.go (new): table-driven coverage for Check() across PDF/image families, audio/video vlm omission, and empty/default configurations.
  • parser_dispatch_test.go: TestPythonFamilyName_FileTypeConstants pins every FileType constant to its setups key, and TestConfigureParserFromSetups_VisualAural pins that image/audio files pick up their setup.
  • office_parsers_nocgo_test.go, pdf_parser_nocgo_test.go: updated for the new ctx parameter.

Backward compatibility

  • Check() runs at construction time and returns errors for malformed DSLs that previously failed silently at runtime or were silently mis-configured. Callers constructing pipelines from validated DSLs (e.g. the shipped ingestion_pipeline_*.json templates) are unaffected.
  • ParseWithResult signature change is internal to the parser package; no public API impact.
  • The audio output_format default change (text → json) aligns with the other media families; pipelines that explicitly set output_format are unaffected.

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 23, 2026
@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Parser construction now validates PDF and image setups, media dispatch recognizes additional file types, and audio defaults use JSON output. No-CGO PDF and office parser methods now accept context values, with tests updated for the new signatures.

Changes

Parser configuration and dispatch

Layer / File(s) Summary
Construction-time setup validation
internal/ingestion/component/parser.go, internal/ingestion/component/parser_check_test.go
NewParserComponent runs Check() to validate PDF and image setup fields; tests cover valid, invalid, empty, and intentionally skipped VLM cases. The audio default output format changes to JSON.
Media family dispatch correction
internal/ingestion/component/parser_dispatch.go, internal/ingestion/component/parser_dispatch_test.go
Media extension normalization recognizes additional aliases, maps image types to image, and tests visual and aural setup dispatch.

No-CGO parser context propagation

Layer / File(s) Summary
PDF parser context propagation
internal/parser/parser/pdf_parser_nocgo.go, internal/parser/parser/pdf_parser_nocgo_test.go
PDFParser.ParseWithResult accepts context and forwards it to context-aware parsing backends; tests use the updated signature.
Office parser context signatures
internal/parser/parser/office_parsers_no_cgo.go, internal/parser/parser/office_parsers_nocgo_test.go
No-CGO office parser methods accept context values, and their tests pass background contexts.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers: euvre

Poem

A bunny checks each parser gate,
While images find their proper state.
PDFs carry context through,
Office parsers do it too.
JSON drums for audio bright—
Hop, the dispatch paths are right!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: parser parameter checks and family-mapping fixes.
Description check ✅ Passed The description includes a clear Summary and detailed sections covering validation, mapping fixes, context threading, tests, and compatibility.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@xugangqiang xugangqiang added the ci Continue Integration label Jul 23, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
internal/ingestion/component/parser.go (1)

133-176: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Check() is bypassed when params == nil.

The pre-existing early return at Lines 136-138 short-circuits before the new pc.Check() call at Lines 172-174, so NewParserComponent(nil) never validates the shipped defaults. It's harmless today only because defaultSetups()/schema.ParserParam{}.Defaults() happen to be valid, but it silently defeats the doc comment's promise that validation "runs at construction time," and TestParserComponent_New_RunsCheck's NewParserComponent(nil) case gives false confidence — it isn't actually exercising Check() against the defaults it claims to validate.

🛡️ Proposed fix — always run Check(), even for nil params
 func NewParserComponent(params map[string]any) (runtime.Component, error) {
 	p := schema.ParserParam{}.Defaults()
 	s := defaultSetups()
-	if params == nil {
-		return &ParserComponent{Setups: s, Param: p}, nil
-	}
-	for k, raw := range params {
-		if k == "outputs" {
-			continue
-		}
-		ftCfg, ok := raw.(map[string]any)
-		if !ok {
-			continue
-		}
-		if _, exists := s[k]; !exists {
-			s[k] = schema.ParserSetup{}
-		}
-		for fk, fv := range ftCfg {
-			s[k][fk] = fv
-		}
-	}
-	if rawAllowed, ok := params["allowed_output_format"].(map[string]any); ok {
-		...
+	if params != nil {
+		for k, raw := range params {
+			if k == "outputs" {
+				continue
+			}
+			ftCfg, ok := raw.(map[string]any)
+			if !ok {
+				continue
+			}
+			if _, exists := s[k]; !exists {
+				s[k] = schema.ParserSetup{}
+			}
+			for fk, fv := range ftCfg {
+				s[k][fk] = fv
+			}
+		}
+		if rawAllowed, ok := params["allowed_output_format"].(map[string]any); ok {
+			...
+		}
 	}
 	pc := &ParserComponent{Setups: s, Param: p}
 	if err := pc.Check(); err != nil {
 		return nil, fmt.Errorf("Parser: %w", err)
 	}
 	return pc, nil
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/ingestion/component/parser.go` around lines 133 - 176, Remove the
early return for nil params in NewParserComponent so nil input follows the same
construction and validation path as other inputs. Preserve the default p and s
initialization, build ParserComponent, and always invoke pc.Check() before
returning it, including when params is nil.
internal/ingestion/component/parser_dispatch.go (1)

282-320: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Remove the legacy "picture"/"visual" branches from familyToExt.

pythonFamilyName now normalizes image families to "image", so familyToExt(pythonFamilyName(...)) cannot hit those branches.

♻️ Proposed cleanup
-	case "picture", "image", "visual":
+	case "image":
 		return utility.FileTypeVISUAL
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/ingestion/component/parser_dispatch.go` around lines 282 - 320,
Remove the legacy "picture" and "visual" cases from familyToExt, since
pythonFamilyName now normalizes both image families to "image". Leave the
existing "image" mapping and all other family mappings unchanged.

Source: Coding guidelines

🧹 Nitpick comments (2)
internal/ingestion/component/parser_dispatch_test.go (1)

852-898: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Consider asserting the actual default value is whitelisted, not just key presence.

This test confirms AllowedOutputFormat[got] exists but doesn't assert that the family's actual default output_format (e.g. "json" for audio) is a member of that list. Strengthening this would directly close the open verification on whether "json" is permitted for audio (see parser.go audio default change).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/ingestion/component/parser_dispatch_test.go` around lines 852 - 898,
Strengthen TestPythonFamilyName_FileTypeConstants by asserting that each
family's configured default output_format is included in its AllowedOutputFormat
whitelist, rather than only checking key presence. Reuse the corresponding
defaults from defaultSetups() and the allowed values from
schema.ParserParam{}.Defaults(), including validation that the audio default
such as "json" is permitted.
internal/ingestion/component/parser.go (1)

225-235: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Replace containsString with slices.Contains.

Go 1.26 supports slices.Contains, so this helper can be removed and the whitelist membership checks can use the stdlib implementation directly.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/ingestion/component/parser.go` around lines 225 - 235, Remove the
local containsString helper and replace each whitelist membership check in
Check() with the standard library slices.Contains call. Add the required slices
import, preserving the existing list and value arguments and behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@internal/ingestion/component/parser_dispatch.go`:
- Around line 282-320: Remove the legacy "picture" and "visual" cases from
familyToExt, since pythonFamilyName now normalizes both image families to
"image". Leave the existing "image" mapping and all other family mappings
unchanged.

In `@internal/ingestion/component/parser.go`:
- Around line 133-176: Remove the early return for nil params in
NewParserComponent so nil input follows the same construction and validation
path as other inputs. Preserve the default p and s initialization, build
ParserComponent, and always invoke pc.Check() before returning it, including
when params is nil.

---

Nitpick comments:
In `@internal/ingestion/component/parser_dispatch_test.go`:
- Around line 852-898: Strengthen TestPythonFamilyName_FileTypeConstants by
asserting that each family's configured default output_format is included in its
AllowedOutputFormat whitelist, rather than only checking key presence. Reuse the
corresponding defaults from defaultSetups() and the allowed values from
schema.ParserParam{}.Defaults(), including validation that the audio default
such as "json" is permitted.

In `@internal/ingestion/component/parser.go`:
- Around line 225-235: Remove the local containsString helper and replace each
whitelist membership check in Check() with the standard library slices.Contains
call. Add the required slices import, preserving the existing list and value
arguments and behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b7d38fe9-224d-42ce-ad7c-3df815e7ad76

📥 Commits

Reviewing files that changed from the base of the PR and between 4dfa5b1 and 47c51e1.

📒 Files selected for processing (8)
  • internal/ingestion/component/parser.go
  • internal/ingestion/component/parser_check_test.go
  • internal/ingestion/component/parser_dispatch.go
  • internal/ingestion/component/parser_dispatch_test.go
  • internal/parser/parser/office_parsers_no_cgo.go
  • internal/parser/parser/office_parsers_nocgo_test.go
  • internal/parser/parser/pdf_parser_nocgo.go
  • internal/parser/parser/pdf_parser_nocgo_test.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants