Skip to content

Refactor : Allow search multiple datasets - #14685

Merged
wangq8 merged 2 commits into
infiniflow:mainfrom
wangq8:refactor/allow-search-multiple-datasets
May 8, 2026
Merged

wangq8 merged 2 commits into
infiniflow:mainfrom
wangq8:refactor/allow-search-multiple-datasets

Conversation

@wangq8

@wangq8 wangq8 commented May 8, 2026 •

Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

Refactor : Allow search multiple datasets

  1. support /datasets/search
  2. get rid of /graph/search, use /graph

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • Refactoring

@coderabbitai

coderabbitai Bot commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR introduces a new POST /datasets/search endpoint to support searching across multiple datasets simultaneously, backed by a new search_datasets service function. The single-dataset search handler is refactored to reuse this unified implementation. Knowledge-graph routing is consolidated to use a base /graph path instead of /graph/search.

Changes

Multi-Dataset Search Feature

Layer / File(s) Summary
Request/Response Contract
api/utils/validation_utils.py
New SearchDatasetsReq Pydantic model with required dataset_ids list and standard search parameters (question, pagination, thresholds, KG/rerank flags, metadata filters).
Route Handler & Imports
api/apps/restful_apis/dataset_api.py
Import SearchDatasetsReq and add POST /datasets/search handler that validates requests and delegates to dataset_api_service.search_datasets.
Multi-Dataset Search Service
api/apps/services/dataset_api_service.py
Implement search_datasets(tenant_id, req) with dataset access validation, embedding-model compatibility checks, metadata filtering, model bundle construction, retrieval with optional KG lookup, and post-processing.
Single-Dataset Handler Refactoring
api/apps/restful_apis/dataset_api.py
Refactor POST /datasets/<dataset_id>/search to inject dataset_ids = [dataset_id] and call unified search_datasets service instead of legacy per-dataset logic.

Knowledge-Graph Endpoint Consolidation

Layer / File(s) Summary
Endpoint Route Cleanup
api/apps/restful_apis/dataset_api.py
Remove GET /datasets/<dataset_id>/graph/search route; remaining graph endpoints start from base /graph path.
Test & Web Client Updates
test/testcases/test_http_api/common.py, web/src/utils/api.ts
Update knowledge_graph test helper and getKnowledgeGraph API utility to reference /graph endpoint instead of /graph/search.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • infiniflow/ragflow#14402: Migrated legacy retrieval test into dataset-scoped search and updated knowledge-graph routing, complementary to this multi-dataset search feature.

Suggested labels

💞 feature

Poem

🐰 A rabbit hops through datasets wide,
Searching many fields with pride,
No need to pick just one to search,
Now multiple queries find their perch!
Graph paths simplified, routes consolidated,
The search for knowledge, unified and escalated! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main feature addition: allowing search across multiple datasets. It is concise and clearly communicates the primary change.
Description check ✅ Passed The description provides the required template sections with the problem statement and type of change selected, though the problem description is brief and mirrors the title without additional context.
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.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@wangq8 wangq8 added the ci Continue Integration label May 8, 2026
@wangq8
wangq8 requested a review from euvre May 8, 2026 09:39
@wangq8
wangq8 marked this pull request as ready for review May 8, 2026 09:40
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 8, 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 `@api/apps/services/dataset_api_service.py`:
- Around line 1146-1153: The loop over tenants currently breaks after appending
the first matching tenant_id, so tenant_ids can contain at most one entry;
remove the break and instead collect all tenant.tenant_id values where
any(KnowledgebaseService.query(tenant_id=tenant.tenant_id, id=kb_id) for kb_id
in kb_ids) is True, and after the loop check if tenant_ids is empty and return
(False, "Only owner of datasets authorized for this operation.") when no tenants
matched; update the block using UserTenantService.query,
KnowledgebaseService.query, tenants, tenant_ids, and kb_ids accordingly.
🪄 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: 8a82b0fd-5632-4e80-98ac-213e1d994669

📥 Commits

Reviewing files that changed from the base of the PR and between a32ebf3 and c7380f8.

📒 Files selected for processing (5)
  • api/apps/restful_apis/dataset_api.py
  • api/apps/services/dataset_api_service.py
  • api/utils/validation_utils.py
  • test/testcases/test_http_api/common.py
  • web/src/utils/api.ts

Comment on lines +1146 to +1153
tenant_ids = []
tenants = UserTenantService.query(user_id=tenant_id)
for tenant in tenants:
if any(KnowledgebaseService.query(tenant_id=tenant.tenant_id, id=kb_id) for kb_id in kb_ids):
tenant_ids.append(tenant.tenant_id)
break
else:
return False, "Only owner of datasets authorized for this operation."

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Collect all dataset tenant IDs before retrieval

Line 1151 breaks after the first matched tenant, so tenant_ids contains at most one tenant even when kb_ids span multiple tenants. This can make multi-dataset search return incomplete results.

🔧 Proposed fix
-    tenant_ids = []
-    tenants = UserTenantService.query(user_id=tenant_id)
-    for tenant in tenants:
-        if any(KnowledgebaseService.query(tenant_id=tenant.tenant_id, id=kb_id) for kb_id in kb_ids):
-            tenant_ids.append(tenant.tenant_id)
-            break
-    else:
-        return False, "Only owner of datasets authorized for this operation."
+    joined_tenant_ids = {tenant.tenant_id for tenant in UserTenantService.query(user_id=tenant_id)}
+    required_tenant_ids = {kb.tenant_id for kb in kbs}
+    if not required_tenant_ids.issubset(joined_tenant_ids):
+        return False, "Only owner of datasets authorized for this operation."
+    tenant_ids = list(required_tenant_ids)
🤖 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/services/dataset_api_service.py` around lines 1146 - 1153, The loop
over tenants currently breaks after appending the first matching tenant_id, so
tenant_ids can contain at most one entry; remove the break and instead collect
all tenant.tenant_id values where
any(KnowledgebaseService.query(tenant_id=tenant.tenant_id, id=kb_id) for kb_id
in kb_ids) is True, and after the loop check if tenant_ids is empty and return
(False, "Only owner of datasets authorized for this operation.") when no tenants
matched; update the block using UserTenantService.query,
KnowledgebaseService.query, tenants, tenant_ids, and kb_ids accordingly.

@codecov

codecov Bot commented May 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.16%. Comparing base (decb5dc) to head (c7380f8).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14685   +/-   ##
=======================================
  Coverage   94.16%   94.16%           
=======================================
  Files          10       10           
  Lines         703      703           
  Branches      112      112           
=======================================
  Hits          662      662           
  Misses         25       25           
  Partials       16       16           

☔ View full report in Codecov by Sentry.
📢 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.

@wangq8
wangq8 merged commit 7d35e40 into infiniflow:main May 8, 2026
1 check passed
@coderabbitai coderabbitai Bot mentioned this pull request May 8, 2026
1 task done
pekar9781 pushed a commit to pekar9781/ragflow that referenced this pull request May 8, 2026
### What problem does this PR solve?

Refactor : Allow search multiple datasets
1. support /datasets/search
2. get rid of /graph/search, use /graph

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
- [x] Refactoring
Ricardo-M-L pushed a commit to Ricardo-M-L/ragflow that referenced this pull request Aug 17, 2026
### What problem does this PR solve?

Refactor : Allow search multiple datasets
1. support /datasets/search
2. get rid of /graph/search, use /graph

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
- [x] Refactoring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants