Repository navigation
Refactor: Remove redundant functions - and fix run_raptor to do_raptor - #16671
Conversation
📝 WalkthroughWalkthroughThis PR centralizes compilation template group ID handling across three parser_config consumers, adjusts chunk_post_processor import scope and RAPTOR gating, and removes the built-in exclusion from saved compilation template queries. ChangesShared compilation template group ID helper adoption
Saved compilation template query scope
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
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.
🧹 Nitpick comments (3)
api/apps/restful_apis/document_api.py (1)
81-93: 📐 Maintainability & Code Quality | 🔵 TrivialAPI layer now reaches into task-executor internals.
_compilation_template_group_id_changedand_normalize_parser_config_compilation_template_group_idsboth lazily import a private (_-prefixed) helper fromrag.svr.task_executor_refactor.chunk_post_processor. Reaching from the REST API layer directly into task-executor internals (rather than a service underapi/apps/services/) inverts the intended dependency direction and the need for a lazy/local import in two places strongly suggests an underlying circular-import coupling between the two packages. See the root-cause comment onchunk_post_processor.pyproposing extraction of this helper into a neutral shared module.As per coding guidelines, "Implement RESTful API routes in
api/apps/restful_apis/using Pydantic request validation, a service layer inapi/apps/services/, and register them under/api/v1."🤖 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 `@api/apps/restful_apis/document_api.py` around lines 81 - 93, The REST API helpers _compilation_template_group_id_changed and _normalize_parser_config_compilation_template_group_ids are importing a private task-executor helper from chunk_post_processor, which creates an inverted dependency and likely a circular import. Move the shared parser-config group-id logic into a neutral module or an api/apps/services/ service helper, then update these two functions to import/use that shared symbol instead of reaching into rag.svr.task_executor_refactor internals.Source: Coding guidelines
rag/svr/task_executor_refactor/chunk_post_processor.py (1)
918-919: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy liftExtract shared parser_config helpers into a neutral module to avoid scattered local imports.
_parser_config_compilation_template_group_idsand_parser_config_compilation_template_idsare private (_-prefixed) helpers defined in this "processor" module but are now cross-imported bydocument_api.py,task_handler.py, anddataset_wiki_generator.py, each needing a function-scoped import to dodge circular imports. This is a known circular-import workaround, not a fix — the underlying coupling betweenapi.apps.restful_apisandrag.svr.task_executor_refactorpersists and will keep forcing local imports as more consumers appear. Consider moving these helpers (dropping the leading underscore since they're now a public cross-module contract) into a small, dependency-free shared module (e.g.rag/svr/task_executor_refactor/parser_config_utils.py) that all four files can import at module scope.🤖 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 `@rag/svr/task_executor_refactor/chunk_post_processor.py` around lines 918 - 919, The parser_config helper functions are being cross-imported with function-scoped imports to work around a circular dependency, which leaves the coupling in place. Move _parser_config_compilation_template_group_ids and _parser_config_compilation_template_ids out of chunk_post_processor.py into a small dependency-free shared module such as parser_config_utils, rename them to public helpers if needed, and update document_api.py, task_handler.py, dataset_wiki_generator.py, and chunk_post_processor.py to import them at module scope.rag/svr/task_executor_refactor/dataset_wiki_generator.py (1)
91-109: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd logging when a configured group resolves to no templates.
The new multi-group aggregation silently continues if
resolve_template_idsreturns[]for a group (e.g., stale/invalid group id), making such cases hard to diagnose in production logs.As per coding guidelines, "Add logging for new flows."
📝 Suggested logging addition
for group_id in _parser_config_compilation_template_group_ids(parser_config): - for template_id in CompilationTemplateGroupService.resolve_template_ids(group_id, tenant_id): + resolved = CompilationTemplateGroupService.resolve_template_ids(group_id, tenant_id) + if not resolved: + logging.warning("compilation template group %s resolved to no templates", group_id) + for template_id in resolved: if template_id in seen: continue seen.add(template_id) template_ids.append(template_id)🤖 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 `@rag/svr/task_executor_refactor/dataset_wiki_generator.py` around lines 91 - 109, The multi-group aggregation in _parser_config_compilation_template_ids currently skips over groups that resolve to no templates without any trace, which makes stale or invalid group IDs hard to diagnose. Add a log statement inside the loop over _parser_config_compilation_template_group_ids(parser_config) when CompilationTemplateGroupService.resolve_template_ids(group_id, tenant_id) returns an empty list, including the group_id and tenant_id in the message and keeping the existing deduplication/append flow unchanged.Source: Coding guidelines
🤖 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.
Nitpick comments:
In `@api/apps/restful_apis/document_api.py`:
- Around line 81-93: The REST API helpers _compilation_template_group_id_changed
and _normalize_parser_config_compilation_template_group_ids are importing a
private task-executor helper from chunk_post_processor, which creates an
inverted dependency and likely a circular import. Move the shared parser-config
group-id logic into a neutral module or an api/apps/services/ service helper,
then update these two functions to import/use that shared symbol instead of
reaching into rag.svr.task_executor_refactor internals.
In `@rag/svr/task_executor_refactor/chunk_post_processor.py`:
- Around line 918-919: The parser_config helper functions are being
cross-imported with function-scoped imports to work around a circular
dependency, which leaves the coupling in place. Move
_parser_config_compilation_template_group_ids and
_parser_config_compilation_template_ids out of chunk_post_processor.py into a
small dependency-free shared module such as parser_config_utils, rename them to
public helpers if needed, and update document_api.py, task_handler.py,
dataset_wiki_generator.py, and chunk_post_processor.py to import them at module
scope.
In `@rag/svr/task_executor_refactor/dataset_wiki_generator.py`:
- Around line 91-109: The multi-group aggregation in
_parser_config_compilation_template_ids currently skips over groups that resolve
to no templates without any trace, which makes stale or invalid group IDs hard
to diagnose. Add a log statement inside the loop over
_parser_config_compilation_template_group_ids(parser_config) when
CompilationTemplateGroupService.resolve_template_ids(group_id, tenant_id)
returns an empty list, including the group_id and tenant_id in the message and
keeping the existing deduplication/append flow unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b7f68e9c-ab95-4f50-be2e-94bd12cce675
📒 Files selected for processing (4)
api/apps/restful_apis/document_api.pyrag/svr/task_executor_refactor/chunk_post_processor.pyrag/svr/task_executor_refactor/dataset_wiki_generator.pyrag/svr/task_executor_refactor/task_handler.py
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16671 +/- ##
=======================================
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:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@rag/svr/task_executor_refactor/chunk_post_processor.py`:
- Line 1226: The RAPTOR post-processing gate is checking the wrong config key,
so per-doc RAPTOR can be skipped even when the documented setting is enabled.
Update the `chunk_post_processor` logic around the `do_raptor` check to use
`use_raptor` instead, and if needed keep the default disabled by setting
`use_raptor` to `False` in this hook; make the change in the same RAPTOR config
path used by the post-processing flow.
🪄 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: d70655cd-0b6a-4f52-87e5-58ea334805b7
📒 Files selected for processing (1)
rag/svr/task_executor_refactor/chunk_post_processor.py
| async def _maybe_run_raptor(): | ||
| raptor_cfg = (ctx.parser_config or {}).get("raptor") or {} | ||
| if not raptor_cfg.get("use_raptor"): | ||
| if not raptor_cfg.get("do_raptor"): |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check whether "do_raptor" is set anywhere in the codebase (API, frontend, config templates)
rg -n 'do_raptor' --type=py --type=go --type=ts --type=js
rg -n 'use_raptor' --type=py -C2Repository: infiniflow/ragflow
Length of output: 156
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- target file context ---'
python3 - <<'PY'
from pathlib import Path
p = Path('rag/svr/task_executor_refactor/chunk_post_processor.py')
lines = p.read_text().splitlines()
for start in (1190, 1210, 1238):
print(f'\n## lines {start}-{min(start+40, len(lines))}')
for i in range(start, min(start+40, len(lines))+1):
print(f"{i:5d}: {lines[i-1]}")
PY
echo '--- search for raptor-related keys ---'
rg -n --hidden --glob '!**/.git/**' 'do_raptor|use_raptor|raptor_cfg|parser_config|RAPTOR' .
echo '--- file list for likely config/docs/go files ---'
git ls-files | rg '(^internal/.*|parser_config|raptor|chunk_post_processor|README|docs|openapi|schema|config)'Repository: infiniflow/ragflow
Length of output: 50375
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- chunk_post_processor context ---'
sed -n '1200,1245p' rag/svr/task_executor_refactor/chunk_post_processor.py
echo '--- refactor tree use_raptor occurrences ---'
rg -n 'use_raptor|do_raptor' rag/svr/task_executor_refactor api/utils/validation_utils.py api/utils/api_utils.py
echo '--- refactor tree raptor config gate occurrences ---'
rg -n 'get\("raptor", \{\}\)\.get\("use_raptor"|get\("do_raptor"' rag/svr/task_executor_refactorRepository: infiniflow/ragflow
Length of output: 3763
Keep the RAPTOR gate on use_raptor. do_raptor doesn’t match the config shape used elsewhere, so this post-processing hook will silently skip per-doc RAPTOR even when callers set the documented flag. If the goal is to default it off, keep use_raptor and default it to False here instead.
🤖 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 `@rag/svr/task_executor_refactor/chunk_post_processor.py` at line 1226, The
RAPTOR post-processing gate is checking the wrong config key, so per-doc RAPTOR
can be skipped even when the documented setting is enabled. Update the
`chunk_post_processor` logic around the `do_raptor` check to use `use_raptor`
instead, and if needed keep the default disabled by setting `use_raptor` to
`False` in this hook; make the change in the same RAPTOR config path used by the
post-processing flow.
Source: Coding guidelines
Follow on: #16515