fix: honor parser params and image VLM system_prompt in Go ingestion (#17334)

## Summary
Fix the Go ingestion pipeline so that several parser setup switches and
the
image VLM prompt are actually honored end-to-end (previously the DSL
fields
existed but the Go code never read them).

- **DOCX** (`docx_parser.go`, `docx_postprocess.go`): read `remove_toc`
and
  `remove_header_footer`; apply to both JSON and markdown output paths
  (outline-based TOC removal with a text-heuristic fallback, plus
  header/footer section filtering).
- **HTML** (`html_parser.go`, `html_postprocess.go`, `text_toc.go`):
read
`remove_header_footer` (pre-parse strip of `<header>`/`<footer>` and
ARIA
`banner`/`contentinfo`) and `remove_toc` (post-parse
`remove_contents_table`
  heuristic).
- **Markdown** (`markdown_parser.go`): read `flatten_media_to_text` and
force
  media blocks to text when enabled.
- **Image VLM** (`media_dispatch.go`): read `system_prompt` instead of
`prompt`
  so the user-configured image VLM prompt is no longer silently dropped
  (`prompt` remains the video family key).

All flags are wired through `ConfigureFromSetup`, which the dispatch
layer
already invokes for every family, so the behavior is live rather than
dead code.

## Test plan
- New unit tests: `docx_postprocess_test.go`, `html_parser_test.go`,
`text_toc_test.go`, `markdown_parser_test.go`, `media_dispatch_test.go`.
- `bash build.sh --test ./internal/parser/parser/...
./internal/ingestion/component/...`

## Notes
- The `File` component is excluded from this migration scope.
- Relates to the Python→Go parity diff (Parser 1.8–1.11, 1.15).
This commit is contained in:
Jack
2026-07-24 14:42:26 +08:00
committed by GitHub
parent ff163764b3
commit 0403d19b5a
16 changed files with 1778 additions and 368 deletions

View File

@@ -49,10 +49,11 @@ const GoMarkdown = "go_markdown"
var ssrfAllowLoopback bool
type MarkdownParser struct {
libType string
ParseMethod string
OutputFormat string
VLM map[string]any
libType string
ParseMethod string
OutputFormat string
VLM map[string]any
FlattenMediaToText bool
}
func NewMarkdownParser(libType string) (*MarkdownParser, error) {
@@ -79,6 +80,9 @@ func (p *MarkdownParser) ConfigureFromSetup(setup map[string]any) {
if v, ok := setup["vlm"].(map[string]any); ok {
p.VLM = v
}
if v, ok := setup["flatten_media_to_text"].(bool); ok {
p.FlattenMediaToText = v
}
}
// ParseWithResult implements ParseResultProducer (plan §6.5) and
@@ -94,7 +98,7 @@ func (p *MarkdownParser) ParseWithResult(ctx context.Context, filename string, d
rawText := string(data)
var items []map[string]any
walkMarkdownBlocksWithImages(doc, rawText, &items)
walkMarkdownBlocksWithImages(doc, rawText, &items, p.FlattenMediaToText)
if items == nil {
items = []map[string]any{{"text": "", "doc_type_kwd": "text"}}
}
@@ -123,8 +127,10 @@ func markdownNew() *parser.Parser {
// emitted with their text. When a block contains a markdown image
// reference (![alt](src)), the image data is resolved via
// resolveMarkdownImage and the item carries `doc_type_kwd: "image"`
// together with the base64-encoded image payload.
func walkMarkdownBlocksWithImages(doc ast.Node, rawText string, out *[]map[string]any) {
// together with the base64-encoded image payload. When flatten is
// true, all items are forced to doc_type_kwd="text" (mirrors Python
// parser.py:1034 flatten_media_to_text).
func walkMarkdownBlocksWithImages(doc ast.Node, rawText string, out *[]map[string]any, flatten bool) {
for _, child := range doc.GetChildren() {
var ckType string
var docTypeKwd string
@@ -166,9 +172,13 @@ func walkMarkdownBlocksWithImages(doc ast.Node, rawText string, out *[]map[strin
// Detect markdown image references in the raw source text
// that corresponds to this block. When found, resolve the
// image data so downstream vision enhancement can describe it.
// When flatten is true, keep doc_type_kwd="text" (Python
// parser.py:1034: flatten_media_to_text overrides image).
if imgData, imgFound := resolveMarkdownImage(txt, rawText); imgFound && imgData != "" {
item["doc_type_kwd"] = "image"
item["image"] = imgData
if !flatten {
item["doc_type_kwd"] = "image"
}
}
*out = append(*out, item)