Fix/#8426 知识库文档列表加载不全#8455
Open
M1LKT wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces fallback metadata generation for configured providers in useProviderSources.ts and updates the document loading logic in DocumentsTab.vue to request a page size based on the knowledge base's document count. Feedback points out a critical issue in DocumentsTab.vue where an outdated props.kb?.doc_count during document upload can cause newly uploaded documents to be truncated. It is recommended to use Math.max(props.kb?.doc_count || 0, 10000) to guarantee a safe minimum page size.
Comment on lines
+345
to
+346
| kb_id: props.kbId, | ||
| page_size: props.kb?.doc_count || 10000 |
Contributor
There was a problem hiding this comment.
问题分析\n1. 当文档上传完成时,系统会先调用 loadDocuments()(第 602 行),然后调用 emit('refresh')(第 603 行)。\n2. 在调用 loadDocuments() 的瞬间,props.kb?.doc_count 还没有被更新,依然是旧的文档数量(例如 100)。\n3. 由于 100 是真值(truthy),page_size 会被设置为 100。此时后端只会返回前 100 条文档,导致新上传的文档被截断。\n4. 虽然随后调用了 emit('refresh') 来更新父组件的状态,但由于 DocumentsTab.vue 中没有对 props.kb 的 watch 监听器,loadDocuments() 不会再次触发。因此,新上传的文档在列表里将无法显示,直到用户手动刷新页面或重新挂载组件。\n\n### 解决方案\n为了确保在 props.kb?.doc_count 临时不同步的情况下,依然能请求到足够大的 page_size 以包含新上传的文档,建议使用 Math.max(props.kb?.doc_count || 0, 10000)。这样可以保证最小请求大小为 10000,同时在文档总数超过 10000 时也能自动向上扩展。
kb_id: props.kbId,
page_size: Math.max(props.kb?.doc_count || 0, 10000)
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The new
page_size: props.kb?.doc_count || 10000logic could result in very large result sets for big knowledge bases; consider capping the page size or adding a guard to avoid overwhelming the backend and UI whendoc_countis very large. - When
getModelMetadata(provider.model)returns null andbuildMetadataFromProvideralso returns null (e.g., no modalities and nomax_context_tokens),supportsReasoning(metadata)will be called with a null argument; it may be worth ensuringsupportsReasoningis null-safe or short-circuiting in this case.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `page_size: props.kb?.doc_count || 10000` logic could result in very large result sets for big knowledge bases; consider capping the page size or adding a guard to avoid overwhelming the backend and UI when `doc_count` is very large.
- When `getModelMetadata(provider.model)` returns null and `buildMetadataFromProvider` also returns null (e.g., no modalities and no `max_context_tokens`), `supportsReasoning(metadata)` will be called with a null argument; it may be worth ensuring `supportsReasoning` is null-safe or short-circuiting in this case.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Modifications / 改动点
修复:知识库文档列表最多只显示 100 条
修复知识库文档数量超过 100 时,文档列表最多只显示 100 条,且分页选择 "all" 也只能看到 100 条的问题。同时顶部 tab 标签上的总数显示却是正确的,导致两边数据不一致。
根因分析:
后端
/api/kb/document/list接口默认page_size=100,前端DocumentsTab.vue调用该接口时未传递任何分页参数,因此最多只能拿到 100 条数据。前端
v-data-table的 "all" 选项只是对已获取数据做客户端分页,并不会重新向后端请求剩余数据,所以即使切到 "all" 也只看到这 100 条。而顶部 tab 显示的数字来自
kb.doc_count(知识库元信息中的真实总数),不受该接口的LIMIT限制,所以两边对不上。改动内容:
src/views/knowledge-base/components/DocumentsTab.vue/api/kb/document/list时,将page_size设置为props.kb?.doc_count || 10000,使用知识库元信息中的真实文档总数作为请求大小,确保一次拉全所有文档效果:
说明:
本次为快速修复,仍然使用前端分页。后续如果文档数量进一步增长(例如上万条),建议改造为真正的服务端分页(
v-data-table-server+ 后端返回total字段),以避免一次性加载过多数据导致前端渲染压力。Screenshots or Test Results / 运行截图或测试结果
验证步骤:
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了"验证步骤"和"运行截图"。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Fix knowledge base document listing limits and improve model provider metadata handling.
Bug Fixes:
Enhancements: