Skip to content

Fix: show tag list for chunk - #15251

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
wangq8:bugfix/show-tag-list-for-chunk
May 26, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
wangq8:bugfix/show-tag-list-for-chunk

Conversation

@wangq8

@wangq8 wangq8 commented May 26, 2026

Copy link
Copy Markdown
Collaborator

See:
image

@wangq8
wangq8 requested a review from cike8899 May 26, 2026 12:01
@wangq8
wangq8 marked this pull request as ready for review May 26, 2026 12:01
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label May 26, 2026
@coderabbitai

coderabbitai Bot commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The hook useFetchTagListByKnowledgeIds improves cache isolation and data normalization: the React Query key now depends on the active knowledgeIds, and the result is normalized from mixed object/tuple formats into a consistent flat array of [string, number] tuples.

Changes

Tag List Query Caching and Normalization

Layer / File(s) Summary
Hook query key and result normalization
web/src/hooks/use-knowledge-request.ts
useFetchTagListByKnowledgeIds adds knowledgeIds to the query key for scope-specific caching, and normalizes the API response by flattening mixed tag formats (tuples and objects with value/count) into a consistent Array<[string, number]>.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

size:XS

Suggested reviewers

  • euvre

Poem

A hook's cache now scopes tight,
With knowledgeIds held just right,
Tags flatten to tuples neat,
Normalization's complete! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description only includes an image reference and lacks required sections from the template such as 'What problem does this PR solve?' and 'Type of change' checklist. Add a detailed explanation of the problem being solved and select the appropriate type of change checkbox from the template.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix: show tag list for chunk' clearly relates to the main change, which fixes tag list display for chunks by normalizing API response data and fixing QueryKey caching.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

@coderabbitai

coderabbitai Bot commented May 26, 2026

Copy link
Copy Markdown
Contributor

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{"name":"HttpError","status":500,"request":{"method":"PATCH","url":"https://api.github.com/repos/infiniflow/ragflow/issues/comments/4543944437","headers":{"accept":"application/vnd.github.v3+json","user-agent":"octokit.js/0.0.0-development octokit-core.js/7.0.6 Node.js/24","authorization":"token [REDACTED]","content-type":"application/json; charset=utf-8"},"body":{"body":"<!-- This is an auto-generated comment: summarize by coderabbit.ai -->\n<!-- review_stack_entry_start -->\n\n[![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/infiniflow/ragflow/pull/15251?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)\n\n<!-- review_stack_entry_end -->\n<!-- This is an auto-generated comment: review in progress by coderabbit.ai -->\n\n> [!NOTE]\n> Currently processing new changes in this PR. This may take a few minutes, please wait...\n> \n> <details>\n> <summary>⚙️ Run configuration</summary>\n> \n> **Configuration used**: Organization UI\n> \n> **Review profile**: CHILL\n> \n> **Plan**: Pro\n> \n> **Run ID**: `7e038359-82c9-4ff4-9c79-f4aad8bd7630`\n> \n> </details>\n> \n> <details>\n> <summary>📥 Commits</summary>\n> \n> Reviewing files that changed from the base of the PR and between 22a3b8cdf968f16e1381ced98d59f9cfcc8f12f1 and 8b68200ad8a02dd3306c63e9248a2a76d9ca9e1e.\n> \n> </details>\n> \n> <details>\n> <summary>📒 Files selected for processing (1)</summary>\n> \n> * `web/src/hooks/use-knowledge-request.ts`\n> \n> </details>\n> \n> ```ascii\n>  ____________________________________________________________________________________________________________________________________________\n> < Organize teams around functionality. Don't separate designers from coders, testers from data modelers. Build teams the way you build code. >\n>  --------------------------------------------------------------------------------------------------------------------------------------------\n>   \\\n>    \\   (\\__/)\n>        (•ㅅ•)\n>        /   づ\n> ```\n\n<!-- end of auto-generated comment: review in progress by coderabbit.ai -->\n\n<!-- tips_start -->\n\n---\n\nThanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=infiniflow/ragflow&utm_content=15251)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.\n\n<details>\n<summary>❤️ Share</summary>\n\n- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)\n- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)\n- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)\n- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)\n\n</details>\n\n\n<sub>Comment `@coderabbitai help` to get the list of available commands and usage tips.</sub>\n\n<!-- tips_end -->"},"request":{"retryCount":3,"signal":{},"retries":3,"retryAfter":16}}}

@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 (1)
web/src/hooks/use-knowledge-request.ts (1)

505-512: ⚡ Quick win

Stabilize knowledgeIds ordering in useFetchTagListByKnowledgeIds to avoid duplicate React Query cache entries

queryKey and dataset_ids both use the raw knowledgeIds array order; callers populate knowledgeIds from parser_config.tag_kb_ids (user-driven via MultiSelect), so the same ID set can arrive in different orders and produce separate cache buckets/extra fetches. Sorting once for both the key and payload prevents this.

Proposed change
 export const useFetchTagListByKnowledgeIds = () => {
   const [knowledgeIds, setKnowledgeIds] = useState<string[]>([]);
+  const sortedKnowledgeIds = useMemo(
+    () => [...knowledgeIds].sort(),
+    [knowledgeIds],
+  );

   const { data, isFetching: loading } = useQuery<Array<[string, number]>>({
-    queryKey: ['fetchTagListByKnowledgeIds', knowledgeIds],
-    enabled: knowledgeIds.length > 0,
+    queryKey: ['fetchTagListByKnowledgeIds', sortedKnowledgeIds],
+    enabled: sortedKnowledgeIds.length > 0,
     initialData: [],
     gcTime: 0, // https://tanstack.com/query/latest/docs/framework/react/guides/caching?from=reactQueryV3
     queryFn: async () => {
       const { data } = await kbService.listTagByKnowledgeIds({
-        dataset_ids: knowledgeIds.join(','),
+        dataset_ids: sortedKnowledgeIds.join(','),
       });

Run npm run lint in web/ to ensure the change passes ESLint.

🤖 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 `@web/src/hooks/use-knowledge-request.ts` around lines 505 - 512, The query
uses the raw knowledgeIds array in the queryKey and in the payload
(kbService.listTagByKnowledgeIds), causing cache duplication when callers supply
the same IDs in different orders; fix by creating a stable sorted array (e.g.,
sortedKnowledgeIds = [...knowledgeIds].sort()) and use sortedKnowledgeIds in the
queryKey (replace usage of knowledgeIds) and when building dataset_ids (use
sortedKnowledgeIds.join(',')), keep the enabled check (knowledgeIds.length > 0)
the same, and run npm run lint in web/ to ensure ESLint passes.
🤖 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.

Nitpick comments:
In `@web/src/hooks/use-knowledge-request.ts`:
- Around line 505-512: The query uses the raw knowledgeIds array in the queryKey
and in the payload (kbService.listTagByKnowledgeIds), causing cache duplication
when callers supply the same IDs in different orders; fix by creating a stable
sorted array (e.g., sortedKnowledgeIds = [...knowledgeIds].sort()) and use
sortedKnowledgeIds in the queryKey (replace usage of knowledgeIds) and when
building dataset_ids (use sortedKnowledgeIds.join(',')), keep the enabled check
(knowledgeIds.length > 0) the same, and run npm run lint in web/ to ensure
ESLint passes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7e038359-82c9-4ff4-9c79-f4aad8bd7630

📥 Commits

Reviewing files that changed from the base of the PR and between 22a3b8c and 8b68200.

📒 Files selected for processing (1)
  • web/src/hooks/use-knowledge-request.ts

@wangq8
wangq8 merged commit 303221c into infiniflow:main May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant