Repository navigation
Go: add parse and chunk command - #15936
Conversation
Signed-off-by: Jin Hai <[email protected]>
📝 WalkthroughWalkthroughThe 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. ChangesCLI command flow for file parsing and chunking
Sequence DiagramsequenceDiagram
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)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (6)
internal/cli/cli_http.gointernal/cli/lexer.gointernal/cli/parser.gointernal/cli/types.gointernal/cli/user_command.gointernal/cli/user_parser.go
| return nil, fmt.Errorf("expected DATASET, WITH, or DOCUMENT") | ||
| } |
There was a problem hiding this comment.
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.
| 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.
| case TokenEmbed: | ||
| p.nextToken() | ||
| var embedModel string | ||
| embedModel, err = p.parseQuotedString() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| cmd.Params["embed_model"] = embedModel | ||
| p.nextToken() |
There was a problem hiding this comment.
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
What problem does this PR solve?
Two commands are used for ingestion file testing
Type of change