Skip to content

feat(agent): add Pipeline chunker component for pre-chunking workflows (#14773) - #15068

Merged
yuzhichang merged 2 commits into
infiniflow:mainfrom
Khaostica:feat/agent-pipeline-chunker
Jun 28, 2026
Merged

yuzhichang merged 2 commits into
infiniflow:mainfrom
Khaostica:feat/agent-pipeline-chunker

Conversation

@Khaostica

Copy link
Copy Markdown
Contributor

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)
  • 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

  • ruff check on changed files — clean.
  • ruff format applied to the new component file.
  • python -m py_compile on both new files — both compile.
  • New unit test file carries pytestmark = pytest.mark.p2 so it runs under marker-filtered CI.
  • Every new function, method, and class has a docstring (CodeRabbit 80% docstring-coverage gate).
  • 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.

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 20, 2026
@coderabbitai

coderabbitai Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: dc6f7df0-9b92-45a7-ae8d-e1a53ea521c7

📥 Commits

Reviewing files that changed from the base of the PR and between 9fcbbe2 and 5300f95.

📒 Files selected for processing (2)
  • agent/component/pipeline_chunker.py
  • test/unit_test/agent/test_pipeline_chunker.py

📝 Walkthrough

Walkthrough

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

Changes

PipelineChunker Agent Component

Layer / File(s) Summary
Parser module mapping and lazy chunker loader
agent/component/pipeline_chunker.py
Defines _PARSER_MODULES mapping parser IDs to rag.app.* modules and implements _load_chunker() to lazily return each module's chunk callable.
Parameter contract and validation
agent/component/pipeline_chunker.py, test/unit_test/agent/test_pipeline_chunker.py
PipelineChunkerParam sets inputs/outputs and check() ensures parser_id is known, from_page/to_page are non-negative and ordered (from_page <= to_page), and parser_config is a dict. Tests cover valid defaults, whitelist acceptance, and error cases (including inverted ranges).
Component interface and file inputs
agent/component/pipeline_chunker.py
PipelineChunker.get_input_form() exposes referenced canvas variables as file inputs; _get_file_content() resolves canvas refs to (bytes, filename) via FileService.get_blob with exception handling.
Chunker invocation, timeout, and aggregation
agent/component/pipeline_chunker.py
_invoke() loads the chunker, prepares args (lang, tenant, page range, parser_config, logger), iterates referenced files invoking the chunker with cancellation and timeout, collects chunks (text), chunks_full (raw chunk dicts), and a formatted per-file summary.
Status reporting
agent/component/pipeline_chunker.py
thoughts() returns a UI status string indicating the active parser_id strategy.
Unit tests
test/unit_test/agent/test_pipeline_chunker.py
Tests stub heavy imports, validate PipelineChunkerParam.check() behavior (including inverted page-range rejection), and assert _load_chunker() resolution and unknown-key handling.

Sequence Diagram

sequenceDiagram
  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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A rabbit with a parser, nimble and quick,
Maps IDs to chunkers and splits every bit,
Files turned to chunks, summaries in tow,
Agent hums softly—onward we go! 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding a PipelineChunker component for Agent workflows that enables pre-chunking without vectorization, which aligns with the changeset.
Description check ✅ Passed The description fully addresses the template with clear problem statement, selected change type (New Feature), detailed implementation notes, and comprehensive test plan.
Linked Issues check ✅ Passed The PR successfully implements all coding objectives from #14773: exposes Pipeline chunking strategies in Agent, enables pre-chunking without vectorization/persistence, and provides chunks to downstream Agent nodes.
Out of Scope Changes check ✅ Passed All changes are within scope; the PR adds PipelineChunker component and unit tests without introducing unrelated modifications or scope creep.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

📥 Commits

Reviewing files that changed from the base of the PR and between dc01e0e and d2796c2.

📒 Files selected for processing (2)
  • agent/component/pipeline_chunker.py
  • test/unit_test/agent/test_pipeline_chunker.py

Comment thread agent/component/pipeline_chunker.py Resolved
Comment thread agent/component/pipeline_chunker.py Resolved
@Khaostica
Khaostica force-pushed the feat/agent-pipeline-chunker branch from d2796c2 to 9fcbbe2 Compare May 20, 2026 15:58

@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

♻️ Duplicate comments (1)
agent/component/pipeline_chunker.py (1)

165-169: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Include resolve failures in per-file summary.

When content is None, the file is skipped without a per_file_counts entry, 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

📥 Commits

Reviewing files that changed from the base of the PR and between d2796c2 and 9fcbbe2.

📒 Files selected for processing (2)
  • agent/component/pipeline_chunker.py
  • test/unit_test/agent/test_pipeline_chunker.py

Comment thread agent/component/pipeline_chunker.py Resolved
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]>
@Khaostica
Khaostica force-pushed the feat/agent-pipeline-chunker branch from 9fcbbe2 to 5300f95 Compare May 20, 2026 16:03
@Khaostica

Copy link
Copy Markdown
Contributor Author

@JinHai-CN This PR is ready for review.

@Khaostica

Copy link
Copy Markdown
Contributor Author

@JinHai-CN could you review this PR, please?

@Khaostica

Copy link
Copy Markdown
Contributor Author

@KevinHuSh, @wangq8, Could you review this PR? Appreciate your feedback.

@yuzhichang
yuzhichang self-requested a review June 28, 2026 00:49

@yuzhichang yuzhichang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@yuzhichang
yuzhichang merged commit d4a0e71 into infiniflow:main Jun 28, 2026
3 checks passed
yuzhichang added a commit that referenced this pull request Jun 29, 2026
#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]>
yuzhichang added a commit to yuzhichang/ragflow that referenced this pull request Jun 29, 2026
…(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
yuzhichang added a commit to yuzhichang/ragflow that referenced this pull request Jun 29, 2026
…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
yuzhichang added a commit to yuzhichang/ragflow that referenced this pull request Jun 29, 2026
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
yuzhichang added a commit to yuzhichang/ragflow that referenced this pull request Jun 29, 2026
…(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
yuzhichang added a commit to yuzhichang/ragflow that referenced this pull request Jun 29, 2026
…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
yuzhichang added a commit to yuzhichang/ragflow that referenced this pull request Jun 29, 2026
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
yuzhichang added a commit to yuzhichang/ragflow that referenced this pull request Jun 29, 2026
…(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
yuzhichang added a commit to yuzhichang/ragflow that referenced this pull request Jun 29, 2026
…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
yuzhichang added a commit to yuzhichang/ragflow that referenced this pull request Jun 29, 2026
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
yuzhichang added a commit to yuzhichang/ragflow that referenced this pull request Jun 29, 2026
…(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
yuzhichang added a commit to yuzhichang/ragflow that referenced this pull request Jun 29, 2026
…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
yuzhichang added a commit to yuzhichang/ragflow that referenced this pull request Jun 29, 2026
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
yuzhichang added a commit that referenced this pull request Jun 30, 2026
)

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.
xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Jul 1, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Enable Pipeline capabilities inside Agent - pre-chunking without vectorization for Agent processing

3 participants