Skip to content

Consolidateion metadata summary API - #14031

Merged
yuzhichang merged 11 commits into
infiniflow:mainfrom
xugangqiang:merge-metadata-summary
Apr 10, 2026
Merged

yuzhichang merged 11 commits into
infiniflow:mainfrom
xugangqiang:merge-metadata-summary

Conversation

@xugangqiang

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Consolidation WEB API & HTTP API for document metadata summary

Before consolidation
Web API: POST /api/v1/document/metadata/summary
Http API - GET /v1/datasets/<dataset_id>/metadata/summary

After consolidation, Restful API -- GET /v1/datasets/<dataset_id>/metadata/summary

Type of change

  • Refactoring

@coderabbitai

coderabbitai Bot commented Apr 10, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Moved the metadata summary endpoint from the legacy web/API layer to a dataset-scoped RESTful handler (POST → GET), updated client SDK and frontend calls to use the new GET route with query params, and adjusted tests to reflect the new route and its behaviors.

Changes

Cohort / File(s) Summary
REST API & Server handlers
api/apps/document_app.py, api/apps/restful_apis/document_api.py, api/apps/sdk/doc.py
Removed old POST /metadata/summary handler from web/app and SDK; added GET /api/v1/datasets/<dataset_id>/metadata/summary in restful_apis/document_api.py with tenant injection, ownership check (KnowledgebaseService.accessible), optional doc_ids via query string, call to DocMetadataService.get_metadata_summary, and server-error handling.
Frontend client
web/src/utils/api.ts, web/src/services/knowledge-service.ts
Changed getMetaData to a function returning /api/v1/datasets/${datasetId}/metadata/summary; getMetaDataService now issues GET and passes doc_ids as a comma-separated query param when provided.
Tests
test/testcases/test_http_api/.../test_doc_sdk_routes_unit.py, test/testcases/test_http_api/.../test_metadata_summary.py, test/testcases/test_web_api/test_document_app/test_document_metadata.py
Removed legacy web-layer unit tests for the old POST endpoint and SDK route; added/enabled pytest-based coverage for the new GET endpoint (404, ownership denial, success, summary content assertions); renamed/refactored remaining SDK tests to drop metadata-summary coverage in favor of new tests.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Auth as Auth/ZAuth (decorators)
  participant REST as REST Handler (/datasets/:id/metadata/summary)
  participant KB as KnowledgebaseService
  participant DocMeta as DocMetadataService
  Client->>REST: GET /datasets/{dataset_id}/metadata/summary?doc_ids=1,2
  REST->>Auth: validate login & add tenant_id
  Auth-->>REST: tenant_id
  REST->>KB: accessible(kb_id=dataset_id, user_id=tenant_id)
  KB-->>REST: accessible? (true/false)
  alt accessible
    REST->>DocMeta: get_metadata_summary(dataset_id, doc_ids)
    DocMeta-->>REST: summary
    REST-->>Client: 200 { code:0, data:{ summary } }
  else not accessible
    REST-->>Client: error (ownership/access failure)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

☯️ refactor, 🧪 test

Suggested reviewers

  • JinHai-CN
  • yuzhichang
  • yongtenglei

Poem

🐰 From POST fields to GET query light,
I hop the route and do it right,
Tenant checks and summaries sing,
Tests applaud — a tidy spring,
Hooray, the metadata takes flight! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Consolidateion metadata summary API' contains a typo ('Consolidateion' instead of 'Consolidation') and is somewhat vague, but it does relate to the main change of consolidating metadata summary APIs. Fix the typo: change 'Consolidateion' to 'Consolidation' for clarity and professionalism.
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The description adequately covers the problem being solved and includes the required template section with the refactoring type clearly marked.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

@xugangqiang xugangqiang self-assigned this Apr 10, 2026
@xugangqiang xugangqiang added the ci Continue Integration label Apr 10, 2026
@xugangqiang
xugangqiang marked this pull request as ready for review April 10, 2026 05:47
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. 🐖api The modified files are located under directory 'api/apps/sdk' labels Apr 10, 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

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

150-185: Add basic logging to this new API flow.

Please add debug/warn logs for access-denied and request-shape events (and optionally successful summary retrieval size) in this new endpoint to align with repo standards.

♻️ Suggested logging additions
 async def metadata_summary(dataset_id, tenant_id):
@@
-    if not KnowledgebaseService.accessible(kb_id=dataset_id, user_id=tenant_id):
+    if not KnowledgebaseService.accessible(kb_id=dataset_id, user_id=tenant_id):
+        logging.warning("Metadata summary access denied. dataset_id=%s tenant_id=%s", dataset_id, tenant_id)
         return get_error_data_result(message=f"You don't own the dataset {dataset_id}. ")
@@
-    doc_ids_param = request.args.get("doc_ids", "")
+    doc_ids_param = request.args.get("doc_ids", "")
+    logging.debug("Metadata summary request. dataset_id=%s tenant_id=%s doc_ids_param=%s", dataset_id, tenant_id, doc_ids_param)
@@
-        summary = DocMetadataService.get_metadata_summary(dataset_id, doc_ids)
+        summary = DocMetadataService.get_metadata_summary(dataset_id, doc_ids)
+        logging.debug("Metadata summary success. dataset_id=%s fields=%s", dataset_id, len(summary or {}))
         return get_result(data={"summary": summary})

As per coding guidelines **/*.py: Add logging for new flows.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/apps/restful_apis/document_api.py` around lines 150 - 185, Add logging to
the metadata_summary flow: in the metadata_summary function, log the incoming
request shape (e.g., dataset_id and doc_ids_param) at debug level before access
checks, log an access-denied warning when
KnowledgebaseService.accessible(kb_id=dataset_id, user_id=tenant_id) returns
false, and after successfully calling
DocMetadataService.get_metadata_summary(dataset_id, doc_ids) log a debug/info
line with the size/summary keys returned; use the module logger (create a logger
= logging.getLogger(__name__) at top if missing) and include contextual fields
(dataset_id, tenant_id, doc_ids) in all log entries.
test/testcases/test_http_api/test_file_management_within_dataset/test_metadata_summary.py (1)

52-89: Add a test for doc_ids query filtering behavior.

The new endpoint contract includes optional doc_ids filtering, but current cases only validate unfiltered summary. Add one @pytest.mark.p2 case that calls metadata_summary(..., params={"doc_ids": "<subset>"}) and asserts excluded docs don’t affect counts.

Based on learnings Applies to tests/**/*.py : Add/adjust tests for behavior changes.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@test/testcases/test_http_api/test_file_management_within_dataset/test_metadata_summary.py`
around lines 52 - 89, Add a new pytest (mark p2) test in
test_metadata_summary.py that verifies the metadata_summary endpoint honors the
optional doc_ids filter: create documents via add_documents_func, set
meta_fields with update_document for each doc, then call
metadata_summary(HttpApiAuth, dataset_id, params={"doc_ids":
"<comma-separated-subset-of-document_ids>"}) and assert res["code"] == 0 and
that _summary_to_counts(res["data"]["summary"]) only includes counts from the
provided subset (i.e., excluded doc_ids do not change tag/author counts).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@api/apps/restful_apis/document_api.py`:
- Around line 179-180: The code currently builds doc_ids from request.args via
doc_ids_param and forwards raw split tokens to
DocMetadataService.get_metadata_summary, which can include whitespace or empty
strings; normalize by trimming whitespace and removing empty tokens (e.g., build
doc_ids as a list comprehension that strips each token and filters out
falsy/empty results), and convert to None if the resulting list is empty before
passing to DocMetadataService.get_metadata_summary.

---

Nitpick comments:
In `@api/apps/restful_apis/document_api.py`:
- Around line 150-185: Add logging to the metadata_summary flow: in the
metadata_summary function, log the incoming request shape (e.g., dataset_id and
doc_ids_param) at debug level before access checks, log an access-denied warning
when KnowledgebaseService.accessible(kb_id=dataset_id, user_id=tenant_id)
returns false, and after successfully calling
DocMetadataService.get_metadata_summary(dataset_id, doc_ids) log a debug/info
line with the size/summary keys returned; use the module logger (create a logger
= logging.getLogger(__name__) at top if missing) and include contextual fields
(dataset_id, tenant_id, doc_ids) in all log entries.

In
`@test/testcases/test_http_api/test_file_management_within_dataset/test_metadata_summary.py`:
- Around line 52-89: Add a new pytest (mark p2) test in test_metadata_summary.py
that verifies the metadata_summary endpoint honors the optional doc_ids filter:
create documents via add_documents_func, set meta_fields with update_document
for each doc, then call metadata_summary(HttpApiAuth, dataset_id,
params={"doc_ids": "<comma-separated-subset-of-document_ids>"}) and assert
res["code"] == 0 and that _summary_to_counts(res["data"]["summary"]) only
includes counts from the provided subset (i.e., excluded doc_ids do not change
tag/author counts).
🪄 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: 266006d8-4f9e-4ea3-9819-18c9fea12b21

📥 Commits

Reviewing files that changed from the base of the PR and between 9ce293a and eebc699.

📒 Files selected for processing (8)
  • api/apps/document_app.py
  • api/apps/restful_apis/document_api.py
  • api/apps/sdk/doc.py
  • test/testcases/test_http_api/test_file_management_within_dataset/test_doc_sdk_routes_unit.py
  • test/testcases/test_http_api/test_file_management_within_dataset/test_metadata_summary.py
  • test/testcases/test_web_api/test_document_app/test_document_metadata.py
  • web/src/services/knowledge-service.ts
  • web/src/utils/api.ts
💤 Files with no reviewable changes (3)
  • test/testcases/test_web_api/test_document_app/test_document_metadata.py
  • api/apps/sdk/doc.py
  • api/apps/document_app.py

Comment on lines +179 to +180
doc_ids_param = request.args.get("doc_ids", "")
doc_ids = doc_ids_param.split(",") if doc_ids_param else None

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 | 🟡 Minor

Normalize doc_ids query values before service call.

Line 180 currently forwards raw split values; whitespace/empty tokens can leak into DocMetadataService.get_metadata_summary(...) and cause avoidable filtering mismatches.

🛠️ Suggested normalization
-    doc_ids_param = request.args.get("doc_ids", "")
-    doc_ids = doc_ids_param.split(",") if doc_ids_param else None
+    doc_ids_param = request.args.get("doc_ids", "")
+    doc_ids = [doc_id.strip() for doc_id in doc_ids_param.split(",") if doc_id.strip()] or None
📝 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.

Suggested change
doc_ids_param = request.args.get("doc_ids", "")
doc_ids = doc_ids_param.split(",") if doc_ids_param else None
doc_ids_param = request.args.get("doc_ids", "")
doc_ids = [doc_id.strip() for doc_id in doc_ids_param.split(",") if doc_id.strip()] or None
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/apps/restful_apis/document_api.py` around lines 179 - 180, The code
currently builds doc_ids from request.args via doc_ids_param and forwards raw
split tokens to DocMetadataService.get_metadata_summary, which can include
whitespace or empty strings; normalize by trimming whitespace and removing empty
tokens (e.g., build doc_ids as a list comprehension that strips each token and
filters out falsy/empty results), and convert to None if the resulting list is
empty before passing to DocMetadataService.get_metadata_summary.

@codecov

codecov Bot commented Apr 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.66%. Comparing base (3b77238) to head (5a4f2eb).
⚠️ Report is 31 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14031      +/-   ##
==========================================
- Coverage   98.11%   96.66%   -1.45%     
==========================================
  Files          10       10              
  Lines         690      690              
  Branches      108      108              
==========================================
- Hits          677      667      -10     
- Misses          4        8       +4     
- Partials        9       15       +6     

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

@xugangqiang

Copy link
Copy Markdown
Contributor Author

@yuzhichang should be good this time. Thanks.

@xugangqiang xugangqiang changed the title Merge metadata summary Consolidateion metadata summary API Apr 10, 2026
@yuzhichang

Copy link
Copy Markdown
Member

LGTM

@yuzhichang
yuzhichang merged commit 4046a4c into infiniflow:main Apr 10, 2026
1 check passed
jasmingacic pushed a commit to jasmingacic/ragflow that referenced this pull request Apr 13, 2026
### What problem does this PR solve?

Consolidation WEB API & HTTP API for document metadata summary

Before consolidation
Web API: POST /api/v1/document/metadata/summary
Http API - GET /v1/datasets/<dataset_id>/metadata/summary

After consolidation, Restful API -- GET
/v1/datasets/<dataset_id>/metadata/summary

### Type of change

- [x] Refactoring
@xugangqiang
xugangqiang deleted the merge-metadata-summary branch April 21, 2026 12:01
jasmingacic pushed a commit to jasmingacic/ragflow that referenced this pull request Apr 23, 2026
### What problem does this PR solve?

Consolidation WEB API & HTTP API for document metadata summary

Before consolidation
Web API: POST /api/v1/document/metadata/summary
Http API - GET /v1/datasets/<dataset_id>/metadata/summary

After consolidation, Restful API -- GET
/v1/datasets/<dataset_id>/metadata/summary

### Type of change

- [x] Refactoring
jasmingacic pushed a commit to jasmingacic/ragflow that referenced this pull request Apr 27, 2026
### What problem does this PR solve?

Consolidation WEB API & HTTP API for document metadata summary

Before consolidation
Web API: POST /api/v1/document/metadata/summary
Http API - GET /v1/datasets/<dataset_id>/metadata/summary

After consolidation, Restful API -- GET
/v1/datasets/<dataset_id>/metadata/summary

### Type of change

- [x] Refactoring
JasleenKaurSethi pushed a commit to stackhpc/ragflow that referenced this pull request Apr 28, 2026
### What problem does this PR solve?

Consolidation WEB API & HTTP API for document metadata summary

Before consolidation
Web API: POST /api/v1/document/metadata/summary
Http API - GET /v1/datasets/<dataset_id>/metadata/summary

After consolidation, Restful API -- GET
/v1/datasets/<dataset_id>/metadata/summary

### Type of change

- [x] Refactoring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐖api The modified files are located under directory 'api/apps/sdk' 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