Repository navigation
Feat: More APIs for compiler list and deletion of compilation result. - #17425
Conversation
📝 WalkthroughWalkthroughAdds compilation template groups to agent listings, introduces dataset-structure deletion APIs, adjusts textual retrieval matching and backend filter helpers based on vector similarity, and updates navigation tool descriptions. ChangesMerged agent listing
Dataset structure deletion
Similarity-aware retrieval
Navigation tool metadata
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant list_agents
participant UserCanvasService
participant CompilationTemplateGroupService
Client->>list_agents: Request without canvas filters
list_agents->>UserCanvasService: Fetch all matching agents
list_agents->>CompilationTemplateGroupService: Fetch tenant template groups
list_agents->>Client: Return sorted and paginated canvas items
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ 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.
Actionable comments posted: 4
🧹 Nitpick comments (1)
api/apps/restful_apis/agent_api.py (1)
705-752: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd focused coverage for merge-mode contracts.
Cover merged ordering/pagination, group inclusion with default owners, and exclusion of caller-owned groups when
owner_idsomitstenant_id.As per coding guidelines, “Preserve valid behavior with focused tests.”
🤖 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/agent_api.py` around lines 705 - 752, Add focused tests for the merge-mode branch in the agent listing handler, covering global update_time ordering with pagination, inclusion of compilation template groups when using default owners, and exclusion of caller-owned groups when owner_ids omits tenant_id. Reuse existing service mocks and fixtures to verify the returned canvas items and total without changing production behavior.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.
Inline comments:
In `@api/apps/restful_apis/agent_api.py`:
- Around line 727-730: Update the group-fetching branch around
CompilationTemplateGroupService.list_saved to first verify that tenant_id is
included in effective_owner_ids. Only fetch and add caller-owned groups when
authorized owner_ids contains tenant_id; otherwise skip this branch so excluded
owners cannot contribute results.
- Around line 729-733: Update the exception handling around
CompilationTemplateGroupService.list_saved in the agent-listing flow so failures
are not converted into an empty groups result. Keep logging the exception, then
re-raise it or use the established error-response path so the request reports
failure instead of returning a partial successful listing.
In `@api/apps/restful_apis/dataset_api.py`:
- Around line 758-759: Update the wipe argument parsing near wipe_arg and wipe
so only explicit true or false aliases are accepted; preserve the corresponding
boolean conversion, but return RetCode.ARGUMENT_ERROR for empty or unrecognized
values instead of defaulting them to true.
In `@rag/nlp/search.py`:
- Around line 596-597: The search flow currently passes only a boolean derived
from vector_similarity_weight, so backends lose the caller’s numeric weight.
Update the owning search path around search() and its FusionExpr construction to
propagate the raw vector_similarity_weight, apply one consistent 0.8 boundary
policy, and log the derived decision at debug level. Add focused coverage for
weights 0.79, 0.8, and 0.81.
---
Nitpick comments:
In `@api/apps/restful_apis/agent_api.py`:
- Around line 705-752: Add focused tests for the merge-mode branch in the agent
listing handler, covering global update_time ordering with pagination, inclusion
of compilation template groups when using default owners, and exclusion of
caller-owned groups when owner_ids omits tenant_id. Reuse existing service mocks
and fixtures to verify the returned canvas items and total without changing
production behavior.
🪄 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 Plus
Run ID: 8ea1906b-41d3-425e-a058-ffc069d1ad2a
📒 Files selected for processing (6)
api/apps/restful_apis/agent_api.pyapi/apps/restful_apis/dataset_api.pyapi/apps/services/dataset_api_service.pyrag/nlp/search.pyrag/utils/es_conn.pyrag/utils/infinity_conn.py
| # Groups are owner-only (no team sharing), so they're scoped to the | ||
| # caller. Keyword filters the group name; scope is left unfiltered. | ||
| try: | ||
| groups = CompilationTemplateGroupService.list_saved(tenant_id, keywords, "", order_by, desc) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Honor owner_ids before adding caller-owned groups.
When an authorized owner_ids request excludes tenant_id, agents are filtered correctly but this branch still adds the caller’s groups. Only fetch groups when tenant_id in effective_owner_ids; otherwise this filter returns items from an unrequested owner.
🤖 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/agent_api.py` around lines 727 - 730, Update the
group-fetching branch around CompilationTemplateGroupService.list_saved to first
verify that tenant_id is included in effective_owner_ids. Only fetch and add
caller-owned groups when authorized owner_ids contains tenant_id; otherwise skip
this branch so excluded owners cannot contribute results.
| try: | ||
| groups = CompilationTemplateGroupService.list_saved(tenant_id, keywords, "", order_by, desc) | ||
| except Exception: | ||
| logging.exception("list_agents: compilation template group merge failed for tenant=%s", tenant_id) | ||
| groups = [] |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Do not turn a group-query failure into a successful partial listing.
A database or service failure is logged but returned as groups = [], so clients receive 200 with silently missing items. Log the error and re-raise it (or return the established error response) instead.
Proposed fix
except Exception:
logging.exception("list_agents: compilation template group merge failed for tenant=%s", tenant_id)
- groups = []
+ raise📝 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.
| try: | |
| groups = CompilationTemplateGroupService.list_saved(tenant_id, keywords, "", order_by, desc) | |
| except Exception: | |
| logging.exception("list_agents: compilation template group merge failed for tenant=%s", tenant_id) | |
| groups = [] | |
| try: | |
| groups = CompilationTemplateGroupService.list_saved(tenant_id, keywords, "", order_by, desc) | |
| except Exception: | |
| logging.exception("list_agents: compilation template group merge failed for tenant=%s", tenant_id) | |
| raise |
🤖 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/agent_api.py` around lines 729 - 733, Update the
exception handling around CompilationTemplateGroupService.list_saved in the
agent-listing flow so failures are not converted into an empty groups result.
Keep logging the exception, then re-raise it or use the established
error-response path so the request reports failure instead of returning a
partial successful listing.
| wipe_arg = (request.args.get("wipe", "true") or "true").strip().lower() | ||
| wipe = wipe_arg not in ("false", "0", "no", "off") |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Reject malformed wipe values instead of treating them as true.
Lines 758-759 convert any value outside the false aliases to True; for example, wipe=typo or wipe= can unexpectedly delete persisted artifacts. Accept explicit true/false values and return RetCode.ARGUMENT_ERROR for anything else.
Suggested fix
- wipe_arg = (request.args.get("wipe", "true") or "true").strip().lower()
- wipe = wipe_arg not in ("false", "0", "no", "off")
+ raw_wipe = request.args.get("wipe")
+ if raw_wipe is None:
+ wipe = True
+ else:
+ wipe_arg = raw_wipe.strip().lower()
+ if wipe_arg in ("true", "1", "yes", "on"):
+ wipe = True
+ elif wipe_arg in ("false", "0", "no", "off"):
+ wipe = False
+ else:
+ return get_error_data_result(
+ message="`wipe` must be one of: true, false.",
+ code=RetCode.ARGUMENT_ERROR,
+ )📝 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.
| wipe_arg = (request.args.get("wipe", "true") or "true").strip().lower() | |
| wipe = wipe_arg not in ("false", "0", "no", "off") | |
| raw_wipe = request.args.get("wipe") | |
| if raw_wipe is None: | |
| wipe = True | |
| else: | |
| wipe_arg = raw_wipe.strip().lower() | |
| if wipe_arg in ("true", "1", "yes", "on"): | |
| wipe = True | |
| elif wipe_arg in ("false", "0", "no", "off"): | |
| wipe = False | |
| else: | |
| return get_error_data_result( | |
| message="`wipe` must be one of: true, false.", | |
| code=RetCode.ARGUMENT_ERROR, | |
| ) |
🤖 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/dataset_api.py` around lines 758 - 759, Update the wipe
argument parsing near wipe_arg and wipe so only explicit true or false aliases
are accepted; preserve the corresponding boolean conversion, but return
RetCode.ARGUMENT_ERROR for empty or unrecognized values instead of defaulting
them to true.
| min_match = vector_similarity_weight < 0.8 | ||
| sres = await self.search(req, idx_names, kb_ids, embd_mdl, highlight, rank_feature=rank_feature, min_match=min_match) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Propagate the numeric vector weight, not only the boolean.
search() still creates FusionExpr(..., {"weights": "0.001,1"}) at Line 210. Consequently, ES and Infinity infer 1.0 and always take their high-vector-weight filter path, even when the caller supplied (for example) 0.3. Pass the raw weight through the owning search path (or otherwise provide it directly to the backends), use one consistent 0.8 boundary policy, and add focused coverage for 0.79, 0.8, and 0.81. Include the derived decision in debug logging.
🤖 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/nlp/search.py` around lines 596 - 597, The search flow currently passes
only a boolean derived from vector_similarity_weight, so backends lose the
caller’s numeric weight. Update the owning search path around search() and its
FusionExpr construction to propagate the raw vector_similarity_weight, apply one
consistent 0.8 boundary policy, and log the derived decision at debug level. Add
focused coverage for weights 0.79, 0.8, and 0.81.
Source: Coding guidelines
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17425 +/- ##
==========================================
- Coverage 94.56% 90.65% -3.91%
==========================================
Files 10 10
Lines 717 717
Branches 118 118
==========================================
- Hits 678 650 -28
- Misses 25 39 +14
- Partials 14 28 +14 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
api/apps/restful_apis/agent_api.py (1)
738-744: 🚀 Performance & Scalability | 🔵 TrivialBound the merge-mode full scan.
This disables SQL pagination and materializes every matching agent before sorting and slicing. For large tenants, request latency and memory usage will grow with the entire dataset rather than
page_size; consider a bounded merge or database-side pagination strategy.🤖 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/agent_api.py` around lines 738 - 744, Update the merge-mode retrieval around UserCanvasService.get_by_tenant_ids so it does not disable SQL pagination and materialize every matching agent. Use a bounded/database-side pagination strategy that fetches only the candidates needed for the requested page while preserving the required global ordering and Python slicing behavior.
🤖 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 `@api/apps/restful_apis/agent_api.py`:
- Around line 725-727: Validate page_number before the slicing logic in both
pagination paths: preserve page_number=0 as “no pagination,” but reject negative
values before calculating start or slicing groups. Apply the same validation
consistently to the code around both referenced pagination blocks.
---
Nitpick comments:
In `@api/apps/restful_apis/agent_api.py`:
- Around line 738-744: Update the merge-mode retrieval around
UserCanvasService.get_by_tenant_ids so it does not disable SQL pagination and
materialize every matching agent. Use a bounded/database-side pagination
strategy that fetches only the candidates needed for the requested page while
preserving the required global ordering and Python slicing behavior.
🪄 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 Plus
Run ID: 712928e1-86f8-46e6-9237-b1d4ac7c17f3
📒 Files selected for processing (2)
api/apps/restful_apis/agent_api.pyrag/advanced_rag/harness/tools/__init__.py
| if page_number and items_per_page: | ||
| start = (page_number - 1) * items_per_page | ||
| groups = groups[start : start + items_per_page] |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate and inspect the relevant API code around the reported lines.
if [ -f api/apps/restful_apis/agent_api.py ]; then
echo "== file exists =="
wc -l api/apps/restful_apis/agent_api.py
echo "== lines 700-790 =="
sed -n '700,790p' api/apps/restful_apis/agent_api.py | nl -ba -v700
else
echo "api/apps/restful_apis/agent_api.py not found"
fd -a 'agent_api.py' .
fiRepository: infiniflow/ragflow
Length of output: 274
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== lines 700-790 with cat -n =="
cat -n api/apps/restful_apis/agent_api.py | sed -n '700,790p'
echo "== deterministic slice probe =="
python3 - <<'PY'
def page_slice(groups, page_number, items_per_page):
if page_number and items_per_page:
start = (page_number - 1) * items_per_page
groups = groups[start : start + items_per_page]
return groups
group = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
items = 5
for page in [-1, 0, 1, 2, 100]:
print(f"{page}: {page_slice(group, page, items)!r}")
PYRepository: infiniflow/ragflow
Length of output: 4746
Reject negative page numbers before slicing.
page_number=-1 makes start = (page_number - 1) * items_per_page, so the slice starts from the list tail and returns the wrong results. Add validation so page 0 continues to mean “no pagination” while negative pages are rejected.
Also applies to: lines 725-727 and 774-776.
🤖 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/agent_api.py` around lines 725 - 727, Validate
page_number before the slicing logic in both pagination paths: preserve
page_number=0 as “no pagination,” but reject negative values before calculating
start or slicing groups. Apply the same validation consistently to the code
around both referenced pagination blocks.
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/utils/es_conn.py`:
- Line 258: Wire the similarity-aware filtering path into both retrieval
backends: in rag/utils/es_conn.py at lines 258-258, pass
_build_knn_filter_query(bool_query, vector_similarity_weight) to s.knn; in
rag/utils/infinity_conn.py at lines 218-218, compute vector_similarity_weight
with _vector_similarity_weight(match_expressions), and at lines 249-253 build
and assign the dense filter via _build_dense_filter(...). Remove the
commented-out filtering implementations so each backend uses one active path.
🪄 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 Plus
Run ID: fc84c84a-a01d-4749-b51e-69f99d090301
📒 Files selected for processing (2)
rag/utils/es_conn.pyrag/utils/infinity_conn.py
| m.topn * 2, | ||
| query_vector=list(m.embedding_data), | ||
| filter=bool_query.to_dict(), | ||
| filter=bool_query.to_dict(), # filter=_build_knn_filter_query(bool_query, vector_similarity_weight), |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Wire the similarity-aware filtering implementation into both active retrieval paths.
The new filtering logic is currently dead code in both backends, leaving the previous hard-filter behavior active and causing dense-only Infinity searches to skip conditions.
rag/utils/es_conn.py#L258-L258: pass_build_knn_filter_query(bool_query, vector_similarity_weight)tos.knn.rag/utils/infinity_conn.py#L218-L218: computevector_similarity_weightwith_vector_similarity_weight(match_expressions).rag/utils/infinity_conn.py#L249-L253: build and assign the dense filter with_build_dense_filter(...), then remove the commented-out implementation.
As per coding guidelines, converge on one implementation path and remove commented-out code.
📍 Affects 2 files
rag/utils/es_conn.py#L258-L258(this comment)rag/utils/infinity_conn.py#L218-L218
🤖 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/utils/es_conn.py` at line 258, Wire the similarity-aware filtering path
into both retrieval backends: in rag/utils/es_conn.py at lines 258-258, pass
_build_knn_filter_query(bool_query, vector_similarity_weight) to s.knn; in
rag/utils/infinity_conn.py at lines 218-218, compute vector_similarity_weight
with _vector_similarity_weight(match_expressions), and at lines 249-253 build
and assign the dense filter via _build_dense_filter(...). Remove the
commented-out filtering implementations so each backend uses one active path.
Source: Coding guidelines
Summary
More APIs for comliler list and deletion of compilation result.