Repository navigation
Go: add office_oxide and parse docx file. - #15976
Conversation
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
📝 WalkthroughWalkthroughThis PR introduces a modular document parser framework that classifies files by type, instantiates format-specific parsers through a factory pattern, and integrates them into CLI local file parsing. It adds native library support for DOCX parsing via office_oxide and updates build configuration and documentation accordingly. ChangesDocument Parsing Framework
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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: 6
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/development.md (1)
10-20:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winThe first-build command does not actually install
office_oxide.
./build.sh --cpponly builds the C++ library. The newoffice_oxideinstall path runs insidebuild_go()inbuild.shLines 184-190, so this instruction currently sends readers down the wrong setup flow. Please change the first-build step to./build.sh --allor explicitly document the required--cppthen--gosequence.Suggested fix
-- First build (includes C++ dependencies and office_oxide native library): +- First build (includes C++ dependencies and office_oxide native library): ```bash -./build.sh --cpp +./build.sh --all
- Subsequent builds (Go only):
</details> <details> <summary>🤖 Prompt for AI Agents</summary>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/development.mdaround lines 10 - 20, Update the documentation so
the "first build" command reflects the actual install flow: change the
first-step example from "./build.sh --cpp" to either "./build.sh --all" or
explicitly document running "./build.sh --cpp" followed by "./build.sh --go";
mention that the office_oxide install happens inside the build_go() step (so
--cpp alone does not install office_oxide) and ensure the examples and prose
consistently reference the script flags (--cpp, --go, --all) and the build_go()
install behavior.</details> <!-- cr-comment:v1:2950fbb6c740cbd224a3eea6 --> </blockquote></details> </blockquote></details>🧹 Nitpick comments (1)
build.sh (1)
21-23: ⚡ Quick winKeep the
office_oxideversion single-sourced.
OFFICE_OXIDE_VERSIONhere has to stay in lockstep withgithub.com/yfedoseev/office_oxide/goingo.modLine 29. If one is bumped without the other, the build will fetch one native release and compile against a different Go wrapper version, which is a fragile ABI contract to enforce manually. Please derive this from one source or add a build-time consistency check.🤖 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 `@build.sh` around lines 21 - 23, OFFICE_OXIDE_VERSION in build.sh must be single-sourced with the module version in go.mod (github.com/yfedoseev/office_oxide/go) to avoid ABI mismatches; update build.sh to derive the native release version from go.mod (parse the module dependency entry for github.com/yfedoseev/office_oxide/go) or add a build-time consistency check that reads go.mod, extracts the office_oxide version and compares it to OFFICE_OXIDE_VERSION (failing the build on mismatch); refer to the OFFICE_OXIDE_VERSION variable in build.sh and the go.mod dependency entry for github.com/yfedoseev/office_oxide/go when implementing this.🤖 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 `@build.sh`: - Around line 122-131: The install success check only verifies lib_path; add a second existence check for the header at "${OFFICE_OXIDE_PREFIX}/include/office_oxide_c/office_oxide.h" (or a new variable header_path) right after the lib_path check and, if missing, echo an error with the missing header path and exit 1; ensure you create a clear message and suggest the same curl/tar extraction hint used for lib_path so the script fails fast and reports the actionable missing header instead of letting `go build` fail later. In `@internal/cli/user_command.go`: - Around line 3261-3264: The error message for the os.ReadFile failure is misleading: update the fmt.Errorf call that currently uses "failed to read dsl file" so it reflects the actual user-selected input document (use filename or a phrase like "input file" / "user-selected document") and include the filename and wrapped error (the os.ReadFile call and variable filename identify the spot to change). In `@internal/ingestion/parser/doc_parser.go`: - Around line 28-30: The placeholder parsers (e.g., DOCParser.Parse, PDFParser.Parse, PPTParser.Parse, XLSParser.Parse, XLSXParser.Parse) currently ignore the input data and return nil, making unsupported formats appear successful; update each Parse method to either implement actual extraction or explicitly return a not-implemented error (e.g., errors.New("parser not implemented for <format>")) so UserParseLocalFile won't treat a no-op as success—locate the Parse methods in the respective types (DOCParser.Parse, PDFParser.Parse, PPTParser.Parse, XLSParser.Parse, XLSXParser.Parse) and replace the println+nil with either working extraction logic or a clear error return. In `@internal/ingestion/parser/docx_parser.go`: - Around line 19-23: The DOCX parser imports cgo-only office_oxide unconditionally; add build tags to isolate it: mark the existing DOCX implementation file (containing NewDOCXParser and any direct use of officeOxide) with a "//go:build cgo" tag and create a companion stub file with "//go:build !cgo" that provides a fallback NewDOCXParser (or returns an error/not-implemented) so the package builds without CGO; also ensure the factory wiring in internal/ingestion/parser/type.go checks the returned value/error from NewDOCXParser (or gates registration) so non-cgo builds don’t register a non-functional DOCX parser. In `@internal/ingestion/parser/pptx_parser.go`: - Around line 28-30: PPTXParser.Parse currently ignores the input and returns nil; stop silently succeeding by returning a clear not-implemented error from PPTXParser.Parse (e.g., return fmt.Errorf("PPTX parsing not implemented")) so callers fail fast, or alternatively remove FileTypePPTX from the parser registry in GetParser until real parsing is implemented; update any tests/usage accordingly to expect the error instead of a successful parse. In `@internal/utility/file.go`: - Around line 60-87: Update GetFileType to keep the explicit Office and PDF cases but for any unrecognized suffix call and return the broader classification from FilenameType(filename) instead of returning FileTypeOTHER; locate the switch in GetFileType and replace the default branch (and possibly other non-office branches) so that when suffix isn't one of "pdf","xls","xlsx","doc","docx","ppt","pptx" it delegates to FilenameType to preserve classifications like txt, md, json, csv, jpg, png, mp3, etc. --- Outside diff comments: In `@internal/development.md`: - Around line 10-20: Update the documentation so the "first build" command reflects the actual install flow: change the first-step example from "./build.sh --cpp" to either "./build.sh --all" or explicitly document running "./build.sh --cpp" followed by "./build.sh --go"; mention that the office_oxide install happens inside the build_go() step (so --cpp alone does not install office_oxide) and ensure the examples and prose consistently reference the script flags (--cpp, --go, --all) and the build_go() install behavior. --- Nitpick comments: In `@build.sh`: - Around line 21-23: OFFICE_OXIDE_VERSION in build.sh must be single-sourced with the module version in go.mod (github.com/yfedoseev/office_oxide/go) to avoid ABI mismatches; update build.sh to derive the native release version from go.mod (parse the module dependency entry for github.com/yfedoseev/office_oxide/go) or add a build-time consistency check that reads go.mod, extracts the office_oxide version and compares it to OFFICE_OXIDE_VERSION (failing the build on mismatch); refer to the OFFICE_OXIDE_VERSION variable in build.sh and the go.mod dependency entry for github.com/yfedoseev/office_oxide/go when implementing this.🪄 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:
dc614c5c-a9a8-4724-97f3-38a935a2bd69⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum📒 Files selected for processing (14)
build.shgo.modinternal/cli/user_command.gointernal/development.mdinternal/ingestion/parser/doc_parser.gointernal/ingestion/parser/docx_parser.gointernal/ingestion/parser/pdf_parser.gointernal/ingestion/parser/ppt_parser.gointernal/ingestion/parser/pptx_parser.gointernal/ingestion/parser/type.gointernal/ingestion/parser/xls_parser.gointernal/ingestion/parser/xlsx_parser.gointernal/service/file.gointernal/utility/file.go
| mkdir -p "${OFFICE_OXIDE_PREFIX}" | ||
| _download_and_extract "$release_url" "${OFFICE_OXIDE_PREFIX}" | ||
|
|
||
| if [ ! -f "$lib_path" ]; then | ||
| echo -e "${RED}Error: Failed to install office_oxide native library (missing ${lib_path})${NC}" | ||
| echo " Try: curl -fsSL ${release_url} | tar xzf - -C ${OFFICE_OXIDE_PREFIX}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo -e "${GREEN}✓ office_oxide native library installed${NC}" |
There was a problem hiding this comment.
Fail the install when the header is missing too.
The success path only validates ${OFFICE_OXIDE_PREFIX}/lib/${lib_file}, but the next step also requires ${OFFICE_OXIDE_PREFIX}/include/office_oxide_c/office_oxide.h on Line 188. A partial extract currently reports a successful install and then fails later in go build with a less actionable CGO error.
Suggested fix
- if [ ! -f "$lib_path" ]; then
- echo -e "${RED}Error: Failed to install office_oxide native library (missing ${lib_path})${NC}"
- echo " Try: curl -fsSL ${release_url} | tar xzf - -C ${OFFICE_OXIDE_PREFIX}"
+ if [ ! -f "$lib_path" ] || [ ! -f "$header_path" ]; then
+ echo -e "${RED}Error: Failed to install office_oxide native library${NC}"
+ echo " Missing library: ${lib_path}"
+ echo " Missing header: ${header_path}"
+ echo " Try: curl -fsSL ${release_url} | tar xzf - -C ${OFFICE_OXIDE_PREFIX}"
exit 1
fi📝 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.
| mkdir -p "${OFFICE_OXIDE_PREFIX}" | |
| _download_and_extract "$release_url" "${OFFICE_OXIDE_PREFIX}" | |
| if [ ! -f "$lib_path" ]; then | |
| echo -e "${RED}Error: Failed to install office_oxide native library (missing ${lib_path})${NC}" | |
| echo " Try: curl -fsSL ${release_url} | tar xzf - -C ${OFFICE_OXIDE_PREFIX}" | |
| exit 1 | |
| fi | |
| echo -e "${GREEN}✓ office_oxide native library installed${NC}" | |
| mkdir -p "${OFFICE_OXIDE_PREFIX}" | |
| _download_and_extract "$release_url" "${OFFICE_OXIDE_PREFIX}" | |
| if [ ! -f "$lib_path" ] || [ ! -f "$header_path" ]; then | |
| echo -e "${RED}Error: Failed to install office_oxide native library${NC}" | |
| echo " Missing library: ${lib_path}" | |
| echo " Missing header: ${header_path}" | |
| echo " Try: curl -fsSL ${release_url} | tar xzf - -C ${OFFICE_OXIDE_PREFIX}" | |
| exit 1 | |
| fi | |
| echo -e "${GREEN}✓ office_oxide native library installed${NC}" |
🤖 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 `@build.sh` around lines 122 - 131, The install success check only verifies
lib_path; add a second existence check for the header at
"${OFFICE_OXIDE_PREFIX}/include/office_oxide_c/office_oxide.h" (or a new
variable header_path) right after the lib_path check and, if missing, echo an
error with the missing header path and exit 1; ensure you create a clear message
and suggest the same curl/tar extraction hint used for lib_path so the script
fails fast and reports the actionable missing header instead of letting `go
build` fail later.
| fileContent, err := os.ReadFile(filename) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to read dsl file: %w", err) | ||
| } |
There was a problem hiding this comment.
Fix the misleading file-read error text.
Line 3263 says "failed to read dsl file" even though this branch reads the user-selected input document. When local parsing fails on a missing DOCX/PDF/etc, the CLI will point users at the wrong file.
Suggested fix
fileContent, err := os.ReadFile(filename)
if err != nil {
- return nil, fmt.Errorf("failed to read dsl file: %w", err)
+ return nil, fmt.Errorf("failed to read file: %w", err)
}📝 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.
| fileContent, err := os.ReadFile(filename) | |
| if err != nil { | |
| return nil, fmt.Errorf("failed to read dsl file: %w", err) | |
| } | |
| fileContent, err := os.ReadFile(filename) | |
| if err != nil { | |
| return nil, fmt.Errorf("failed to read file: %w", err) | |
| } |
🤖 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_command.go` around lines 3261 - 3264, The error message for
the os.ReadFile failure is misleading: update the fmt.Errorf call that currently
uses "failed to read dsl file" so it reflects the actual user-selected input
document (use filename or a phrase like "input file" / "user-selected document")
and include the filename and wrapped error (the os.ReadFile call and variable
filename identify the spot to change).
| func (p *DOCParser) Parse(filename string, data []byte) error { | ||
| fmt.Printf("Parsing DOC file: %s\n", filename) | ||
| return nil |
There was a problem hiding this comment.
Placeholder parsers are registered as supported but never parse anything.
DOCParser in internal/ingestion/parser/doc_parser.go, PDFParser in internal/ingestion/parser/pdf_parser.go, PPTParser in internal/ingestion/parser/ppt_parser.go, XLSParser in internal/ingestion/parser/xls_parser.go, and XLSXParser in internal/ingestion/parser/xlsx_parser.go all ignore data and return nil. Because UserParseLocalFile treats nil as success, these formats now look fully supported even though the command only logs a filename. Either implement extraction before wiring them in, or return a clear "not implemented" error until they are real.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/ingestion/parser/doc_parser.go` around lines 28 - 30, The
placeholder parsers (e.g., DOCParser.Parse, PDFParser.Parse, PPTParser.Parse,
XLSParser.Parse, XLSXParser.Parse) currently ignore the input data and return
nil, making unsupported formats appear successful; update each Parse method to
either implement actual extraction or explicitly return a not-implemented error
(e.g., errors.New("parser not implemented for <format>")) so UserParseLocalFile
won't treat a no-op as success—locate the Parse methods in the respective types
(DOCParser.Parse, PDFParser.Parse, PPTParser.Parse, XLSParser.Parse,
XLSXParser.Parse) and replace the println+nil with either working extraction
logic or a clear error return.
| import ( | ||
| "fmt" | ||
|
|
||
| officeOxide "github.com/yfedoseev/office_oxide/go" | ||
| ) |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
fd -a 'docx_parser.go|type.go|go.mod|build.sh'
echo
rg -n --glob 'go.mod' --glob 'build.sh' --glob 'internal/**/*.go' \
'office_oxide|//go:build|CGO_CFLAGS|CGO_LDFLAGS|NewDOCXParser|FileTypeDOCX'Repository: infiniflow/ragflow
Length of output: 2937
Isolate office_oxide behind a build tag (or add a !cgo DOCX fallback)
internal/ingestion/parser/docx_parser.go unconditionally imports github.com/yfedoseev/office_oxide/go, and internal/ingestion/parser/type.go wires utility.FileTypeDOCX to NewDOCXParser(), making the parser package’s build depend on native/CGO office_oxide even if DOCX parsing isn’t used. build.sh sets up native office_oxide + CGO flags, but there are no //go:build guards around the DOCX implementation.
Add //go:build cgo to the DOCX parser and a //go:build !cgo stub/fallback (and/or factory gating) so non-CGO environments still compile.
🧰 Tools
🪛 golangci-lint (2.12.2)
[error] 22-22: could not import github.com/yfedoseev/office_oxide/go (-: build constraints exclude all Go files in /home/jailuser/.cache/go/.go-mod-cache/github.com/yfedoseev/office_oxide/[email protected])
(typecheck)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/ingestion/parser/docx_parser.go` around lines 19 - 23, The DOCX
parser imports cgo-only office_oxide unconditionally; add build tags to isolate
it: mark the existing DOCX implementation file (containing NewDOCXParser and any
direct use of officeOxide) with a "//go:build cgo" tag and create a companion
stub file with "//go:build !cgo" that provides a fallback NewDOCXParser (or
returns an error/not-implemented) so the package builds without CGO; also ensure
the factory wiring in internal/ingestion/parser/type.go checks the returned
value/error from NewDOCXParser (or gates registration) so non-cgo builds don’t
register a non-functional DOCX parser.
Source: Linters/SAST tools
| func (p *PPTXParser) Parse(filename string, data []byte) error { | ||
| fmt.Printf("Parsing PPTX file: %s\n", filename) | ||
| return nil |
There was a problem hiding this comment.
Fail fast until PPTX parsing is actually implemented.
Parse ignores data, only logs the filename, and returns nil. In the CLI flow that means every .pptx file is reported as successfully parsed even though nothing was extracted.
If the implementation is still a placeholder, return an error here (or stop registering FileTypePPTX in GetParser) instead of silently succeeding.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/ingestion/parser/pptx_parser.go` around lines 28 - 30,
PPTXParser.Parse currently ignores the input and returns nil; stop silently
succeeding by returning a clear not-implemented error from PPTXParser.Parse
(e.g., return fmt.Errorf("PPTX parsing not implemented")) so callers fail fast,
or alternatively remove FileTypePPTX from the parser registry in GetParser until
real parsing is implemented; update any tests/usage accordingly to expect the
error instead of a successful parse.
| func GetFileType(filename string) FileType { | ||
|
|
||
| ext := filepath.Ext(filename) | ||
| var suffix string | ||
| if len(ext) > 0 && ext[0] == '.' { | ||
| suffix = strings.ToLower(ext[1:]) | ||
| } else { | ||
| suffix = strings.ToLower(ext) | ||
| } | ||
|
|
||
| switch suffix { | ||
| case "pdf": | ||
| return FileTypePDF | ||
| case "xls": | ||
| return FileTypeXLS | ||
| case "xlsx": | ||
| return FileTypeXLSX | ||
| case "doc": | ||
| return FileTypeDOC | ||
| case "docx": | ||
| return FileTypeDOCX | ||
| case "ppt": | ||
| return FileTypePPT | ||
| case "pptx": | ||
| return FileTypePPTX | ||
| default: | ||
| return FileTypeOTHER | ||
| } |
There was a problem hiding this comment.
Preserve the existing non-Office classifications in GetFileType.
UserParseLocalFile now drives parser selection through GetFileType(...), but this switch only recognizes PDF and the Office extensions. Extensions that FilenameType(...) still treats as parseable/document-like (txt, md, json, csv, etc.) or media (jpg, png, mp3, ...) now collapse to other, so the CLI rejects them before parsing starts.
Please keep the new specific Office mappings, but fall back to the broader FilenameType(...) classification for everything else.
🤖 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/utility/file.go` around lines 60 - 87, Update GetFileType to keep
the explicit Office and PDF cases but for any unrecognized suffix call and
return the broader classification from FilenameType(filename) instead of
returning FileTypeOTHER; locate the switch in GetFileType and replace the
default branch (and possibly other non-office branches) so that when suffix
isn't one of "pdf","xls","xlsx","doc","docx","ppt","pptx" it delegates to
FilenameType to preserve classifications like txt, md, json, csv, jpg, png, mp3,
etc.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15976 +/- ##
=======================================
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?
Type of change