Skip to content

Consolidate set_meta into update_document - #14045

Merged
yuzhichang merged 1 commit into
infiniflow:mainfrom
xugangqiang:merge-set-meta
Apr 13, 2026
Merged

yuzhichang merged 1 commit into
infiniflow:mainfrom
xugangqiang:merge-set-meta

Conversation

@xugangqiang

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Consolidate "set_meta" API into "update_document" .

Before consolidation
Web API: POST /api/v1/document/set_meta
Http API - PUT /v1/datasets/<dataset_id>/document/<document_id>

After consolidation, Restful API -- PUT /v1/datasets/<dataset_id>/document/<document_id>

Type of change

  • Refactoring

@coderabbitai

coderabbitai Bot commented Apr 10, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The PR refactors the document metadata update flow by migrating from the POST /document/set_meta endpoint to a new PUT /datasets/{dataset_id}/documents/{doc_id} endpoint. The client now resolves the dataset ID through document lookup, parses metadata JSON, and the legacy endpoint is removed from the server.

Changes

Cohort / File(s) Summary
Client metadata endpoint migration
admin/client/ragflow_client.py
Added _get_documents_by_ids() helper to fetch documents and resolve dataset IDs. Updated set_metadata() to parse JSON metadata, obtain dataset ID via document lookup, and use new PUT endpoint with parsed metadata dict instead of raw string.
Server endpoint removal
api/apps/document_app.py
Removed POST /set_meta route handler, including request validation, authorization checks, and metadata update logic. Eliminated unused json import.
Test cleanup
test/testcases/test_web_api/test_chunk_feedback/__init__.py
Deleted entire module initializer file with __all__ declaration.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

size:L, 🐖api

Suggested reviewers

  • yuzhichang
  • JinHai-CN

Poem

🐰 Hop along, old endpoint, your time has come to pass,
A newer route awaits us, in datasets swift and vast,
With JSON parsed and IDs found, our metadata takes flight,
The rabbit's refactored stream makes document updates right! 🚀

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main objective of the pull request—consolidating the set_meta functionality into the update_document endpoint.
Description check ✅ Passed The description includes the required template sections with clear context about the problem being solved and the type of change (Refactoring).

✏️ 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 added the ci Continue Integration label Apr 10, 2026
@xugangqiang
xugangqiang marked this pull request as ready for review April 10, 2026 10:48
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label 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.

🧹 Nitpick comments (3)
admin/client/ragflow_client.py (3)

1597-1613: Remove redundant import and unreachable code.

  1. Redundant import: json is already imported at line 16, so the import at line 1598 is unnecessary.

  2. Unreachable code: The check at lines 1611-1613 is redundant because _get_documents_by_ids already returns an error message when docs is empty (lines 1584-1585). If doc_error_msg is None, docs is guaranteed to be non-empty.

♻️ Proposed fix
-        # Parse JSON string to dict
-        import json
         try:
             meta_fields = json.loads(meta_json_str)
         except json.JSONDecodeError as e:
             print(f"Invalid JSON format: {e}")
             return
 
         # Step 1: Get document info to find kb_id (dataset_id)
         doc_error_msg, docs = self._get_documents_by_ids([doc_id])
         if doc_error_msg:
             print(doc_error_msg)
             return
 
-        if len(docs) == 0:
-            print(f"no document found for {doc_id}")
-            return
-
         dataset_id = docs[0].get("kb_id")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@admin/client/ragflow_client.py` around lines 1597 - 1613, Remove the
redundant local import of json and the unreachable docs-empty check: delete the
"import json" line in the JSON parsing block and remove the if len(docs) == 0 /
print(...) / return block, since json is already imported globally and
_get_documents_by_ids(doc_id) (used via self._get_documents_by_ids) already
returns a doc_error_msg when docs are empty; keep the json.loads(...) try/except
and subsequent logic intact.

1567-1587: Add logging for this new flow.

The new _get_documents_by_ids method should include logging for error conditions (HTTP failures, non-zero response codes, document not found) to aid debugging and observability. As per coding guidelines, "Add logging for new flows".

Also, minor style: add space after colon in type hint (ids: list[str]).

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

In `@admin/client/ragflow_client.py` around lines 1567 - 1587, The
_get_documents_by_ids method lacks logging for failure branches and has a minor
type-hint spacing style issue; add structured logs (using the module's logger)
for the HTTP failure branch (log status_code and request payload/ids), for the
non-zero response code branch (log res_json.get("code"), res_json.get("message")
and ids), and for the empty docs branch (log that no documents were found along
with ids); ensure you call logger.error or logger.warning consistently around
the http_client.request call and its response checks (response.status_code,
res_json) and adjust the signature to use a spaced type hint ids: list[str].

1625-1640: Add logging for this updated flow.

The metadata update operation lacks logging for success and failure cases. Consider adding debug/info level logging before the request and error-level logging for failures to improve observability. As per coding guidelines, "Add logging for new flows".

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

In `@admin/client/ragflow_client.py` around lines 1625 - 1640, Add structured
logging around the metadata PUT flow: obtain a logger (use self.logger if
present or logging.getLogger(__name__)), log an info/debug message before
calling self.http_client.request with dataset_id, doc_id and a redacted
indication of payload, then replace the print statements with logger.info on
success and logger.error on failures including response.status_code,
res_json.get("code"), and res_json.get("message"); also catch and
logger.exception for any request exceptions around the self.http_client.request
call to ensure errors are recorded for debugging.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@admin/client/ragflow_client.py`:
- Around line 1597-1613: Remove the redundant local import of json and the
unreachable docs-empty check: delete the "import json" line in the JSON parsing
block and remove the if len(docs) == 0 / print(...) / return block, since json
is already imported globally and _get_documents_by_ids(doc_id) (used via
self._get_documents_by_ids) already returns a doc_error_msg when docs are empty;
keep the json.loads(...) try/except and subsequent logic intact.
- Around line 1567-1587: The _get_documents_by_ids method lacks logging for
failure branches and has a minor type-hint spacing style issue; add structured
logs (using the module's logger) for the HTTP failure branch (log status_code
and request payload/ids), for the non-zero response code branch (log
res_json.get("code"), res_json.get("message") and ids), and for the empty docs
branch (log that no documents were found along with ids); ensure you call
logger.error or logger.warning consistently around the http_client.request call
and its response checks (response.status_code, res_json) and adjust the
signature to use a spaced type hint ids: list[str].
- Around line 1625-1640: Add structured logging around the metadata PUT flow:
obtain a logger (use self.logger if present or logging.getLogger(__name__)), log
an info/debug message before calling self.http_client.request with dataset_id,
doc_id and a redacted indication of payload, then replace the print statements
with logger.info on success and logger.error on failures including
response.status_code, res_json.get("code"), and res_json.get("message"); also
catch and logger.exception for any request exceptions around the
self.http_client.request call to ensure errors are recorded for debugging.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: afe028e9-ceb3-47cf-9c25-4e6119a862da

📥 Commits

Reviewing files that changed from the base of the PR and between 4046a4c and b16e643.

📒 Files selected for processing (3)
  • admin/client/ragflow_client.py
  • api/apps/document_app.py
  • test/testcases/test_web_api/test_chunk_feedback/__init__.py
💤 Files with no reviewable changes (2)
  • test/testcases/test_web_api/test_chunk_feedback/init.py
  • api/apps/document_app.py

@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 (3d59448) to head (b16e643).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14045   +/-   ##
=======================================
  Coverage   96.66%   96.66%           
=======================================
  Files          10       10           
  Lines         690      690           
  Branches      108      108           
=======================================
  Hits          667      667           
  Misses          8        8           
  Partials       15       15           

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

@yuzhichang yuzhichang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Apr 13, 2026
@yuzhichang
yuzhichang merged commit 51ce6aa into infiniflow:main Apr 13, 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?

Consolidate "set_meta" API into "update_document" .

Before consolidation
Web API: POST /api/v1/document/set_meta
Http API - PUT /v1/datasets/<dataset_id>/document/<document_id>

After consolidation, Restful API -- PUT
/v1/datasets/<dataset_id>/document/<document_id>

### Type of change

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

Consolidate "set_meta" API into "update_document" .

Before consolidation
Web API: POST /api/v1/document/set_meta
Http API - PUT /v1/datasets/<dataset_id>/document/<document_id>

After consolidation, Restful API -- PUT
/v1/datasets/<dataset_id>/document/<document_id>

### 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?

Consolidate "set_meta" API into "update_document" .

Before consolidation
Web API: POST /api/v1/document/set_meta
Http API - PUT /v1/datasets/<dataset_id>/document/<document_id>

After consolidation, Restful API -- PUT
/v1/datasets/<dataset_id>/document/<document_id>

### 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?

Consolidate "set_meta" API into "update_document" .

Before consolidation
Web API: POST /api/v1/document/set_meta
Http API - PUT /v1/datasets/<dataset_id>/document/<document_id>

After consolidation, Restful API -- PUT
/v1/datasets/<dataset_id>/document/<document_id>

### Type of change

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

Labels

ci Continue Integration lgtm This PR has been approved by a maintainer 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