Repository navigation
Feat(ingestion): align image to MinIO upload, unify chunk-id computation and add PPT parsing support - #17111
Conversation
📝 WalkthroughWalkthroughThe 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. ChangesChunk identity and image uploads
Presentation format parsing
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
Possibly related PRs
Suggested labels: 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: 2
🧹 Nitpick comments (1)
internal/ingestion/task/chunk_process_test.go (1)
113-116: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueFix package name typo in the documentation comment.
The comment refers to
component.ChunkID, but the helper function is actually located in thecommonpackage (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
📒 Files selected for processing (11)
internal/common/format.gointernal/common/format_test.gointernal/ingestion/component/chunker/image_upload.gointernal/ingestion/component/chunker/image_upload_test.gointernal/ingestion/component/chunker/register.gointernal/ingestion/component/image_uploader.gointernal/ingestion/task/chunk_builder.gointernal/ingestion/task/chunk_builder_test.gointernal/ingestion/task/chunk_process.gointernal/ingestion/task/chunk_process_test.gointernal/service/chunk/chunk.go
💤 Files with no reviewable changes (2)
- internal/ingestion/task/chunk_builder_test.go
- internal/ingestion/task/chunk_builder.go
|
@yingfeng @JinHai-CN @yuzhichang Please help to review. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/parser/parser/pptx_parser.go (1)
28-35: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider renaming
PPTXParsertoPresentationParser.Since this parser now handles both
.pptxand.pptformats uniformly, the namePPTXParseris slightly misleading. Renaming the struct toPresentationParser(and updating its constructor to something likeNewPresentationParser(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
⛔ Files ignored due to path filters (1)
internal/parser/parser/testdata/sample.pptis excluded by!**/*.ppt
📒 Files selected for processing (3)
internal/parser/parser/ppt_parser.gointernal/parser/parser/ppt_parser_cgo_test.gointernal/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. |
There was a problem hiding this comment.
📐 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
|
LGTM |
Summary
Align the Go ingestion pipeline with Python's
image→img_idpersistence semantics, and unify the chunk-id computation across all paths.Changes
**1. Image upload at chunker stage **
ImageUploadertype andDefaultImageUploaderininternal/ingestion/component/image_uploader.go— the write-side counterpart toFetchBinary, storing raw image bytes at(bucket=kbID, key=chunkID), no re-encoding.uploadOneImage— pure upload primitive (bytes in,img_idout), does not touch chunk maps.uploadChunkImages/uploadChunkImage— caller-side helper: decodesimagefrom a chunk, uploads bytes, writesck["img_id"],delete(ck,"image"), bounded by a process-wide semaphore (default 10, envMAX_CONCURRENT_MINIO).imageUploadDecoratorinregister.go: every chunker runs the upload pass at invocation time, writingck["id"]before upload and dropping image bytes right after — peak memory = single chunk image lifetime.2. Unify chunk-id computation
component.ChunkID,task.ChunkID, inlineFormatUintin API) into one:common.ChunkID(docID, text string), using%016x+xxhash.Sum64String(text+docID)(matching Pythonhexdigest()).ck["id"]viacommon.ChunkID; the persist stage (ProcessChunksForPipeline) falls back to the same function (if !exists id).common.ChunkIDinstead of the divergentFormatUint(xxhash.Sum64(...))— fixing a pre-existing inconsistency.internal/ingestion/component/chunk_id.goandinternal/ingestion/task/chunk_builder.go(both were pure forwarding shells).3. Preserve
img_id(never deleted)img_idis a persistent index field (Infinity, OB) and the only consumer-side reference for image retrieval; it is NEVER removed from the chunk map. Onlyimage(raw data URL) is dropped after upload.4. PPT parser support
Previously PPT parsing failed. Add support to parse.
Key design decisions
minio_limiter), envMAX_CONCURRENT_MINIOimg_idformat"<kb_id>-<chunk_id>"— matches Python task_executor pathcommon.ChunkID(docID, text), concatenationtext+docIDinside hash (matching Python)removeInternalChunkFieldsdelete(ck,"image")as defensive fallback for non-chunker pathsFiles touched
internal/common/format.goChunkID(docID, text)internal/common/format_test.gointernal/ingestion/component/image_uploader.goImageUploadertype +DefaultImageUploaderinternal/ingestion/component/chunker/image_upload.gouploadOneImage,uploadChunkImages,uploadChunkImage,decodeChunkImage, semaphoreinternal/ingestion/component/chunker/image_upload_test.gointernal/ingestion/component/chunker/register.goimageUploadDecorator(writesck["id"], runs upload)internal/ingestion/task/chunk_process.gocommon.ChunkIDfor persist fallbackinternal/service/chunk/chunk.gocommon.ChunkIDinstead ofFormatUintinternal/ingestion/component/chunk_id.gocommon)internal/ingestion/task/chunk_builder.gointernal/ingestion/task/chunk_builder_test.gocommon/format_test.go)Verification