Skip to content

Go: add parse and chunk command - #15936

Merged
JinHai-CN merged 1 commit into
infiniflow:mainfrom
JinHai-CN:fix452
Jun 11, 2026
Merged

JinHai-CN merged 1 commit into
infiniflow:mainfrom
JinHai-CN:fix452

Conversation

@JinHai-CN

@JinHai-CN JinHai-CN commented Jun 11, 2026 •

Copy link
Copy Markdown
Member

What problem does this PR solve?

Two commands are used for ingestion file testing

RAGFlow(api/default)> chunk 'file' with 'dsl';
Chunk file: file, DSL: dsl
SUCCESS
RAGFlow(api/default)> explain chunk 'file' with 'dsl';
Explain chunk file: file, DSL: dsl
SUCCESS
RAGFlow(api/default)> parse file 'filename' chat 'xxx';
Success to parse local file "filename", vision: , chat: xxx, asr: , ocr: , embedding: , doc_parse: 
SUCCESS

Type of change

  • New Feature (non-breaking change which adds functionality)

@coderabbitai

coderabbitai Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds two new CLI command types to the RAGFlow parser: PARSE FILE for parsing local files with optional model configuration, and EXPLAIN CHUNK for parsing chunks with explanation enabled. Changes flow through lexer token recognition, parser routing, command parsing logic, and execution handlers.

Changes

CLI command flow for file parsing and chunking

Layer / File(s) Summary
Token type and keyword recognition
internal/cli/types.go, internal/cli/lexer.go
TokenExplain constant added to the token type enumeration, and lexer.lookupIdent now recognizes the EXPLAIN keyword.
Parser command dispatch
internal/cli/parser.go, internal/cli/user_parser.go
parseUserCommand routes TokenExplain and TokenChunk to their respective parsing functions; parseParseCommand expands to recognize FILE token and dispatch to file-based parsing.
PARSE FILE and EXPLAIN CHUNK parsing
internal/cli/user_parser.go
parseParseLocalFileCommand handles PARSE FILE syntax with optional model selection clauses (VISION, ASR, OCR, CHAT, EMBED, DOC_PARSE); parseExplainCommand and parseChunkCommand parse EXPLAIN CHUNK syntax with filename and DSL parameters.
Command execution and HTTP routing
internal/cli/user_command.go, internal/cli/cli_http.go
UserParseLocalFile handler reads filename and optional model identifiers, prints success, and returns SimpleResponse; ChunkCommand handler reads filename and DSL with optional explain flag, prints chunking status, and returns SimpleResponse; ExecuteUserCommand dispatcher routes user_parse_local_file_command and user_chunk_command to their handlers.

Sequence Diagram

sequenceDiagram
  participant Lexer
  participant Parser
  participant UserParser
  participant Handler
  participant Response

  Lexer->>Lexer: Recognize EXPLAIN keyword → TokenExplain
  Parser->>UserParser: Route TokenExplain → parseExplainCommand()
  UserParser->>UserParser: Parse CHUNK filename WITH dsl
  UserParser->>UserParser: Build user_chunk_command with explain=true
  UserParser->>Handler: Return parsed command
  Handler->>Handler: Extract filename, dsl, explain params
  Handler->>Response: Return SimpleResponse(code=0, message)

  Lexer->>Lexer: Tokenize PARSE FILE filename
  Parser->>UserParser: Route FILE token → parseParseLocalFileCommand()
  UserParser->>UserParser: Parse FILE and optional model clauses
  UserParser->>UserParser: Build user_parse_local_file_command
  UserParser->>Handler: Return parsed command
  Handler->>Handler: Extract filename and model identifiers
  Handler->>Response: Return SimpleResponse(code=0, message)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

size:L

Poem

🐰 Chunk by chunk, files to parse,
New commands light the path,
With EXPLAIN to show the way,
PARSE FILE saves the day!
Lexer, parser, handlers aligned—
A complete CLI redesigned. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Go: add parse and chunk command' clearly and concisely summarizes the main changes, which add two new CLI commands (parse and chunk) to the Go codebase.
Description check ✅ Passed The description addresses the problem being solved and includes the required Type of change field, but lacks specific implementation details and technical context that would aid reviewers.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

Command failed


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.

@JinHai-CN JinHai-CN added the ci Continue Integration label Jun 11, 2026
@JinHai-CN
JinHai-CN marked this pull request as ready for review June 11, 2026 04:47
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 11, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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/cli/user_parser.go`:
- Around line 3769-3770: Update the stale error string that returns
fmt.Errorf("expected DATASET, WITH, or DOCUMENT") to include the newly supported
FILE token (e.g. "expected DATASET, WITH, DOCUMENT, or FILE" or "expected
DATASET, WITH, DOCUMENT, or PARSE FILE") in the same return statement inside
internal/cli/user_parser.go so CLI parse errors reflect the new `PARSE FILE`
grammar; locate the return using the exact error string and change it
accordingly.
- Around line 3888-3896: The parser branch handling TokenEmbed stores the wrong
params key ("embed_model") causing the handler (which reads
cmd.Params["embedding_model"] in internal/cli/user_command.go) to miss the
value; change the parser code in the TokenEmbed case to store the parsed value
under "embedding_model" (the same key the handler expects) — locate the
TokenEmbed case that calls parseQuotedString() and set
cmd.Params["embedding_model"] = embedModel, ensuring you keep the existing
p.nextToken() and error handling.
🪄 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: 40f45228-961d-4b84-962f-de9066da44bb

📥 Commits

Reviewing files that changed from the base of the PR and between a079c08 and 18af9c6.

📒 Files selected for processing (6)
  • internal/cli/cli_http.go
  • internal/cli/lexer.go
  • internal/cli/parser.go
  • internal/cli/types.go
  • internal/cli/user_command.go
  • internal/cli/user_parser.go

Comment on lines 3769 to 3770
return nil, fmt.Errorf("expected DATASET, WITH, or DOCUMENT")
}

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Error message is stale after adding PARSE FILE

The default parse error still says expected DATASET, WITH, or DOCUMENT, but FILE is now valid too. This makes CLI errors misleading.

Suggested fix
-		return nil, fmt.Errorf("expected DATASET, WITH, or DOCUMENT")
+		return nil, fmt.Errorf("expected DATASET, WITH, DOCUMENT, or FILE")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return nil, fmt.Errorf("expected DATASET, WITH, or DOCUMENT")
}
return nil, fmt.Errorf("expected DATASET, WITH, DOCUMENT, or FILE")
}
🤖 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/cli/user_parser.go` around lines 3769 - 3770, Update the stale error
string that returns fmt.Errorf("expected DATASET, WITH, or DOCUMENT") to include
the newly supported FILE token (e.g. "expected DATASET, WITH, DOCUMENT, or FILE"
or "expected DATASET, WITH, DOCUMENT, or PARSE FILE") in the same return
statement inside internal/cli/user_parser.go so CLI parse errors reflect the new
`PARSE FILE` grammar; locate the return using the exact error string and change
it accordingly.

Comment on lines +3888 to +3896
case TokenEmbed:
p.nextToken()
var embedModel string
embedModel, err = p.parseQuotedString()
if err != nil {
return nil, err
}
cmd.Params["embed_model"] = embedModel
p.nextToken()

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

PARSE FILE ... EMBED stores the wrong param key

The parser writes cmd.Params["embed_model"], but the handler reads cmd.Params["embedding_model"] (internal/cli/user_command.go, Line 3242). The embed option is silently lost at runtime.

Suggested fix
-		case TokenEmbed:
+		case TokenEmbed:
 			p.nextToken()
 			var embedModel string
 			embedModel, err = p.parseQuotedString()
 			if err != nil {
 				return nil, err
 			}
-			cmd.Params["embed_model"] = embedModel
+			cmd.Params["embedding_model"] = embedModel
 			p.nextToken()
🤖 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/cli/user_parser.go` around lines 3888 - 3896, The parser branch
handling TokenEmbed stores the wrong params key ("embed_model") causing the
handler (which reads cmd.Params["embedding_model"] in
internal/cli/user_command.go) to miss the value; change the parser code in the
TokenEmbed case to store the parsed value under "embedding_model" (the same key
the handler expects) — locate the TokenEmbed case that calls parseQuotedString()
and set cmd.Params["embedding_model"] = embedModel, ensuring you keep the
existing p.nextToken() and error handling.

@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (a079c08) to head (18af9c6).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15936   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit ca00d23 into infiniflow:main Jun 11, 2026
1 check passed
This was referenced Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant