Repository navigation
feat(agent): add Pipeline chunker component for pre-chunking workflows (#14773) - #15068
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds a PipelineChunker Agent component that maps parser IDs to rag.app chunkers, validates parameters (including from_page <= to_page), resolves canvas file blobs, invokes chunkers per file with timeout/cancellation, aggregates chunks/chunks_full and a per-file summary, and includes unit tests. ChangesPipelineChunker Agent Component
Sequence DiagramsequenceDiagram
participant Canvas
participant PipelineChunker
participant Loader as _load_chunker
participant Chunker as ChunkerCallable
participant FileService
participant Output
Canvas->>PipelineChunker: canvas file refs + parser_id + params
PipelineChunker->>Loader: resolve parser_id
Loader-->>PipelineChunker: ChunkerCallable (chunk)
loop per file reference
PipelineChunker->>FileService: FileService.get_blob(blob_ref)
FileService-->>PipelineChunker: content_bytes, filename
PipelineChunker->>Chunker: invoke chunk(content_bytes, lang, tenant, page_range, parser_config, log_cb)
Chunker-->>PipelineChunker: list of chunk dicts
end
PipelineChunker->>Output: publish chunks, chunks_full, summary
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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: 3
🤖 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 `@agent/component/pipeline_chunker.py`:
- Around line 124-130: Wrap the FileService.get_blob(...) call in a try/except
inside the file-resolution logic so exceptions from FileService.get_blob don’t
bubble out of _invoke and stop processing remaining files; on exception catch
Exception as e, log the error with context (e.g. which
file_id/created_by/filename) using the component logger and return (None, None)
for that item so per-file failures remain isolated; apply the same change to the
other occurrence noted (lines ~156-160) that also calls FileService.get_blob.
- Around line 84-95: The check() method in PipelineChunker currently does not
reject inverted page ranges, allowing from_page to be greater than to_page;
update PipelineChunker.check to validate that when both from_page and to_page
are not None (or are numeric), from_page <= to_page and raise a ValueError with
a clear message like "[PipelineChunker] from_page must be <= to_page" if the
condition fails; keep existing checks for parser_id, from_page, to_page and
parser_config shape but add this additional validation after the nonnegative
checks and before returning True.
In `@test/unit_test/agent/test_pipeline_chunker.py`:
- Around line 39-65: The test creates module-level stubs in sys.modules
(_file_service_stub and entries for the listed mods) which leak between tests;
modify the test to save the original sys.modules entries before inserting stubs
(e.g., capture originals in a dict keyed by mod and the original for
"api.db.services.file_service"), install the stubs, and then restore the
originals (or delete newly added keys) in a teardown step (use teardown_module
or a pytest.fixture(scope="module", autouse=True) that yields) so that
sys.modules is returned to its prior state after tests in this file complete.
🪄 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: 97581347-cb6a-448a-8122-a0d222256946
📒 Files selected for processing (2)
agent/component/pipeline_chunker.pytest/unit_test/agent/test_pipeline_chunker.py
d2796c2 to
9fcbbe2
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
agent/component/pipeline_chunker.py (1)
165-169:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winInclude resolve failures in per-file summary.
When
content is None, the file is skipped without aper_file_countsentry, so summary accounting is incomplete for failed inputs.Suggested fix
content, filename = self._get_file_content(file_ref) self.set_input_value(file_ref, filename or "") if content is None: + per_file_counts.append(f"{filename or file_ref}: error (resolve failed)") logging.warning(f"[PipelineChunker] could not resolve file ref: {file_ref}") continue🤖 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 `@agent/component/pipeline_chunker.py` around lines 165 - 169, When _get_file_content(file_ref) returns None you currently skip adding an entry to per_file_counts which omits failed files from the summary; update the failure branch in PipelineChunker (the block that calls _get_file_content, set_input_value and logs the warning) to also add a per_file_counts entry for that file_ref (for example set per_file_counts[file_ref] = 0 or a failure marker) so the per-file summary includes resolve failures, keep the existing logging, and ensure any downstream summary/aggregation logic that reads per_file_counts handles the failure marker consistently.
🤖 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 `@agent/component/pipeline_chunker.py`:
- Around line 171-176: The current pipeline_chunker code appends raw exception
text (str(e)) into per_file_counts and later publishes it in summary, which can
leak internal details; keep logging.exception(e) to record the full trace but
change the per_file_counts append and any uses when building summary to a
sanitized message (e.g., f"{filename}: error" or f"{filename}: error (chunking
failed)") instead of including e, and ensure the same sanitization is applied
where per_file_counts is consumed/published (the summary-building code that
references per_file_counts and the chunker(filename, ...) exception handling).
---
Duplicate comments:
In `@agent/component/pipeline_chunker.py`:
- Around line 165-169: When _get_file_content(file_ref) returns None you
currently skip adding an entry to per_file_counts which omits failed files from
the summary; update the failure branch in PipelineChunker (the block that calls
_get_file_content, set_input_value and logs the warning) to also add a
per_file_counts entry for that file_ref (for example set
per_file_counts[file_ref] = 0 or a failure marker) so the per-file summary
includes resolve failures, keep the existing logging, and ensure any downstream
summary/aggregation logic that reads per_file_counts handles the failure marker
consistently.
🪄 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: b878f28c-9c78-4c65-a25d-64ed6e471821
📒 Files selected for processing (2)
agent/component/pipeline_chunker.pytest/unit_test/agent/test_pipeline_chunker.py
infiniflow#14773) Add `PipelineChunker` agent component that runs rag.app.* chunking strategies (naive, paper, qa, manual, book, table, presentation, laws, one, email, picture, audio, resume, tag) against uploaded files inside an Agent workflow. Emits plain text chunks for downstream Agent nodes without performing embedding or persisting to a knowledge base, per the issue request. The component is picked up by the existing auto-discovery in agent/component/__init__.py. Chunker functions are imported lazily to avoid pulling deepdoc/OCR machinery at module import time. File resolution mirrors the ExcelProcessor convention. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
9fcbbe2 to
5300f95
Compare
|
@JinHai-CN This PR is ready for review. |
|
@JinHai-CN could you review this PR, please? |
|
@KevinHuSh, @wangq8, Could you review this PR? Appreciate your feedback. |
yuzhichang
left a comment
There was a problem hiding this comment.
I re-reviewed the current head locally. The earlier review points I was watching for are already addressed in the branch now: from_page <= to_page validation is present, FileService.get_blob(...) failures are isolated per file, the summary no longer exposes raw exception text, and the test module restores its sys.modules stubs in teardown.
From my side I do not see a remaining blocking issue in the current diff. This looks ready to merge.
#14773) (#15068) ### What problem does this PR solve? Closes #14773. Today, Pipeline (`rag/flow/`) chunking strategies only run as part of a dataset ingestion that always embeds and indexes the result. There is no way to drive Pipeline-style chunking from an Agent workflow without paying that vectorization/persistence cost. This PR adds a single new Agent component, `PipelineChunker`, that: - Takes one or more file references (from `Begin` / `UserFillUp` uploads) as input. - Runs the existing `rag.app.*` chunking strategies (`naive`, `paper`, `qa`, `manual`, `book`, `presentation`, `laws`, `table`, `one`, `email`, `picture`, `audio`, `resume`, `tag`) against each file. - Emits the resulting chunks as `chunks: list[str]` and `chunks_full: list[dict]` for downstream Agent nodes. - Performs **no embedding and no persistence** — chunks live only in canvas variables for the duration of the run, exactly as requested in the issue. The component is auto-discovered by `agent/component/__init__.py`; no registry edits required. Chunker functions are imported lazily so the component itself does not pull `deepdoc` / OCR / VLM at component-discovery time. File resolution mirrors the existing `ExcelProcessor` convention. Out of scope for this PR (potential follow-ups): - Vectorization / KB persistence (explicit ask in the issue). - Frontend canvas UI for the new component. - Bridging to the newer Pydantic-based `rag/flow/chunker/TokenChunker` (consumes a parser node's structured output rather than a raw file — a separate, larger feature). ### Type of change - [ ] Bug Fix (non-breaking change which fixes an issue) - [x] New Feature (non-breaking change which adds functionality) - [ ] Documentation Update - [ ] Refactoring - [ ] Performance Improvement - [ ] Other (please describe): --- ## Files changed - `agent/component/pipeline_chunker.py` — new component (~180 lines) - `test/unit_test/agent/test_pipeline_chunker.py` — unit tests (~120 lines) ## Test plan - [x] `ruff check` on changed files — clean. - [x] `ruff format` applied to the new component file. - [x] `python -m py_compile` on both new files — both compile. - [x] New unit test file carries `pytestmark = pytest.mark.p2` so it runs under marker-filtered CI. - [x] Every new function, method, and class has a docstring (CodeRabbit 80% docstring-coverage gate). - [x] `python -m pytest test/unit_test/agent/test_pipeline_chunker.py -x -q` — **7 passed in 1.95s** locally. Tests stub `api.db.services.file_service` and `rag.app.*` so they exercise the parameter validation and parser-id lookup table without requiring the full backend / model stack. ## Manual integration plan (post-merge) 1. Drop the component into an Agent canvas after a `Begin` node with a file input. 2. Set `parser_id = "naive"` (or any other strategy) and reference the file input in `inputs`. 3. Wire the `chunks` output into a downstream `LLM` / `Message` / `Iteration` node — chunks are available as plain text without any embedding or KB write. Co-authored-by: John Baillie <[email protected]> Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]> Co-authored-by: Zhichang Yu <[email protected]>
…(NEW) Ports PR infiniflow#15068 (merged) to the Go agent side. The Python `PipelineChunker` component dispatches to a lazy `_PARSER_MODULES` table under `rag.app.*` — each entry is a `chunk(filename) -> list[chunks]` function that does file-format extraction AND chunking in one step. The Go chunking layer is architecturally different: it is a DSL-driven pipeline (internal/ingestion.ChunkEngine) that operates on TEXT, not on a file path. There is no single `rag.app.naive.chunk(filename)` entry point on the Go side. To stay honest with the architectural difference, the Go port: 1. Accepts text input (already extracted upstream) and runs it through the existing chunk engine via a minimal preprocess→split→postprocess pipeline. 2. Validates parser_id against the python whitelist (general/naive/paper/book/presentation/manual/laws/qa/ table/resume/picture/one/audio/email/tag) so canvas authors see a clear error at compile time, not mid-run. 3. Emits the same output shape: chunks (list[string]), chunks_full (list[object{text,size,index,meta}]), summary. 4. Documents the file-format extraction gap (PDF/DOCX/…) as a follow-up that lands when the Go file→text layer unifies. The structural port is complete: param validation, registry discovery, output schema, and end-to-end chunking all work against text inputs (5 new tests). File-format extraction remains a follow-up. Adjusts verify_p1_test expected count from 30 → 32 to account for the new PipelineChunker registration. Refs: .claude/plans/review-and-port-py-agent-changes.md Refs: infiniflow#15068
…hunker file support Two regressions caught in code review of a00ef0d: 1. Invoke proxy path did not actually pin DNS The previous code said (in a comment) "we layer our own pin around the proxy dial target" but the implementation was just http.Transport{Proxy: http.ProxyURL(...)} — no custom DialContext, so the proxy host got re-resolved at connect time, re-opening the TOCTOU window the SSRF guard was supposed to close. Fix: wrap the proxy transport in a custom DialContext that intercepts the proxy-host dial and replaces the target with the validated public IP (the same pattern utility.PinnedHTTPClient uses for the direct path). The connection now goes to the IP we validated, even if a subsequent DNS lookup returns a different answer. New TestInvoke_ProxyDNSPin exercises the pin path. 2. PipelineChunker accepted only text — not file input The previous commit documented "accepts TEXT input" and ran the chunk engine on whatever string the caller passed. The Python PR's contract is chunk(filename) — it does file-format extraction (PDF/DOCX/table/...) AND chunking in one step. The Go port silently downgraded the contract. Fix: PipelineChunker now reads file_bytes / file_ref / text / content from the inputs map, and the dispatch keys on parser_id (not just validation): - text / content → run through chunk engine - file_bytes → run through chunk engine (caller has done the extraction) - file_ref (with bytes) → run through chunk engine - non-UTF-8 bytes → reject with a clear error (PDF extraction is a follow-up) - parser_id → selects a real chunk strategy (naive→paragraph, paper/laws→sentence, qa→paragraph, etc.) so the output actually differs by parser_id File-format extraction (PDF/DOCX/table/...) remains a documented follow-up — the Go file→text layer is not unified the way Python's rag.app.*.chunk functions are. The component now rejects non-UTF-8 bytes explicitly so a downstream caller that mistakenly passes a PDF without extraction sees a clear error rather than a silent garbled chunk. 7 new PipelineChunker tests cover: text input, content alias, parser_id dispatch (paper > naive chunk count on the same input), file_bytes UTF-8, file_ref resolution, non-UTF-8 rejection, empty input. Refs: a00ef0d (Wave 4 partial — infiniflow#15068) Refs: infiniflow#15068 infiniflow#15426
Code review caught two issues on the previous fix-up:
1. Silent base64 misinterpretation. The previous
decodeFileRefString tried base64 first and fell back
to raw text on failure. Any plain-text input that
happened to satisfy the base64 alphabet would be
silently decoded — e.g. file_ref="Zm9v" would
rewrite to "foo", "Q29kZUNvbnZlcnQ" to
"CodeConvert". This is a real correctness bug:
any upstream component that puts already-extracted
text into file_ref and the text happens to be
base64-alphabet only would produce wrong chunks.
Fix: file_ref string is STRICTLY base64. No
fall-through. A non-base64 string returns a clear
error pointing the caller at the "text" / "content"
key for raw text input. The base64-alphabet test
("Zm9v") now decodes to "foo" deterministically —
the contract is unambiguous, not heuristic.
2. Metadata out of sync. The top-level package doc and
Inputs() still listed only text / content / file_bytes,
even though readPipelineInputText had been updated to
accept file_ref. The runtime contract and the
publicly-discoverable Inputs() surface were out of
sync, so a DSL/UI tool that introspects Inputs() to
build an input panel or validate keys would not
expose file_ref to canvas authors — the support
would be effectively hidden.
Fix: top-level SCOPE doc now lists file_ref with
the strict base64 contract; Inputs() exposes
file_ref, content, and file_bytes alongside text
with explicit encoding contract per key.
Updated tests:
- TestPipelineChunker_FileRefRawTextRejected:
Replaces the prior fall-through test. Pins that
plain-text under file_ref is rejected with a
clear error pointing the caller at text/content.
- TestPipelineChunker_FileRefBase64AlphabetText:
Pins that a base64-alphabet-only string
(file_ref="Zm9v") IS treated as base64 (decodes
to "foo") and chunks accordingly. This is the
intended strict behaviour; a future regression
to the fall-through policy would fail this test.
Refs: 3c820d1 (previous fix-up that introduced the
silent-misinterpretation risk)
Refs: infiniflow#15068
…(NEW) Ports PR infiniflow#15068 (merged) to the Go agent side. The Python `PipelineChunker` component dispatches to a lazy `_PARSER_MODULES` table under `rag.app.*` — each entry is a `chunk(filename) -> list[chunks]` function that does file-format extraction AND chunking in one step. The Go chunking layer is architecturally different: it is a DSL-driven pipeline (internal/ingestion.ChunkEngine) that operates on TEXT, not on a file path. There is no single `rag.app.naive.chunk(filename)` entry point on the Go side. To stay honest with the architectural difference, the Go port: 1. Accepts text input (already extracted upstream) and runs it through the existing chunk engine via a minimal preprocess→split→postprocess pipeline. 2. Validates parser_id against the python whitelist (general/naive/paper/book/presentation/manual/laws/qa/ table/resume/picture/one/audio/email/tag) so canvas authors see a clear error at compile time, not mid-run. 3. Emits the same output shape: chunks (list[string]), chunks_full (list[object{text,size,index,meta}]), summary. 4. Documents the file-format extraction gap (PDF/DOCX/…) as a follow-up that lands when the Go file→text layer unifies. The structural port is complete: param validation, registry discovery, output schema, and end-to-end chunking all work against text inputs (5 new tests). File-format extraction remains a follow-up. Adjusts verify_p1_test expected count from 30 → 32 to account for the new PipelineChunker registration. Refs: .claude/plans/review-and-port-py-agent-changes.md Refs: infiniflow#15068
…hunker file support Two regressions caught in code review of a00ef0d: 1. Invoke proxy path did not actually pin DNS The previous code said (in a comment) "we layer our own pin around the proxy dial target" but the implementation was just http.Transport{Proxy: http.ProxyURL(...)} — no custom DialContext, so the proxy host got re-resolved at connect time, re-opening the TOCTOU window the SSRF guard was supposed to close. Fix: wrap the proxy transport in a custom DialContext that intercepts the proxy-host dial and replaces the target with the validated public IP (the same pattern utility.PinnedHTTPClient uses for the direct path). The connection now goes to the IP we validated, even if a subsequent DNS lookup returns a different answer. New TestInvoke_ProxyDNSPin exercises the pin path. 2. PipelineChunker accepted only text — not file input The previous commit documented "accepts TEXT input" and ran the chunk engine on whatever string the caller passed. The Python PR's contract is chunk(filename) — it does file-format extraction (PDF/DOCX/table/...) AND chunking in one step. The Go port silently downgraded the contract. Fix: PipelineChunker now reads file_bytes / file_ref / text / content from the inputs map, and the dispatch keys on parser_id (not just validation): - text / content → run through chunk engine - file_bytes → run through chunk engine (caller has done the extraction) - file_ref (with bytes) → run through chunk engine - non-UTF-8 bytes → reject with a clear error (PDF extraction is a follow-up) - parser_id → selects a real chunk strategy (naive→paragraph, paper/laws→sentence, qa→paragraph, etc.) so the output actually differs by parser_id File-format extraction (PDF/DOCX/table/...) remains a documented follow-up — the Go file→text layer is not unified the way Python's rag.app.*.chunk functions are. The component now rejects non-UTF-8 bytes explicitly so a downstream caller that mistakenly passes a PDF without extraction sees a clear error rather than a silent garbled chunk. 7 new PipelineChunker tests cover: text input, content alias, parser_id dispatch (paper > naive chunk count on the same input), file_bytes UTF-8, file_ref resolution, non-UTF-8 rejection, empty input. Refs: a00ef0d (Wave 4 partial — infiniflow#15068) Refs: infiniflow#15068 infiniflow#15426
Code review caught two issues on the previous fix-up:
1. Silent base64 misinterpretation. The previous
decodeFileRefString tried base64 first and fell back
to raw text on failure. Any plain-text input that
happened to satisfy the base64 alphabet would be
silently decoded — e.g. file_ref="Zm9v" would
rewrite to "foo", "Q29kZUNvbnZlcnQ" to
"CodeConvert". This is a real correctness bug:
any upstream component that puts already-extracted
text into file_ref and the text happens to be
base64-alphabet only would produce wrong chunks.
Fix: file_ref string is STRICTLY base64. No
fall-through. A non-base64 string returns a clear
error pointing the caller at the "text" / "content"
key for raw text input. The base64-alphabet test
("Zm9v") now decodes to "foo" deterministically —
the contract is unambiguous, not heuristic.
2. Metadata out of sync. The top-level package doc and
Inputs() still listed only text / content / file_bytes,
even though readPipelineInputText had been updated to
accept file_ref. The runtime contract and the
publicly-discoverable Inputs() surface were out of
sync, so a DSL/UI tool that introspects Inputs() to
build an input panel or validate keys would not
expose file_ref to canvas authors — the support
would be effectively hidden.
Fix: top-level SCOPE doc now lists file_ref with
the strict base64 contract; Inputs() exposes
file_ref, content, and file_bytes alongside text
with explicit encoding contract per key.
Updated tests:
- TestPipelineChunker_FileRefRawTextRejected:
Replaces the prior fall-through test. Pins that
plain-text under file_ref is rejected with a
clear error pointing the caller at text/content.
- TestPipelineChunker_FileRefBase64AlphabetText:
Pins that a base64-alphabet-only string
(file_ref="Zm9v") IS treated as base64 (decodes
to "foo") and chunks accordingly. This is the
intended strict behaviour; a future regression
to the fall-through policy would fail this test.
Refs: 3c820d1 (previous fix-up that introduced the
silent-misinterpretation risk)
Refs: infiniflow#15068
…(NEW) Ports PR infiniflow#15068 (merged) to the Go agent side. The Python `PipelineChunker` component dispatches to a lazy `_PARSER_MODULES` table under `rag.app.*` — each entry is a `chunk(filename) -> list[chunks]` function that does file-format extraction AND chunking in one step. The Go chunking layer is architecturally different: it is a DSL-driven pipeline (internal/ingestion.ChunkEngine) that operates on TEXT, not on a file path. There is no single `rag.app.naive.chunk(filename)` entry point on the Go side. To stay honest with the architectural difference, the Go port: 1. Accepts text input (already extracted upstream) and runs it through the existing chunk engine via a minimal preprocess→split→postprocess pipeline. 2. Validates parser_id against the python whitelist (general/naive/paper/book/presentation/manual/laws/qa/ table/resume/picture/one/audio/email/tag) so canvas authors see a clear error at compile time, not mid-run. 3. Emits the same output shape: chunks (list[string]), chunks_full (list[object{text,size,index,meta}]), summary. 4. Documents the file-format extraction gap (PDF/DOCX/…) as a follow-up that lands when the Go file→text layer unifies. The structural port is complete: param validation, registry discovery, output schema, and end-to-end chunking all work against text inputs (5 new tests). File-format extraction remains a follow-up. Adjusts verify_p1_test expected count from 30 → 32 to account for the new PipelineChunker registration. Refs: .claude/plans/review-and-port-py-agent-changes.md Refs: infiniflow#15068
…hunker file support Two regressions caught in code review of a00ef0d: 1. Invoke proxy path did not actually pin DNS The previous code said (in a comment) "we layer our own pin around the proxy dial target" but the implementation was just http.Transport{Proxy: http.ProxyURL(...)} — no custom DialContext, so the proxy host got re-resolved at connect time, re-opening the TOCTOU window the SSRF guard was supposed to close. Fix: wrap the proxy transport in a custom DialContext that intercepts the proxy-host dial and replaces the target with the validated public IP (the same pattern utility.PinnedHTTPClient uses for the direct path). The connection now goes to the IP we validated, even if a subsequent DNS lookup returns a different answer. New TestInvoke_ProxyDNSPin exercises the pin path. 2. PipelineChunker accepted only text — not file input The previous commit documented "accepts TEXT input" and ran the chunk engine on whatever string the caller passed. The Python PR's contract is chunk(filename) — it does file-format extraction (PDF/DOCX/table/...) AND chunking in one step. The Go port silently downgraded the contract. Fix: PipelineChunker now reads file_bytes / file_ref / text / content from the inputs map, and the dispatch keys on parser_id (not just validation): - text / content → run through chunk engine - file_bytes → run through chunk engine (caller has done the extraction) - file_ref (with bytes) → run through chunk engine - non-UTF-8 bytes → reject with a clear error (PDF extraction is a follow-up) - parser_id → selects a real chunk strategy (naive→paragraph, paper/laws→sentence, qa→paragraph, etc.) so the output actually differs by parser_id File-format extraction (PDF/DOCX/table/...) remains a documented follow-up — the Go file→text layer is not unified the way Python's rag.app.*.chunk functions are. The component now rejects non-UTF-8 bytes explicitly so a downstream caller that mistakenly passes a PDF without extraction sees a clear error rather than a silent garbled chunk. 7 new PipelineChunker tests cover: text input, content alias, parser_id dispatch (paper > naive chunk count on the same input), file_bytes UTF-8, file_ref resolution, non-UTF-8 rejection, empty input. Refs: a00ef0d (Wave 4 partial — infiniflow#15068) Refs: infiniflow#15068 infiniflow#15426
Code review caught two issues on the previous fix-up:
1. Silent base64 misinterpretation. The previous
decodeFileRefString tried base64 first and fell back
to raw text on failure. Any plain-text input that
happened to satisfy the base64 alphabet would be
silently decoded — e.g. file_ref="Zm9v" would
rewrite to "foo", "Q29kZUNvbnZlcnQ" to
"CodeConvert". This is a real correctness bug:
any upstream component that puts already-extracted
text into file_ref and the text happens to be
base64-alphabet only would produce wrong chunks.
Fix: file_ref string is STRICTLY base64. No
fall-through. A non-base64 string returns a clear
error pointing the caller at the "text" / "content"
key for raw text input. The base64-alphabet test
("Zm9v") now decodes to "foo" deterministically —
the contract is unambiguous, not heuristic.
2. Metadata out of sync. The top-level package doc and
Inputs() still listed only text / content / file_bytes,
even though readPipelineInputText had been updated to
accept file_ref. The runtime contract and the
publicly-discoverable Inputs() surface were out of
sync, so a DSL/UI tool that introspects Inputs() to
build an input panel or validate keys would not
expose file_ref to canvas authors — the support
would be effectively hidden.
Fix: top-level SCOPE doc now lists file_ref with
the strict base64 contract; Inputs() exposes
file_ref, content, and file_bytes alongside text
with explicit encoding contract per key.
Updated tests:
- TestPipelineChunker_FileRefRawTextRejected:
Replaces the prior fall-through test. Pins that
plain-text under file_ref is rejected with a
clear error pointing the caller at text/content.
- TestPipelineChunker_FileRefBase64AlphabetText:
Pins that a base64-alphabet-only string
(file_ref="Zm9v") IS treated as base64 (decodes
to "foo") and chunks accordingly. This is the
intended strict behaviour; a future regression
to the fall-through policy would fail this test.
Refs: 3c820d1 (previous fix-up that introduced the
silent-misinterpretation risk)
Refs: infiniflow#15068
…(NEW) Ports PR infiniflow#15068 (merged) to the Go agent side. The Python `PipelineChunker` component dispatches to a lazy `_PARSER_MODULES` table under `rag.app.*` — each entry is a `chunk(filename) -> list[chunks]` function that does file-format extraction AND chunking in one step. The Go chunking layer is architecturally different: it is a DSL-driven pipeline (internal/ingestion.ChunkEngine) that operates on TEXT, not on a file path. There is no single `rag.app.naive.chunk(filename)` entry point on the Go side. To stay honest with the architectural difference, the Go port: 1. Accepts text input (already extracted upstream) and runs it through the existing chunk engine via a minimal preprocess→split→postprocess pipeline. 2. Validates parser_id against the python whitelist (general/naive/paper/book/presentation/manual/laws/qa/ table/resume/picture/one/audio/email/tag) so canvas authors see a clear error at compile time, not mid-run. 3. Emits the same output shape: chunks (list[string]), chunks_full (list[object{text,size,index,meta}]), summary. 4. Documents the file-format extraction gap (PDF/DOCX/…) as a follow-up that lands when the Go file→text layer unifies. The structural port is complete: param validation, registry discovery, output schema, and end-to-end chunking all work against text inputs (5 new tests). File-format extraction remains a follow-up. Adjusts verify_p1_test expected count from 30 → 32 to account for the new PipelineChunker registration. Refs: .claude/plans/review-and-port-py-agent-changes.md Refs: infiniflow#15068
…hunker file support Two regressions caught in code review of a00ef0d: 1. Invoke proxy path did not actually pin DNS The previous code said (in a comment) "we layer our own pin around the proxy dial target" but the implementation was just http.Transport{Proxy: http.ProxyURL(...)} — no custom DialContext, so the proxy host got re-resolved at connect time, re-opening the TOCTOU window the SSRF guard was supposed to close. Fix: wrap the proxy transport in a custom DialContext that intercepts the proxy-host dial and replaces the target with the validated public IP (the same pattern utility.PinnedHTTPClient uses for the direct path). The connection now goes to the IP we validated, even if a subsequent DNS lookup returns a different answer. New TestInvoke_ProxyDNSPin exercises the pin path. 2. PipelineChunker accepted only text — not file input The previous commit documented "accepts TEXT input" and ran the chunk engine on whatever string the caller passed. The Python PR's contract is chunk(filename) — it does file-format extraction (PDF/DOCX/table/...) AND chunking in one step. The Go port silently downgraded the contract. Fix: PipelineChunker now reads file_bytes / file_ref / text / content from the inputs map, and the dispatch keys on parser_id (not just validation): - text / content → run through chunk engine - file_bytes → run through chunk engine (caller has done the extraction) - file_ref (with bytes) → run through chunk engine - non-UTF-8 bytes → reject with a clear error (PDF extraction is a follow-up) - parser_id → selects a real chunk strategy (naive→paragraph, paper/laws→sentence, qa→paragraph, etc.) so the output actually differs by parser_id File-format extraction (PDF/DOCX/table/...) remains a documented follow-up — the Go file→text layer is not unified the way Python's rag.app.*.chunk functions are. The component now rejects non-UTF-8 bytes explicitly so a downstream caller that mistakenly passes a PDF without extraction sees a clear error rather than a silent garbled chunk. 7 new PipelineChunker tests cover: text input, content alias, parser_id dispatch (paper > naive chunk count on the same input), file_bytes UTF-8, file_ref resolution, non-UTF-8 rejection, empty input. Refs: a00ef0d (Wave 4 partial — infiniflow#15068) Refs: infiniflow#15068 infiniflow#15426
Code review caught two issues on the previous fix-up:
1. Silent base64 misinterpretation. The previous
decodeFileRefString tried base64 first and fell back
to raw text on failure. Any plain-text input that
happened to satisfy the base64 alphabet would be
silently decoded — e.g. file_ref="Zm9v" would
rewrite to "foo", "Q29kZUNvbnZlcnQ" to
"CodeConvert". This is a real correctness bug:
any upstream component that puts already-extracted
text into file_ref and the text happens to be
base64-alphabet only would produce wrong chunks.
Fix: file_ref string is STRICTLY base64. No
fall-through. A non-base64 string returns a clear
error pointing the caller at the "text" / "content"
key for raw text input. The base64-alphabet test
("Zm9v") now decodes to "foo" deterministically —
the contract is unambiguous, not heuristic.
2. Metadata out of sync. The top-level package doc and
Inputs() still listed only text / content / file_bytes,
even though readPipelineInputText had been updated to
accept file_ref. The runtime contract and the
publicly-discoverable Inputs() surface were out of
sync, so a DSL/UI tool that introspects Inputs() to
build an input panel or validate keys would not
expose file_ref to canvas authors — the support
would be effectively hidden.
Fix: top-level SCOPE doc now lists file_ref with
the strict base64 contract; Inputs() exposes
file_ref, content, and file_bytes alongside text
with explicit encoding contract per key.
Updated tests:
- TestPipelineChunker_FileRefRawTextRejected:
Replaces the prior fall-through test. Pins that
plain-text under file_ref is rejected with a
clear error pointing the caller at text/content.
- TestPipelineChunker_FileRefBase64AlphabetText:
Pins that a base64-alphabet-only string
(file_ref="Zm9v") IS treated as base64 (decodes
to "foo") and chunks accordingly. This is the
intended strict behaviour; a future regression
to the fall-through policy would fail this test.
Refs: 3c820d1 (previous fix-up that introduced the
silent-misinterpretation risk)
Refs: infiniflow#15068
) Mirrors 14 merged upstream PRs into the Go agent port. PRs ported: - #15609 ExeSQL SSRF guard + DNS pin - #15436 HTTP timeout on external API tools - #16363 be_output restore + DeepL error path - #15644 switch no longer matches empty condition - #15374 session_id bind to path agent_id (DAO idor guard) - #16169 sandbox artifact ownership gate - #15457 tenant ownership on agentbots - #15145 rerun agent document access check - #15446 thinking switch (component portion; provider policy lives in internal/llm) - #15426 Invoke URL/proxy SSRF + DNS pin + no-redirects - #15238 agentbot thinking-logs beta endpoint - #14589 UserFillUp SSE event propagation - #14890 anonymous webhook opt-in - #15068 PipelineChunker new component (text/file_ref/parser_id dispatch; file-format extraction is a follow-up) 40 files, +2355 / -58 lines. 33 new tests, all targeted package suites pass (1721 + 4 skipped); 1 pre-existing flaky test unrelated.
…iniflow#16455) Mirrors 14 merged upstream PRs into the Go agent port. PRs ported: - infiniflow#15609 ExeSQL SSRF guard + DNS pin - infiniflow#15436 HTTP timeout on external API tools - infiniflow#16363 be_output restore + DeepL error path - infiniflow#15644 switch no longer matches empty condition - infiniflow#15374 session_id bind to path agent_id (DAO idor guard) - infiniflow#16169 sandbox artifact ownership gate - infiniflow#15457 tenant ownership on agentbots - infiniflow#15145 rerun agent document access check - infiniflow#15446 thinking switch (component portion; provider policy lives in internal/llm) - infiniflow#15426 Invoke URL/proxy SSRF + DNS pin + no-redirects - infiniflow#15238 agentbot thinking-logs beta endpoint - infiniflow#14589 UserFillUp SSE event propagation - infiniflow#14890 anonymous webhook opt-in - infiniflow#15068 PipelineChunker new component (text/file_ref/parser_id dispatch; file-format extraction is a follow-up) 40 files, +2355 / -58 lines. 33 new tests, all targeted package suites pass (1721 + 4 skipped); 1 pre-existing flaky test unrelated.
What problem does this PR solve?
Closes #14773.
Today, Pipeline (
rag/flow/) chunking strategies only run as part of a dataset ingestion that always embeds and indexes the result. There is no way to drive Pipeline-style chunking from an Agent workflow without paying that vectorization/persistence cost.This PR adds a single new Agent component,
PipelineChunker, that:Begin/UserFillUpuploads) as input.rag.app.*chunking strategies (naive,paper,qa,manual,book,presentation,laws,table,one,email,picture,audio,resume,tag) against each file.chunks: list[str]andchunks_full: list[dict]for downstream Agent nodes.The component is auto-discovered by
agent/component/__init__.py; no registry edits required. Chunker functions are imported lazily so the component itself does not pulldeepdoc/ OCR / VLM at component-discovery time. File resolution mirrors the existingExcelProcessorconvention.Out of scope for this PR (potential follow-ups):
rag/flow/chunker/TokenChunker(consumes a parser node's structured output rather than a raw file — a separate, larger feature).Type of change
Files changed
agent/component/pipeline_chunker.py— new component (~180 lines)test/unit_test/agent/test_pipeline_chunker.py— unit tests (~120 lines)Test plan
ruff checkon changed files — clean.ruff formatapplied to the new component file.python -m py_compileon both new files — both compile.pytestmark = pytest.mark.p2so it runs under marker-filtered CI.python -m pytest test/unit_test/agent/test_pipeline_chunker.py -x -q— 7 passed in 1.95s locally. Tests stubapi.db.services.file_serviceandrag.app.*so they exercise the parameter validation and parser-id lookup table without requiring the full backend / model stack.Manual integration plan (post-merge)
Beginnode with a file input.parser_id = "naive"(or any other strategy) and reference the file input ininputs.chunksoutput into a downstreamLLM/Message/Iterationnode — chunks are available as plain text without any embedding or KB write.