Skip to content

Fix: empty metadata conditions and non-integer available flags - #19508

Open
MoonPointer-Byte wants to merge 1 commit into
infiniflow:mainfrom
MoonPointer-Byte:fix/python-empty-metadata-condition
Open

MoonPointer-Byte wants to merge 1 commit into
infiniflow:mainfrom
MoonPointer-Byte:fix/python-empty-metadata-condition

Conversation

@MoonPointer-Byte

@MoonPointer-Byte MoonPointer-Byte commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Fix POST /retrieval so an empty metadata_condition.conditions list no longer scopes the search to the sentinel document "-999". Empty conditions now mean no metadata filtering, matching Go MetadataConditionToDocIDs, and explicit document_ids are preserved.
  • Validate available / available_int on chunk update and switch routes; non-integer values return a data error instead of a 500.

Fixes #19366
Fixes #19479

Test plan

  • pytest test/testcases/test_web_api/test_chunk_app/test_chunk_routes_unit.py (9 passed)
  • Confirm empty metadata_condition.conditions retrieval returns unfiltered chunks
  • Confirm PATCH .../chunks/<id> with {"available":"abc"} returns a data error
  • Confirm switch chunks with {"available_int":"abc"} returns a data error

Skip metadata filtering when conditions is empty so retrieval keeps
caller document_ids (or None) instead of scoping to "-999", matching
Go MetadataConditionToDocIDs. Also return data errors for non-integer
available/available_int instead of 500s.
@coderabbitai

coderabbitai Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 8a17ecda-3586-4401-8c45-f69132f94c63

📥 Commits

Reviewing files that changed from the base of the PR and between a024bea and f3d6594.

📒 Files selected for processing (2)
  • api/apps/restful_apis/chunk_api.py
  • test/testcases/test_web_api/test_chunk_app/test_chunk_routes_unit.py

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The chunk API now preserves document scope when metadata conditions are empty and returns data errors for non-integer availability flags. Unit tests and route stubs cover both behaviors.

Changes

Chunk API fixes

Layer / File(s) Summary
Empty metadata condition handling
api/apps/restful_apis/chunk_api.py
retrieval_test skips metadata filtering when metadata_condition.conditions is empty. It preserves caller document IDs or leaves the search unscoped.
Availability flag validation
api/apps/restful_apis/chunk_api.py
update_chunk and switch_chunks return data errors for non-integer available and available_int values.
Route stubs and regression tests
test/testcases/test_web_api/test_chunk_app/test_chunk_routes_unit.py
Test stubs support the updated route paths. New tests verify retrieval scope and invalid availability handling.

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

Severity of issue fixed: Medium

Suggested reviewers: wangq8, jinhai-cn, euvre

Merge Risk: ⚪ Minimal · up to f3d65

Empty metadata conditions now allow unfiltered retrieval and preserve requested document IDs, while invalid availability values receive clear data errors without changing stored chunks. No concrete merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 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%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address both linked issues: [#19366] empty metadata conditions no longer apply filtering or discard explicit document IDs, and [#19479] non-integer availability values return data errors i…
Out of Scope Changes check ✅ Passed The production changes and test updates directly support the two linked issue objectives. No unrelated code changes are identified.
Title check ✅ Passed The title clearly and concisely describes both fixes: empty metadata conditions and non-integer available flags.
Description check ✅ Passed The description includes the required Summary section, explains both fixes, provides issue references, and lists test results and pending validation steps.
  • Fix all pre-merge checks with AI

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

A rabbit checks the chunks with care
Empty filters leave IDs there
Bad flags meet an error gate
No more 500s at the route
Tests hop along in tidy rows
The API now clearly shows

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

@JinHai-CN
JinHai-CN requested a review from euvre September 10, 2026 12:08
@euvre euvre added the ci Continue Integration label Sep 11, 2026
@codecov

codecov Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 42.85714% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 36.44%. Comparing base (97029b0) to head (f3d6594).
⚠️ Report is 57 commits behind head on main.

Files with missing lines Patch % Lines
api/apps/restful_apis/chunk_api.py 42.85% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #19508      +/-   ##
==========================================
- Coverage   37.29%   36.44%   -0.85%     
==========================================
  Files          54       54              
  Lines       15353    16135     +782     
  Branches      119      125       +6     
==========================================
+ Hits         5726     5881     +155     
- Misses       9601    10227     +626     
- Partials       26       27       +1     

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

@euvre euvre added ci Continue Integration and removed ci Continue Integration labels Sep 14, 2026
@euvre

euvre commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

This reply was generated by Hands-Free-Vibe-for-RAGFlow.

LGTM 🚀

What was verified

  • Go-parity claim holds: for empty conditions the Go side returns the caller's doc scope unchanged (internal/service/metadata_filter.go:583 — MetadataConditionToDocIDs returns "" for empty conditions; internal/service/metadata_filter.go:727 — manual ApplyMetaDataFilter returns baseDocIDs, false for an empty manual list). The new Python branch (api/apps/restful_apis/chunk_api.py:410-428) now matches, and non-empty conditions keep the previous semantics (intersect with caller document_ids, zero-result short-circuit at api/apps/restful_apis/chunk_api.py:425-426).
  • Live end-to-end against the running stack, from a real authenticated browser session (web → Python API), using a freshly created dataset with an uploaded and parsed document:
    • POST /api/v1/retrieval baseline (no condition): total=1, similarity 0.43.
    • Same request + metadata_condition: {"logic":"and","conditions":[]}: total=1, identical to baseline — previously this scoped the search to the -999 sentinel and returned 0.
    • Same + explicit document_ids: total=1 with the document scope preserved — previously the ids were intersected away to 0.
    • Non-matching non-empty condition (zzz_nonexistent_key = no-such-value): total=0 — filtering and the zero-result short-circuit still work (adjacent regression path).
    • PATCH /api/v1/datasets/{id}/documents/{doc}/chunks/{chunk} with {"available":"abc"} → code 102 "available should be an integer" (previously a 500), and no store write happens.
    • PATCH .../chunks with {"chunk_ids":[...],"available_int":"abc"} → code 102 "available_int should be an integer"; valid available_int 0/1 toggles still return code 0 (state restored afterwards).
    • Browser pass: logged-in datasets landing, dataset "Retrieval testing" page with a question run, and the document chunk view — screenshots 01/02 in the audit record.
  • The two new unit tests load the real route functions with stubbed services and pin exactly the fixed behaviors (empty conditions skip filter_doc_ids_by_metadata, doc_ids fidelity, 102 data errors with no store update). The unit-tier pre-run reported no test failures for the touched files; its ruff line failed only because the fresh venv has no ruff binary — an environment issue, not a diff issue.

Verification tier: Python REST runtime change — programmatic drive of every changed route from an authenticated browser session, plus a browser UI pass over the retrieval-testing page and the document chunk view (screenshots captured).

Non-blocking notes:

  1. api/apps/restful_apis/dify_retrieval_api.py:269 still falls back to doc_ids=["-999"] when metadata_condition is present with empty conditions and the caller passed no document_ids — the same bug shape as Retrieval with an empty metadata_condition.conditions list returns zero chunks (Pyt[Bug]: #19366 on the Dify-compatible route. Pre-existing and outside this PR's scope (api/apps/restful_apis/openai_api.py:296-304 already behaves the new way), but worth a follow-up so the sentinel doesn't resurface elsewhere.
  2. Pre-existing inconsistency this PR doesn't unify: update_chunk parses available as an int (api/apps/restful_apis/chunk_api.py:1277) while switch_chunks treats it as a boolean flag (api/apps/restful_apis/chunk_api.py:1349), so "0" disables on one route and enables on the other.

Verification screenshots

datasets landing
retrieval testing
chunk list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration

Projects

None yet

2 participants