Repository navigation
fix: fetch all knowledge bases via pagination in link-to-dataset dialog - #17170
Conversation
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.
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthrough
ChangesKnowledge list pagination
Scroll-based selector loading
Consumer contract updates
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
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
wangq8
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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 >= pageSizeis the right condition to detect when there are more pages- The
shouldFilterListWithoutDocumentfilter is applied to the aggregatedalllist, 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.
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.
There was a problem hiding this comment.
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
📒 Files selected for processing (8)
web/src/components/knowledge-base-item.tsxweb/src/components/ui/multi-select.tsxweb/src/hooks/use-knowledge-request.tsweb/src/pages/agent/canvas/node/retrieval-node.tsxweb/src/pages/dataset/dataset-setting/components/tag-item.tsxweb/src/pages/datasets/use-select-owners.tsweb/src/pages/files/hooks.tsweb/src/pages/files/link-to-dataset-dialog.tsx
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.
There was a problem hiding this comment.
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 winGuard pagination against all in-flight query work.
isFetchingNextPageonly means anotherfetchNextPage()call is loading, so background or initial refetches can also setisFetchingwhile this flag remains false. CallfetchNextPage()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
📒 Files selected for processing (3)
web/src/hooks/use-knowledge-request.tsweb/src/pages/dataset/dataset-setting/components/tag-item.tsxweb/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
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.
Summary
Fix: the file management "link to dataset" dialog only displayed the 30 most recently created knowledge bases because
useFetchKnowledgeListcalled the dataset list API without pagination parameters, hitting the Go backend defaultpage_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: