Skip to content

fix: fetch all knowledge bases via pagination in link-to-dataset dialog - #17170

Merged
wangq8 merged 6 commits into
infiniflow:mainfrom
euvre:fix/knowledge-base-list-pagination
Jul 23, 2026
Merged

wangq8 merged 6 commits into
infiniflow:mainfrom
euvre:fix/knowledge-base-list-pagination

Conversation

@euvre

@euvre euvre commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix: the file management "link to dataset" dialog only displayed the 30 most recently created knowledge bases because useFetchKnowledgeList called the dataset list API without pagination parameters, hitting the Go backend default page_size=30. Knowledge bases beyond the first page were invisible and unsearchable in the selection dropdown.

This PR fixes the issue by looping through pages (page_size=200) until all knowledge bases are loaded, ensuring the complete list is available for both display and client-side search in the MultiSelect component.

The fix also benefits other consumers of useFetchKnowledgeList:

  • Agent retrieval node knowledge base selector
  • Dataset settings tag item
  • Knowledge base item component
  • Owner selection filter

The file management link-to-dataset dialog only showed the 30 most
recently created knowledge bases because useFetchKnowledgeList called
listDataset without page/page_size params, hitting the Go backend
default of page_size=30. The MultiSelect search box only filtered
client-side within those 30 results, making unlisted knowledge bases
unsearchable and unselectable.

Fix by looping through pages (page_size=200) until all knowledge bases
are loaded, so the full list is available for display and search.
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 21, 2026
@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

useFetchKnowledgeList now supports paginated dataset loading, aggregated filtering, automatic full-list retrieval, and scroll-driven option loading. Consumers were updated for the expanded hook contracts and new MultiSelect scroll callback.

Changes

Knowledge list pagination

Layer / File(s) Summary
Paginated retrieval and full-list loading
web/src/hooks/use-knowledge-request.ts
useFetchKnowledgeList requests and aggregates dataset pages, applies keyword and document filters, and exposes pagination controls. useFetchAllKnowledgeList automatically loads remaining pages, while useSelectKnowledgeOptions uses the full-list hook to derive options.

Scroll-based selector loading

Layer / File(s) Summary
MultiSelect scroll wiring
web/src/components/ui/multi-select.tsx, web/src/components/knowledge-base-item.tsx, web/src/pages/dataset/dataset-setting/components/tag-item.tsx, web/src/pages/files/link-to-dataset-dialog.tsx
MultiSelect forwards list scroll events, and selectors conditionally connect them to pagination handlers when more results exist. Search state and debounced keywords are passed to paginated selectors.

Consumer contract updates

Layer / File(s) Summary
Full-list and options consumers
web/src/pages/agent/canvas/node/retrieval-node.tsx, web/src/pages/datasets/use-select-owners.ts, web/src/pages/files/hooks.ts
Retrieval and owner selection use automatic full-list loading, and file connection code reads options from the updated hook return object.

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

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant MultiSelect
  participant useFetchKnowledgeList
  participant listDataset
  User->>MultiSelect: scroll dataset options
  MultiSelect->>useFetchKnowledgeList: invoke onListScroll
  useFetchKnowledgeList->>listDataset: request next dataset page
  listDataset-->>useFetchKnowledgeList: return page items
  useFetchKnowledgeList-->>MultiSelect: update aggregated options
Loading

Suggested labels: 🐞 bug, 🧰 typescript

Suggested reviewers: dcc123456

Poem

I hopped through pages, one by one,
While scrolls fetched more in the sun.
Full lists gathered, options grew—
A tidy trail of knowledge too!

🚥 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%. 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 clearly summarizes the main change: paginated loading of knowledge bases in the link-to-dataset dialog.
Description check ✅ Passed The description matches the required Summary template and includes problem context, fix, and affected consumers.
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.

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.

@euvre euvre added the ci Continue Integration label Jul 21, 2026
@euvre
euvre requested a review from wangq8 July 21, 2026 08:34

@wangq8 wangq8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Clean fix that brings the Go frontend KB list in line with the Python behavior.

What's good:

  • The pagination loop correctly fetches all KBs with page_size=200, solving the 30-KB visibility cap
  • is the right condition to detect when there are more pages
  • The filter is applied to the aggregated list, preserving existing behavior
  • This also fixes the Agent retrieval node selector and other consumers of this hook

One minor thought: If the API were ever to return exactly results but have no more pages (a full page == last page edge case), this would make one extra empty request. Not a correctness issue — just an extra round-trip. You could consider checking instead, but the current approach is fine and defensively safe. No change needed.

@wangq8 wangq8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Clean fix that brings the KB list loading in line with the Python behavior.

What's good:

  • The pagination loop correctly fetches all KBs with page_size=200, solving the 30-KB visibility cap
  • hasMore = pageData.length >= pageSize is the right condition to detect when there are more pages
  • The shouldFilterListWithoutDocument filter is applied to the aggregated all list, preserving existing behavior
  • This also fixes the Agent retrieval node selector and other consumers of this hook

One minor thought: If the API were ever to return exactly pageSize results but have no more pages (a full page == last page edge case), this would make one extra empty request. Not a correctness issue, just an extra round-trip. You could consider checking pageData.length < pageSize instead, but the current approach is fine and defensively safe. No change needed.

@wangq8
wangq8 requested a review from dcc123456 July 21, 2026 11:05
Replace eager full-list loading in useFetchKnowledgeList with useInfiniteQuery,
so pages are lazily loaded on scroll instead of upfront. Add onListScroll prop
to MultiSelect and wire it up in dropdown consumers. Non-scroll consumers
(use-select-owners, retrieval-node) use useFetchAllKnowledgeList for auto
full-load.
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jul 23, 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: 3

🤖 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 `@web/src/components/knowledge-base-item.tsx`:
- Around line 31-36: Update the knowledge-base list flow in
useFetchKnowledgeList’s consumer to destructure and propagate the returned
hasNextPage field instead of nonexistent hasMore. Preserve the existing wrapper
and KnowledgeBaseFormField wiring so onListScroll receives handleScroll whenever
hasNextPage is true, enabling pagination for the chat.knowledgeBases field.

In `@web/src/hooks/use-knowledge-request.ts`:
- Around line 844-848: Introduce a same-file knowledge-list keys factory and
centralize the key shape currently built in useFetchKnowledgeList. Update that
query’s queryKey and the mutation invalidation sites to call the factory,
replacing raw 'fetchKnowledgeList' literals while preserving
shouldFilterListWithoutDocument and keywords in the key.
- Around line 829-871: Update useFetchKnowledgeList to use the expected 200-item
page size for the complete-list path, while preserving the existing smaller page
size for scroll-driven loading when granular pagination is required. Ensure
getNextPageParam continues using the selected page size so pagination boundaries
remain correct.
🪄 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 Plus

Run ID: ec6d09e6-1596-4bde-98d5-1d2c464432ca

📥 Commits

Reviewing files that changed from the base of the PR and between 6b075ff and d97285a.

📒 Files selected for processing (8)
  • web/src/components/knowledge-base-item.tsx
  • web/src/components/ui/multi-select.tsx
  • web/src/hooks/use-knowledge-request.ts
  • web/src/pages/agent/canvas/node/retrieval-node.tsx
  • web/src/pages/dataset/dataset-setting/components/tag-item.tsx
  • web/src/pages/datasets/use-select-owners.ts
  • web/src/pages/files/hooks.ts
  • web/src/pages/files/link-to-dataset-dialog.tsx

Comment thread web/src/hooks/use-knowledge-request.ts Resolved
Comment thread web/src/hooks/use-knowledge-request.ts Resolved
euvre added 2 commits July 23, 2026 15:10
Replace frontend-only filtering with debounced backend keyword search in
tag-item and link-to-dataset-dialog. Set shouldFilter={false} to disable
cmdk's built-in filter. Switch useSelectKnowledgeOptions to full-load
variant for name lookup consumers.
useFetchKnowledgeList returns hasNextPage, not hasMore. Destructuring
hasMore always yielded undefined, making scroll pagination dead code for
the knowledgeBases field.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
web/src/hooks/use-knowledge-request.ts (1)

872-884: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Guard pagination against all in-flight query work.

isFetchingNextPage only means another fetchNextPage() call is loading, so background or initial refetches can also set isFetching while this flag remains false. Call fetchNextPage() only when there’s no active query work, e.g. !isFetching && !isFetchingNextPage.

🤖 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 872 - 884, Update the
handleScroll pagination guard to require that no query work is active before
calling fetchNextPage: retain hasNextPage and isFetchingNextPage checks, and
also require !isFetching so background or initial refetches cannot trigger
pagination.
🤖 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.

Outside diff comments:
In `@web/src/hooks/use-knowledge-request.ts`:
- Around line 872-884: Update the handleScroll pagination guard to require that
no query work is active before calling fetchNextPage: retain hasNextPage and
isFetchingNextPage checks, and also require !isFetching so background or initial
refetches cannot trigger pagination.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 76b50423-8696-47b9-89e6-3d24c4a0b236

📥 Commits

Reviewing files that changed from the base of the PR and between d97285a and 56b1498.

📒 Files selected for processing (3)
  • web/src/hooks/use-knowledge-request.ts
  • web/src/pages/dataset/dataset-setting/components/tag-item.tsx
  • web/src/pages/files/link-to-dataset-dialog.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/src/pages/dataset/dataset-setting/components/tag-item.tsx

euvre added 2 commits July 23, 2026 15:18
useFetchAllKnowledgeList now uses page_size=200 to minimize backend
round-trips for retrieval-node and owner-selection consumers, while
scroll-driven selectors keep page_size=10 for granular loading.
Also include pageSize in queryKey to avoid cache collisions.
Add a same-file KnowledgeListKeys factory and use it from both the
useFetchKnowledgeList query and the createKnowledge invalidation site,
replacing the inline key construction and raw string literal.
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.

3 participants