Skip to content

Refactor: Remove redundant functions - and fix run_raptor to do_raptor - #16671

Merged
KevinHuSh merged 3 commits into
infiniflow:mainfrom
KevinHuSh:main
Jul 6, 2026
Merged

KevinHuSh merged 3 commits into
infiniflow:mainfrom
KevinHuSh:main

Conversation

@KevinHuSh

@KevinHuSh KevinHuSh commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Follow on: #16515

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. ☯️ refactor Pull request that refactor/refine code 🌈 python Pull requests that update Python code labels Jul 6, 2026
@KevinHuSh KevinHuSh added the ci Continue Integration label Jul 6, 2026
@KevinHuSh
KevinHuSh marked this pull request as draft July 6, 2026 09:12
@KevinHuSh
KevinHuSh marked this pull request as ready for review July 6, 2026 09:12
@coderabbitai

coderabbitai Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

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

Changes

Shared compilation template group ID helper adoption

Layer / File(s) Summary
Document API normalization using shared helper
api/apps/restful_apis/document_api.py
Replaces local parser_config group-id extraction with a lazy import of the shared helper for change detection and normalization.
Task handler template ID resolution refactor
rag/svr/task_executor_refactor/task_handler.py
Removes the local group-id parser and delegates parser_config group resolution to the shared helper before resolving template IDs.
Dataset wiki generator multi-group resolution
rag/svr/task_executor_refactor/dataset_wiki_generator.py
Updates the note and resolves template IDs from all parser_config group IDs, deduplicating results across groups.
chunk_post_processor import scope cleanup
rag/svr/task_executor_refactor/chunk_post_processor.py
Moves _compilation_template_kind into local scope inside run_document_structure_compile and removes an outdated comment.
RAPTOR config key change
rag/svr/task_executor_refactor/chunk_post_processor.py
Changes the RAPTOR enablement check in _maybe_run_raptor from use_raptor to do_raptor.

Saved compilation template query scope

Layer / File(s) Summary
Saved template filters without built-in exclusion
api/db/services/compilation_template_service.py
list_saved, get_saved, and name_exists now filter by tenant, status, and the existing per-query conditions without is_builtin in the base where clauses.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • infiniflow/ragflow#16515: Both PRs refactor parser_config compilation template group ID handling in document_api.py and related normalization paths.

Poem

A rabbit hopped through helper trails,
one shared path for parser tales.
The built-in gate slipped soft aside,
while template names stayed neat and wide.
Thump-thump — the burrow’s code runs bright. 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description matches the template heading but is too generic and lacks the requested background context. Expand the summary with the problem being solved, relevant background, and the main implementation changes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and related to the cleanup, though it omits the RAPTOR behavior change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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.

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

🧹 Nitpick comments (3)
api/apps/restful_apis/document_api.py (1)

81-93: 📐 Maintainability & Code Quality | 🔵 Trivial

API layer now reaches into task-executor internals.

_compilation_template_group_id_changed and _normalize_parser_config_compilation_template_group_ids both lazily import a private (_-prefixed) helper from rag.svr.task_executor_refactor.chunk_post_processor. Reaching from the REST API layer directly into task-executor internals (rather than a service under api/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 on chunk_post_processor.py proposing 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 in api/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 lift

Extract shared parser_config helpers into a neutral module to avoid scattered local imports.

_parser_config_compilation_template_group_ids and _parser_config_compilation_template_ids are private (_-prefixed) helpers defined in this "processor" module but are now cross-imported by document_api.py, task_handler.py, and dataset_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 between api.apps.restful_apis and rag.svr.task_executor_refactor persists 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 win

Add logging when a configured group resolves to no templates.

The new multi-group aggregation silently continues if resolve_template_ids returns [] 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

📥 Commits

Reviewing files that changed from the base of the PR and between 57625c9 and d37bf18.

📒 Files selected for processing (4)
  • api/apps/restful_apis/document_api.py
  • rag/svr/task_executor_refactor/chunk_post_processor.py
  • rag/svr/task_executor_refactor/dataset_wiki_generator.py
  • rag/svr/task_executor_refactor/task_handler.py

@codecov

codecov Bot commented Jul 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (98189cd) to head (72b0c96).
⚠️ Report is 5 commits behind head on main.

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

@KevinHuSh
KevinHuSh requested a review from yingfeng July 6, 2026 09:45
@KevinHuSh KevinHuSh changed the title Remove redundant functions. Refactor: Remove redundant functions. Jul 6, 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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2820308 and 72b0c96.

📒 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"):

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.

🗄️ 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 -C2

Repository: 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_refactor

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

@KevinHuSh
KevinHuSh merged commit 52f985f into infiniflow:main Jul 6, 2026
3 checks passed
@wangq8 wangq8 changed the title Refactor: Remove redundant functions. Refactor: Remove redundant functions - and fix run_raptor to do_raptor Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 🌈 python Pull requests that update Python code ☯️ refactor Pull request that refactor/refine code 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