Skip to content

Feat(ingestion): align image to MinIO upload, unify chunk-id computation and add PPT parsing support - #17111

Merged
yuzhichang merged 4 commits into
infiniflow:mainfrom
xugangqiang:feat/chunker-image
Jul 20, 2026
Merged

yuzhichang merged 4 commits into
infiniflow:mainfrom
xugangqiang:feat/chunker-image

Conversation

@xugangqiang

@xugangqiang xugangqiang commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Align the Go ingestion pipeline with Python's image → img_id persistence semantics, and unify the chunk-id computation across all paths.

Changes

**1. Image upload at chunker stage **

  • Add ImageUploader type and DefaultImageUploader in internal/ingestion/component/image_uploader.go — the write-side counterpart to FetchBinary, storing raw image bytes at (bucket=kbID, key=chunkID), no re-encoding.
  • Add uploadOneImage — pure upload primitive (bytes in, img_id out), does not touch chunk maps.
  • Add uploadChunkImages / uploadChunkImage — caller-side helper: decodes image from a chunk, uploads bytes, writes ck["img_id"], delete(ck,"image") , bounded by a process-wide semaphore (default 10, env MAX_CONCURRENT_MINIO).
  • Wire via imageUploadDecorator in register.go: every chunker runs the upload pass at invocation time, writing ck["id"] before upload and dropping image bytes right after — peak memory = single chunk image lifetime.

2. Unify chunk-id computation

  • Consolidate three separate id-computation paths (component.ChunkID, task.ChunkID, inline FormatUint in API) into one: common.ChunkID(docID, text string), using %016x + xxhash.Sum64String(text+docID) (matching Python hexdigest()).
  • The chunker decorator writes ck["id"] via common.ChunkID; the persist stage (ProcessChunksForPipeline) falls back to the same function (if !exists id).
  • The API AddChunk path now also calls common.ChunkID instead of the divergent FormatUint(xxhash.Sum64(...)) — fixing a pre-existing inconsistency.
  • Delete internal/ingestion/component/chunk_id.go and internal/ingestion/task/chunk_builder.go (both were pure forwarding shells).

3. Preserve img_id (never deleted)

  • img_id is a persistent index field (Infinity, OB) and the only consumer-side reference for image retrieval; it is NEVER removed from the chunk map. Only image (raw data URL) is dropped after upload.

4. PPT parser support
Previously PPT parsing failed. Add support to parse.

Key design decisions

Decision Choice
Upload timing Chunker stage (not persist), so image bytes are dropped immediately — bounds peak memory to one chunk image
Upload concurrency Process-wide semaphore, default 10 (matches Python minio_limiter), env MAX_CONCURRENT_MINIO
Image encoding Store as-is, no JPEG re-encoding (unlike Python)
img_id format "<kb_id>-<chunk_id>" — matches Python task_executor path
id function Single common.ChunkID(docID, text), concatenation text+docID inside hash (matching Python)
removeInternalChunkFields Retains delete(ck,"image") as defensive fallback for non-chunker paths

Files touched

File Change
internal/common/format.go Add ChunkID(docID, text)
internal/common/format_test.go Add ChunkID golden-value test
internal/ingestion/component/image_uploader.go Add ImageUploader type + DefaultImageUploader
internal/ingestion/component/chunker/image_upload.go Add uploadOneImage, uploadChunkImages, uploadChunkImage, decodeChunkImage, semaphore
internal/ingestion/component/chunker/image_upload_test.go Tests: upload/drop, skip, no-image, concurrency, missing-id error
internal/ingestion/component/chunker/register.go Add imageUploadDecorator (writes ck["id"], runs upload)
internal/ingestion/task/chunk_process.go Use common.ChunkID for persist fallback
internal/service/chunk/chunk.go Use common.ChunkID instead of FormatUint
internal/ingestion/component/chunk_id.go Deleted (moved to common)
internal/ingestion/task/chunk_builder.go Deleted (shell, no callers left)
internal/ingestion/task/chunk_builder_test.go Deleted (test migrated to common/format_test.go)

Verification

bash build.sh --test ./internal/service/chunk/... ./internal/common/... ./internal/ingestion/component/... ./internal/ingestion/task/...
→ ok   service/chunk / common / component / chunker / schema / task

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. ☯️ refactor Pull request that refactor/refine code 💞 feature Feature request, pull request that fullfill a new feature. labels Jul 20, 2026
@xugangqiang xugangqiang added the ci Continue Integration label Jul 20, 2026
@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change centralizes deterministic chunk ID generation, applies it across ingestion and service chunk creation, and adds image persistence for registered chunkers. PPT parsing now uses a format-aware shared parser path with CGO-gated validation.

Changes

Chunk identity and image uploads

Layer / File(s) Summary
Centralized chunk ID contract
internal/common/format.go, internal/common/format_test.go
Adds a fixed-width xxhash-based ChunkID helper with tests for empty inputs and leading-zero preservation.
Image uploader storage contract
internal/ingestion/component/image_uploader.go
Defines the uploader function type and persists image bytes through the registered storage backend.
Chunker image processing
internal/ingestion/component/chunker/image_upload.go, internal/ingestion/component/chunker/image_upload_test.go
Decodes chunk images, limits concurrent uploads, skips existing references, writes img_id, and removes raw image data with unit and concurrency coverage.
Registered chunker integration
internal/ingestion/component/chunker/register.go, internal/ingestion/component/chunker/image_upload_test.go
Decorates registered chunkers to assign chunk IDs, upload images, and propagate upload errors.
Chunk ID consumer migration
internal/ingestion/task/chunk_process.go, internal/ingestion/task/chunk_process_test.go, internal/service/chunk/chunk.go
Switches pipeline and service chunk creation to common.ChunkID; malformed pipeline text now falls back to an empty string instead of returning an error.

Presentation format parsing

Layer / File(s) Summary
Presentation format parameterization
internal/parser/parser/pptx_parser.go, internal/parser/parser/ppt_parser.go
Passes the selected presentation format through PPTXParser and reports it in parse metadata.
Presentation parser validation
internal/parser/parser/ppt_parser_cgo_test.go
Adds CGO-gated validation for PPT and PPTX parsing output, metadata, and generated presentation input.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Chunker
  participant imageUploadDecorator
  participant uploadChunkImages
  participant DefaultImageUploader
  participant StorageBackend
  Chunker->>imageUploadDecorator: Return chunks
  imageUploadDecorator->>imageUploadDecorator: Assign deterministic chunk IDs
  imageUploadDecorator->>uploadChunkImages: Upload decoded image bytes
  uploadChunkImages->>DefaultImageUploader: Pass kbID, chunkID, and bytes
  DefaultImageUploader->>StorageBackend: Put(kbID, chunkID, data)
  StorageBackend-->>DefaultImageUploader: Return storage result
  DefaultImageUploader-->>uploadChunkImages: Return imgID
  uploadChunkImages-->>imageUploadDecorator: Return updated chunks
Loading

Possibly related PRs

Suggested labels: 🧪 test

Suggested reviewers: yingfeng, yuzhichang, jinhai-cn

Poem

A bunny hashes chunks in a row,
Then sends their bright images below.
PPT pages parse right,
IDs shine fixed and bright,
While raw bytes melt into snow.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.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
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.
Title check ✅ Passed The title is specific and accurately summarizes the main changes: image upload, chunk-id unification, and PPT parsing support.
Description check ✅ Passed The PR description matches the template and provides a clear summary, changes, design decisions, files, and verification.

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.

@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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
internal/ingestion/task/chunk_process_test.go (1)

113-116: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Fix package name typo in the documentation comment.

The comment refers to component.ChunkID, but the helper function is actually located in the common package (common.ChunkID).

💡 Proposed fix for the comment typo
 // TestProcessChunksForPipeline_GeneratesIDOnNonStringText pins the id fallback:
 // when ck["id"] is absent and ck["text"] is a non-string (e.g. from a
 // malformed input), the type assertion silently yields "" and
- // component.ChunkID computes a valid id from empty text, rather than erroring.
+ // common.ChunkID computes a valid id from empty text, rather than erroring.
🤖 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/chunk_process_test.go` around lines 113 - 116,
Correct the documentation comment for
TestProcessChunksForPipeline_GeneratesIDOnNonStringText by changing the package
reference from component.ChunkID to common.ChunkID; leave the test behavior and
implementation unchanged.
🤖 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/image_upload.go`:
- Around line 113-117: Update uploadOneImage so acquiring imageUploadSem uses a
select that either sends the semaphore token or returns ctx.Err() when
ctx.Done() is signaled. Keep the existing deferred semaphore release only after
successful acquisition, and preserve the upload call for contexts that obtain a
slot.

In `@internal/ingestion/component/chunker/register.go`:
- Around line 78-81: Update the chunk ID assignment loop in the chunk
registration logic to hash the chunk’s content_with_weight value, falling back
to text when appropriate to preserve compatibility with chunks that only provide
text. Ensure common.ChunkID receives the same content used by the Python
implementation and does not default to an empty string when content_with_weight
is populated.

---

Nitpick comments:
In `@internal/ingestion/task/chunk_process_test.go`:
- Around line 113-116: Correct the documentation comment for
TestProcessChunksForPipeline_GeneratesIDOnNonStringText by changing the package
reference from component.ChunkID to common.ChunkID; leave the test behavior and
implementation unchanged.
🪄 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

Run ID: 2da0f6e6-fb19-4611-9abf-4fbfc6d4a30a

📥 Commits

Reviewing files that changed from the base of the PR and between 3fa8902 and 008f6af.

📒 Files selected for processing (11)
  • internal/common/format.go
  • internal/common/format_test.go
  • internal/ingestion/component/chunker/image_upload.go
  • internal/ingestion/component/chunker/image_upload_test.go
  • internal/ingestion/component/chunker/register.go
  • internal/ingestion/component/image_uploader.go
  • internal/ingestion/task/chunk_builder.go
  • internal/ingestion/task/chunk_builder_test.go
  • internal/ingestion/task/chunk_process.go
  • internal/ingestion/task/chunk_process_test.go
  • internal/service/chunk/chunk.go
💤 Files with no reviewable changes (2)
  • internal/ingestion/task/chunk_builder_test.go
  • internal/ingestion/task/chunk_builder.go

@xugangqiang

Copy link
Copy Markdown
Contributor Author

@yingfeng @JinHai-CN @yuzhichang Please help to review.

@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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/parser/parser/pptx_parser.go (1)

28-35: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider renaming PPTXParser to PresentationParser.

Since this parser now handles both .pptx and .ppt formats uniformly, the name PPTXParser is slightly misleading. Renaming the struct to PresentationParser (and updating its constructor to something like NewPresentationParser(format string)) would better reflect its unified capability.

🤖 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/parser/parser/pptx_parser.go` around lines 28 - 35, Rename the
PPTXParser type to PresentationParser and update its constructor, such as
NewPPTXParser, to a presentation-oriented name like NewPresentationParser(format
string). Update all references, instantiations, and method receivers to use the
new symbols while preserving support for both pptx and ppt formats.
🤖 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/parser/parser/pptx_parser.go`:
- Line 61: Update the comment immediately before the slide parser output
description to remove all references to the Python TxtParser convention and
migration history, including the preceding line, while retaining only the
current RAGFlow slide-parser behavior.

---

Nitpick comments:
In `@internal/parser/parser/pptx_parser.go`:
- Around line 28-35: Rename the PPTXParser type to PresentationParser and update
its constructor, such as NewPPTXParser, to a presentation-oriented name like
NewPresentationParser(format string). Update all references, instantiations, and
method receivers to use the new symbols while preserving support for both pptx
and ppt formats.
🪄 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

Run ID: 5f89e39f-39bd-4c21-8819-9cc1dae8224c

📥 Commits

Reviewing files that changed from the base of the PR and between bc6e2ac and 88a1564.

⛔ Files ignored due to path filters (1)
  • internal/parser/parser/testdata/sample.ppt is excluded by !**/*.ppt
📒 Files selected for processing (3)
  • internal/parser/parser/ppt_parser.go
  • internal/parser/parser/ppt_parser_cgo_test.go
  • internal/parser/parser/pptx_parser.go


// Split on form-feed (the python TxtParser convention used by
// ragflow's slide parser) — each block becomes a JSON item.
// RAGFlow's slide parser) — each block becomes a JSON item.

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.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Remove reference to Python parser history.

As per coding guidelines, documentation comments must align with the current runtime path and omit migration history or compatibility wording. Please remove the reference to the Python TxtParser convention here and in the preceding line.

♻️ Proposed fix
-	// RAGFlow's slide parser) — each block becomes a JSON item.
+	// the slide parser) — each block becomes a JSON item.

(Note: Also adjust the preceding unchanged line to remove (the python TxtParser convention used by)

🤖 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/parser/parser/pptx_parser.go` at line 61, Update the comment
immediately before the slide parser output description to remove all references
to the Python TxtParser convention and migration history, including the
preceding line, while retaining only the current RAGFlow slide-parser behavior.

Source: Coding guidelines

@xugangqiang xugangqiang changed the title feat(ingestion): align image → MinIO upload and unify chunk-id computation Feat(ingestion): align image to MinIO upload, unify chunk-id computation and add PPT parsing support Jul 20, 2026
@yuzhichang

Copy link
Copy Markdown
Member

LGTM

@yuzhichang
yuzhichang merged commit 2f7c2eb into infiniflow:main Jul 20, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. ☯️ refactor Pull request that refactor/refine code 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