Repository navigation
Fix(go): align ingestion pipeline with Python (parser/media dispatch + PDF coordinate chain + Chunker) - #17349
Conversation
📝 WalkthroughWalkthroughThe PR standardizes media JSON output, expands vision enrichment, updates parser inputs and method recognition, preserves PDF coordinates and outlines through chunking, carries QA metadata, renders positioned text previews, normalizes text inputs, and isolates pipeline integration tests. ChangesMedia vision output contracts
Parser input and method handling
Text normalization and embedding inputs
PDF chunk metadata and heading detection
Isolated pipeline validation
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant ParserComponent
participant MediaDispatch
participant DOCXVision
participant VisionModel
participant Chunker
participant TextPreviewRenderer
ParserComponent->>MediaDispatch: dispatch image or audio
MediaDispatch-->>ParserComponent: return structured JSON or text output
ParserComponent->>DOCXVision: provide DOCX JSON items
DOCXVision->>VisionModel: send eligible image or table data URI
VisionModel-->>DOCXVision: return description
DOCXVision-->>ParserComponent: append description to item text
ParserComponent->>Chunker: provide positioned records
Chunker->>TextPreviewRenderer: render positioned text preview
TextPreviewRenderer-->>Chunker: return preview image
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
internal/ingestion/component/extractor.go (1)
172-178: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove migration-history references from Go comments.
These comments repeat Python source paths, migration identifiers, or template-history rationale. Keep each comment concise and limited to the current Go input or dispatch contract.
internal/ingestion/component/extractor.go#L172-L178: document that non-empty string-formpromptsis accepted.internal/ingestion/component/extractor_test.go#L573-L578: describe the string-form prompt test without Python/source-history details.internal/ingestion/component/extractor_test.go#L595-L598: describe prompt precedence without migration context.internal/ingestion/component/pdf_vision_dispatch_test.go#L20-L30: describe whitelist alignment without “Diff 2.10” or Python-validation history.internal/ingestion/component/pdf_vision_dispatch_test.go#L63-L67: describe layout suffix behavior without migration rationale.As per coding guidelines, Go comments should describe the current runtime path rather than migration history.
🤖 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/extractor.go` around lines 172 - 178, Remove migration-history and Python/source-path references from comments at internal/ingestion/component/extractor.go:172-178, internal/ingestion/component/extractor_test.go:573-578, and internal/ingestion/component/extractor_test.go:595-598; describe respectively non-empty string-form prompts, the string-form prompt test, and prompt precedence using current Go behavior. Update comments at internal/ingestion/component/pdf_vision_dispatch_test.go:20-30 and :63-67 to describe whitelist alignment and layout-suffix behavior without migration rationale, preserving all runtime and test logic.Source: Coding guidelines
internal/ingestion/component/tokenizer.go (1)
437-440: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove migration-history references from the changed Go comments.
The implementation and tests are correct; the shared issue is that the added comments cite Python files and line numbers instead of documenting the current Go contract.
internal/ingestion/component/tokenizer.go#L437-L440: describe blank-name validation and raw title embedding directly in Go terms.internal/ingestion/component/tokenizer_test.go#L594-L598: explain the raw-name expectation without Python source locations.internal/ingestion/component/tokenizer_test.go#L613-L614: state that surrounding whitespace must be preserved without the Python reference.internal/utility/split.go#L30-L34: retain theTrimSpace/nil semantics and remove thetask_executorreference.internal/utility/split_test.go#L55-L58: describe whitespace-only filtering locally.As per coding guidelines, Go comments should remain aligned with the current runtime path rather than migration history.
🤖 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/tokenizer.go` around lines 437 - 440, Remove migration-history references from comments at internal/ingestion/component/tokenizer.go#L437-L440, internal/ingestion/component/tokenizer_test.go#L594-L598, and internal/ingestion/component/tokenizer_test.go#L613-L614; describe blank-name validation, raw title embedding, and preservation of surrounding whitespace using current Go behavior. Update comments at internal/utility/split.go#L30-L34 to retain TrimSpace/nil semantics without mentioning task_executor, and at internal/utility/split_test.go#L55-L58 to describe whitespace-only filtering locally; do not change implementation or tests.Source: Coding guidelines
🤖 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.
Inline comments:
In `@internal/ingestion/component/pdf_vision_dispatch.go`:
- Around line 361-389: Update isNamedPDFParseMethod to recognize only the plain
PDF parser names accepted by ParserComponent.Check(), removing the `@mineru`,
`@paddleocr`, `@somark`, and `@opendataloader` suffix matching. Preserve suffix
handling for layout_recognizer through a separate classifier or caller-specific
logic, and add regression coverage confirming foo@mineru remains a VLM
parse_method while valid plain names remain recognized.
---
Nitpick comments:
In `@internal/ingestion/component/extractor.go`:
- Around line 172-178: Remove migration-history and Python/source-path
references from comments at internal/ingestion/component/extractor.go:172-178,
internal/ingestion/component/extractor_test.go:573-578, and
internal/ingestion/component/extractor_test.go:595-598; describe respectively
non-empty string-form prompts, the string-form prompt test, and prompt
precedence using current Go behavior. Update comments at
internal/ingestion/component/pdf_vision_dispatch_test.go:20-30 and :63-67 to
describe whitelist alignment and layout-suffix behavior without migration
rationale, preserving all runtime and test logic.
In `@internal/ingestion/component/tokenizer.go`:
- Around line 437-440: Remove migration-history references from comments at
internal/ingestion/component/tokenizer.go#L437-L440,
internal/ingestion/component/tokenizer_test.go#L594-L598, and
internal/ingestion/component/tokenizer_test.go#L613-L614; describe blank-name
validation, raw title embedding, and preservation of surrounding whitespace
using current Go behavior. Update comments at internal/utility/split.go#L30-L34
to retain TrimSpace/nil semantics without mentioning task_executor, and at
internal/utility/split_test.go#L55-L58 to describe whitespace-only filtering
locally; do not change implementation or tests.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ec3ab3ab-8b8c-496d-aeaf-83af32b97113
📒 Files selected for processing (15)
internal/ingestion/component/docx_vision_dispatch.gointernal/ingestion/component/docx_vision_dispatch_test.gointernal/ingestion/component/extractor.gointernal/ingestion/component/extractor_test.gointernal/ingestion/component/markdown_vision_dispatch.gointernal/ingestion/component/media_dispatch.gointernal/ingestion/component/media_dispatch_test.gointernal/ingestion/component/parser.gointernal/ingestion/component/pdf_vision_dispatch.gointernal/ingestion/component/pdf_vision_dispatch_test.gointernal/ingestion/component/tokenizer.gointernal/ingestion/component/tokenizer_test.gointernal/ingestion/pipeline/template/ingestion_pipeline_picture.jsoninternal/utility/split.gointernal/utility/split_test.go
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (2)
internal/ingestion/component/chunker/pdfcrop_cgo.go (1)
144-156: 🚀 Performance & Scalability | 🔵 TrivialPreview rendering now runs per positioned text chunk — consider the throughput impact on large PDFs.
Extending
needsCropto"text"means every text chunk carrying PDF positions now goes throughCropSectionPositions(crop + base64 PNG encode) incropImageChunks, not just image/table chunks. For large documents this can be the majority of chunks (most paragraphs), multiplying per-chunk image encoding work. Page renders are already cached (pageCache), which helps, but the crop+encode step itself still runs once per chunk. Worth keeping an eye on ingestion latency/memory for large PDFs with dense positions, since this is a new cost surface introduced for parity with the Python behavior.🤖 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/chunker/pdfcrop_cgo.go` around lines 144 - 156, The updated needsCrop function now sends every positioned text chunk through expensive crop and PNG encoding. Review the cropImageChunks flow and preserve text preview parity while reducing redundant per-chunk rendering or encoding work, using the existing pageCache and relevant crop helpers where possible; ensure image/table cropping behavior remains unchanged.internal/ingestion/component/chunker/title.go (1)
398-431: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valueSentinel
matched == 0conflates "no match" with a legitimatelevel 0outline entry that resolves tolevel+1 == 0.
matchedis used as both the "no match found" sentinel and the computed level; ifo.levelwere-1(not the typical 0-based PDF outline depth, but not impossible for defensively-parsed data),matched = o.level + 1 == 0would be silently treated as "unmatched" and demoted tobodyLevelinstead of the intended level. Consider amatched boolalongside the level, or offsetting the sentinel (e.g.matched := -1).🛡️ Proposed defensive fix
- matched := 0 + matched := -1 for _, o := range outline { if outlineSimilarity(o.title, rec.text) > 0.8 { matched = o.level + 1 break } } - if matched == 0 { + if matched < 0 { levels[i] = bodyLevel } else { levels[i] = matched }🤖 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/chunker/title.go` around lines 398 - 431, Update resolveOutlineLevels so match detection is independent from the computed level: track whether an outline entry matched separately from matched’s level value, or use a sentinel that cannot collide with valid levels such as zero. Preserve the intended resolved level, including when o.level + 1 equals zero, and only assign bodyLevel when no outline entry matches.
🤖 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.
Inline comments:
In `@internal/ingestion/component/chunker/title_test.go`:
- Around line 445-469: Update TestOutlineFromInputs so the outline entries use
float64 values for their level fields, matching JSON-decoded map[string]any data
and exercising anyToInt’s float64 branch. Preserve the existing assertions and
missing-input fallback coverage.
In `@internal/ingestion/task/pipeline_real_integration_test.go`:
- Around line 140-142: Update the setup comment for the integration test to
describe the temporary on-disk SQLite database accurately, remove the obsolete
comparison to external MySQL/MinIO/ES services, and retain only the current
runtime details, including the in-memory storage backend and WithInsertFunc
chunk capture.
- Around line 257-259: Update the content_with_weight assertion in the
integration test to require a string value and reject nil, empty, or non-string
values. Preserve the existing per-chunk failure reporting while validating the
field’s type before checking that its string content is non-empty.
- Around line 412-439: Update the test cleanup registered after SQLite setup to
obtain the underlying *sql.DB from db and close the connection pool before
removing the temporary database file. Preserve the existing cleanup removal
behavior and handle any db.DB error consistently with the surrounding setup.
---
Nitpick comments:
In `@internal/ingestion/component/chunker/pdfcrop_cgo.go`:
- Around line 144-156: The updated needsCrop function now sends every positioned
text chunk through expensive crop and PNG encoding. Review the cropImageChunks
flow and preserve text preview parity while reducing redundant per-chunk
rendering or encoding work, using the existing pageCache and relevant crop
helpers where possible; ensure image/table cropping behavior remains unchanged.
In `@internal/ingestion/component/chunker/title.go`:
- Around line 398-431: Update resolveOutlineLevels so match detection is
independent from the computed level: track whether an outline entry matched
separately from matched’s level value, or use a sentinel that cannot collide
with valid levels such as zero. Preserve the intended resolved level, including
when o.level + 1 equals zero, and only assign bodyLevel when no outline entry
matches.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 8849588a-8def-48c6-b687-5d225788f659
📒 Files selected for processing (11)
internal/ingestion/component/chunker/group.gointernal/ingestion/component/chunker/group_test.gointernal/ingestion/component/chunker/hierarchy.gointernal/ingestion/component/chunker/pdfcrop_cgo.gointernal/ingestion/component/chunker/pdfcrop_cgo_test.gointernal/ingestion/component/chunker/title.gointernal/ingestion/component/chunker/title_test.gointernal/ingestion/component/chunker/token.gointernal/ingestion/component/chunker/token_pdfpos_test.gointernal/ingestion/component/tokenizer_unit_test.gointernal/ingestion/task/pipeline_real_integration_test.go
| // Loads service config (server.Init side effect) without requiring any | ||
| // external MySQL/MinIO/ES. The pipeline runs against an in-memory sqlite | ||
| // DB and an in-memory storage backend; chunks are captured via WithInsertFunc. |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the isolated-database comment.
The test uses a temporary on-disk SQLite file, not an in-memory database. Remove the obsolete external-service comparison while correcting the description. As per coding guidelines, keep documentation comments aligned with the current runtime path rather than migration history.
Proposed fix
- // Loads service config (server.Init side effect) without requiring any
- // external MySQL/MinIO/ES. The pipeline runs against an in-memory sqlite
- // DB and an in-memory storage backend; chunks are captured via WithInsertFunc.
+ // Loads service configuration for this isolated pipeline test. The pipeline
+ // uses a temporary on-disk SQLite database and in-memory storage; chunks are
+ // captured via WithInsertFunc.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Loads service config (server.Init side effect) without requiring any | |
| // external MySQL/MinIO/ES. The pipeline runs against an in-memory sqlite | |
| // DB and an in-memory storage backend; chunks are captured via WithInsertFunc. | |
| // Loads service configuration for this isolated pipeline test. The pipeline | |
| // uses a temporary on-disk SQLite database and in-memory storage; chunks are | |
| // captured via WithInsertFunc. |
🤖 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/task/pipeline_real_integration_test.go` around lines 140 -
142, Update the setup comment for the integration test to describe the temporary
on-disk SQLite database accurately, remove the obsolete comparison to external
MySQL/MinIO/ES services, and retain only the current runtime details, including
the in-memory storage backend and WithInsertFunc chunk capture.
Source: Coding guidelines
| if got := chunk["content_with_weight"]; got == nil || got == "" { | ||
| t.Fatalf("result chunk[%d].content_with_weight = %v, want non-empty", i, got) | ||
| t.Fatalf("chunk[%d].content_with_weight = %v, want non-empty", i, got) | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== locate file =="
git ls-files | grep -F 'internal/ingestion/task/pipeline_real_integration_test.go' || true
echo "== relevant test section =="
if [ -f internal/ingestion/task/pipeline_real_integration_test.go ]; then
sed -n '230,285p' internal/ingestion/task/pipeline_real_integration_test.go | cat -n
fi
echo "== search content_with_weight producers/uses =="
rg -n "content_with_weight" internal/ingestion -C 3 || true
echo "== file size/stat =="
wc -l internal/ingestion/task/pipeline_real_integration_test.go 2>/dev/null || trueRepository: infiniflow/ragflow
Length of output: 40909
Assert the required string type for content_with_weight.
content_with_weight is consumed as a string by downstream chunking/extractor code, so this test should reject non-string non-empty values.
Proposed fix
- if got := chunk["content_with_weight"]; got == nil || got == "" {
- t.Fatalf("chunk[%d].content_with_weight = %v, want non-empty", i, got)
+ if got, ok := chunk["content_with_weight"].(string); !ok || got == "" {
+ t.Fatalf("chunk[%d].content_with_weight = %T/%v, want non-empty string", i, chunk["content_with_weight"], chunk["content_with_weight"])
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if got := chunk["content_with_weight"]; got == nil || got == "" { | |
| t.Fatalf("result chunk[%d].content_with_weight = %v, want non-empty", i, got) | |
| t.Fatalf("chunk[%d].content_with_weight = %v, want non-empty", i, got) | |
| } | |
| if got, ok := chunk["content_with_weight"].(string); !ok || got == "" { | |
| t.Fatalf("chunk[%d].content_with_weight = %T/%v, want non-empty string", i, chunk["content_with_weight"], chunk["content_with_weight"]) | |
| } |
🤖 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/task/pipeline_real_integration_test.go` around lines 257 -
259, Update the content_with_weight assertion in the integration test to require
a string value and reject nil, empty, or non-string values. Preserve the
existing per-chunk failure reporting while validating the field’s type before
checking that its string content is non-empty.
Source: Coding guidelines
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/ingestion/component/pdf_vision_dispatch.go (1)
373-385: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winAlign PDF method normalization across validation, dispatch, and tests.
ParserComponent.Check()andresolvePDFVisionModelIDnormalize whitespace differently, so padded canonical methods can take inconsistent paths.
internal/ingestion/component/pdf_vision_dispatch.go#L373-L385: use one shared normalization rule or reject surrounding whitespace consistently.internal/ingestion/component/pdf_vision_dispatch_test.go#L31-L61: add padded-value cases covering the selected contract.🤖 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/pdf_vision_dispatch.go` around lines 373 - 385, The PDF parse-method handling uses inconsistent whitespace normalization between validation and dispatch. Align isNamedPDFParseMethod and resolvePDFVisionModelID with ParserComponent.Check by choosing one shared normalization/rejection contract, then apply it consistently to canonical method values without treating “@”-suffixed selectors as parse methods. In internal/ingestion/component/pdf_vision_dispatch_test.go lines 31-61, add padded-value cases that verify the selected contract across validation and dispatch.
🧹 Nitpick comments (1)
internal/ingestion/component/chunker/token.go (1)
288-292: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove migration-history commentary from Go source and tests.
Keep concise comments describing current behavior; remove
diff, “legacy,” and Python-migration narratives.
internal/ingestion/component/chunker/token.go#L288-L292: describe the active sentence-boundary behavior only.internal/ingestion/component/chunker/token_batch1_test.go#L27-L32: describe the tested delimiter behavior only.internal/ingestion/component/chunker/qa.go#L102-L104: describe the explicit language behavior only.internal/ingestion/component/chunker/qa_batch2_test.go#L44-L46: describe the default-output contract only.internal/ingestion/component/chunker/qa_test.go#L215-L216: describe valid space-separated prefixes only.As per coding guidelines, keep Go documentation aligned with the current runtime path rather than migration history and remove stale documentation.
🤖 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/chunker/token.go` around lines 288 - 292, Remove migration-history, “diff,” legacy, and Python-migration commentary from the identified comments. In token.go, document only the active sentence-boundary behavior; in token_batch1_test.go, describe the tested delimiter behavior; in qa.go, describe the explicit language behavior; in qa_batch2_test.go, describe the default-output contract; and in qa_test.go, describe valid space-separated prefixes. Update comments only, preserving runtime code and tests.Source: Coding guidelines
🤖 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.
Inline comments:
In `@internal/ingestion/component/pdf_vision_dispatch.go`:
- Around line 373-377: Update the comments around the named-method
classification in internal/ingestion/component/pdf_vision_dispatch.go:373-377 to
state that `@-suffixed` values are excluded from parse_method classification and
that layout_recognizer uses dedicated MinerU handling. In
internal/ingestion/component/pdf_vision_dispatch_test.go:63-68, remove the claim
that all suffixes fall through to generic VLM dispatch; document the
field-specific dispatch behavior instead.
---
Outside diff comments:
In `@internal/ingestion/component/pdf_vision_dispatch.go`:
- Around line 373-385: The PDF parse-method handling uses inconsistent
whitespace normalization between validation and dispatch. Align
isNamedPDFParseMethod and resolvePDFVisionModelID with ParserComponent.Check by
choosing one shared normalization/rejection contract, then apply it consistently
to canonical method values without treating “@”-suffixed selectors as parse
methods. In internal/ingestion/component/pdf_vision_dispatch_test.go lines
31-61, add padded-value cases that verify the selected contract across
validation and dispatch.
---
Nitpick comments:
In `@internal/ingestion/component/chunker/token.go`:
- Around line 288-292: Remove migration-history, “diff,” legacy, and
Python-migration commentary from the identified comments. In token.go, document
only the active sentence-boundary behavior; in token_batch1_test.go, describe
the tested delimiter behavior; in qa.go, describe the explicit language
behavior; in qa_batch2_test.go, describe the default-output contract; and in
qa_test.go, describe valid space-separated prefixes. Update comments only,
preserving runtime code and tests.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 93d7d3bd-7c29-481e-a434-1b1c4e3e1873
📒 Files selected for processing (10)
internal/ingestion/component/chunker/qa.gointernal/ingestion/component/chunker/qa_batch2_test.gointernal/ingestion/component/chunker/qa_test.gointernal/ingestion/component/chunker/title_test.gointernal/ingestion/component/chunker/token.gointernal/ingestion/component/chunker/token_batch1_test.gointernal/ingestion/component/pdf_vision_dispatch.gointernal/ingestion/component/pdf_vision_dispatch_test.gointernal/ingestion/component/schema/chunk_types.gointernal/ingestion/task/pipeline_real_integration_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
- internal/ingestion/component/chunker/title_test.go
- internal/ingestion/task/pipeline_real_integration_test.go
| // Note: "@"-suffixed spellings such as "foo@mineru" are layout_recognizer | ||
| // selectors, not parse_method values. Check() rejects them as parse_method, | ||
| // and the MinerU layout branch is resolved from the layout_recognizer field | ||
| // separately (pdf_vision_dispatch.go:62-68), so they must NOT be recognized | ||
| // here. |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Document @... handling by field and dispatch path.
The comments conflate layout selectors with custom parse_method VLM values and incorrectly imply that @mineru follows generic VLM handling.
internal/ingestion/component/pdf_vision_dispatch.go#L373-L377: explain that suffixes are excluded from named-method classification, whilelayout_recognizerhas dedicated MinerU handling.internal/ingestion/component/pdf_vision_dispatch_test.go#L63-L68: remove the claim that every suffix falls through to generic VLM dispatch.
As per coding guidelines, keep Go documentation comments aligned with the current runtime path.
📍 Affects 2 files
internal/ingestion/component/pdf_vision_dispatch.go#L373-L377(this comment)internal/ingestion/component/pdf_vision_dispatch_test.go#L63-L68
🤖 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/pdf_vision_dispatch.go` around lines 373 - 377,
Update the comments around the named-method classification in
internal/ingestion/component/pdf_vision_dispatch.go:373-377 to state that
`@-suffixed` values are excluded from parse_method classification and that
layout_recognizer uses dedicated MinerU handling. In
internal/ingestion/component/pdf_vision_dispatch_test.go:63-68, remove the claim
that all suffixes fall through to generic VLM dispatch; document the
field-specific dispatch behavior instead.
Source: Coding guidelines
|
@yingfeng @JinHai-CN @yuzhichang Please help to review |
Summary
Aligns the Go ingestion pipeline with the Python implementation, closing several behavioral gaps found during the Python→Go migration (tracked in
docs/migration_python_go_diff.md). Covers parser/media dispatch alignment, the PDF coordinate-chain (preview images, outline→title, chunk coordinate finalization), and the Chunker Token/QA batches below.Commits are grouped as follows.
1. Fix parser params (c524f45)
Fixes parser/media wiring and several dispatch gaps:
doc_type_kwdistable, not onlyimage(parser/utils.py:181).output_formatisjson, carry the ASR transcription as a JSON item instead of only theTextfield (the Invoke switch had nojsonbranch and dropped it).output_formatisjson(parser.py:212), nottext.2. fix parser gap (373537d)
Image dispatch now mirrors
rag/app/picture.py:chunk():describe) and combineOCR + VLMtext.doc_type_kwd:"image", instead of a bareTextstring. This fixes the payload being rejected downstream by OneChunker/TokenChunker (JSON=nil).3. PDF coordinate-chain fixes (55367a8, 727f816)
Closes three items from the migration tracker in the chunker/tokenizer/task layer:
(Chunker-1.3)
restore_pdf_text_previews—needsCropnow also returns true fortextchunks that carry PDF positions (pdfcrop_cgo.go), so text blocks get a rendered preview image uploaded to storage viaimageUploadDecorator/ChunkImageUploader, matching Pythonrestore_pdf_text_previews+image2id.(Chunker-1.5) PDF outline → title levels —
title.goaddsoutlineSimilarity(rune-bigram Jaccard, mirroringcommon.py:_outline_similarity),resolveOutlineLevels(matches text lines to outline entries at similarity > 0.8, with a sparse guardlen(outline)/len(records) <= 0.03), andoutlineFromInputs(readsfile.outline). Wired intonewLevelContextin bothgroup.goandhierarchy.go; falls back to the title-shape heuristic when no outline is present.(Tokenizer-(T)1)
finalize_pdf_chunk— the coordinate →position_int/page_num_int/top_intconversion is owned by the task layer (processChunkPositions→AddPositions), which runs after the tokenizer and consumes the tokenizer-owned fields. The tokenizer only preserves the rawpositions/_pdf_positions(no duplicate conversion), pinned byTestChunkDocsToMaps_PreservesPDFPositions.4. Integration test made environment-free (
internal/ingestion/task/pipeline_real_integration_test.go)//go:build integrationtag so the contract tests run under the defaultbuild.sh --test(which does not pass-tags integration).glebarez/sqlite) with the needed tables auto-migrated.storage.NewMemoryStorage().WithInsertFuncinstead ofengine.InsertChunks/Search.requireTokenizerPoolstill skips gracefully when the native tokenizer pool is unavailable;WithLogCreateFunc(noop)avoids depending on the operation-log table.taskChunkFieldEqualsStrto toleratekb_idbeing a[]string/[]anyin the raw chunk payload (the search engine flattens it to a string on read).5. TokenChunker alignment — Batch 1 (
internal/ingestion/component/chunker/token.go)Closes four Chunker items from the migration tracker:
!/?. Extracted to a package-levelvar sentenceDelimiterand used inmergeByTokenSize, matching Python's full delimiter set.removeTag, in both the text path (mergeByTokenSize) and the JSON path (mergeByTokenSizeFromJSON). Parser tags (@@…##) no longer leak into the overlap region (mirrorsnlp/__init__.py:1181).mergeByTokenSizeFromJSON), mirroringtoken_chunker.py:236-239.takeFromEnd/takeFromStartnow count tokens exactly viatokenizeStrinstead of the 4-bytes/token heuristic, fixing over-counting for CJK text.6. QA Chunker alignment — Batch 2 (
internal/ingestion/component/chunker/qa.go+schema)Closes three Chunker items from the migration tracker:
langnow defaults to Chinese prefixes (问题:/回答:) instead of English, matchingqa.py:299.rmQAPrefixregex — the separator is changed to[\t:: ]+(one-or-more), matchingqa.py:241, so multiple separators (e.g.Q:: answer) are fully stripped.top_int— the source row/record index, threaded through the tab/csv/markdown extractors (mirrorsqa.pybeAdoc(..., row_num=i));image+doc_type_kwd:"image";_pdf_positions/positionscarried from the upstream JSON item.schema.ChunkDocgains aTopInt []intfield (serialized astop_int, registered inUnmarshalJSON). Note: the Tag/Table/Presentation/One chunker field gaps under 1.8 remain pending.Test plan
pdfcrop_cgo_test.go(TestNeedsCrop,TestRestorePDFTextPreview),title_test.go(TestResolveOutlineLevels,TestResolveOutlineLevels_SparseGuard,TestNewLevelContext_OutlineBranch,TestOutlineFromInputs),tokenizer_unit_test.go(TestChunkDocsToMaps_PreservesPDFPositions),token_pdfpos_test.go.token_batch1_test.go:TestSentenceDelimiterMatchesBangAndQuestion,TestMergeByTokenSizeFromJSON_OverlapStripsTags,TestMergeByTokenSizeFromJSON_EmptyPrevKeepsChunk,TestTakeFromEndRespectsTokenCount,TestTakeFromStartRespectsTokenCount.qa_batch2_test.go:TestQAChunker_DefaultLangIsChinese,TestRmQAPrefixStripsMultipleSeparators,TestQAChunker_SetsTopInt,TestQAChunker_CarriesImageAndPositions. Existingqa_test.goexpectations were updated to the corrected language default / separator behavior.pipeline_real_integration_test.go(TestPipelineExecutor_Run_RealCanvasDSL_UsesGeneralPipeline,TestPipelineExecutor_Run_RealPDF_ProducesIndexedChunks,TestRunPipeline_RealPipelineOutput_ProducesIndexFields) now runs without any external service.bash build.sh --test ./internal/ingestion/...passes.