Skip to content

Fix/#8426 知识库文档列表加载不全#8455

Open
M1LKT wants to merge 2 commits into
AstrBotDevs:masterfrom
M1LKT:fix/#8426
Open

Fix/#8426 知识库文档列表加载不全#8455
M1LKT wants to merge 2 commits into
AstrBotDevs:masterfrom
M1LKT:fix/#8426

Conversation

@M1LKT
Copy link
Copy Markdown
Contributor

@M1LKT M1LKT commented May 31, 2026

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 限制,所以两边对不上。

改动内容:

  1. src/views/knowledge-base/components/DocumentsTab.vue
    • 调用 /api/kb/document/list 时,将 page_size 设置为 props.kb?.doc_count || 10000,使用知识库元信息中的真实文档总数作为请求大小,确保一次拉全所有文档

效果:

  • 文档数量超过 100 时,列表能显示全部文档
  • 列表数量与顶部 tab 显示的总数保持一致
  • "all" 选项能正确显示所有文档

说明:

本次为快速修复,仍然使用前端分页。后续如果文档数量进一步增长(例如上万条),建议改造为真正的服务端分页(v-data-table-server + 后端返回 total 字段),以避免一次性加载过多数据导致前端渲染压力。

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

验证步骤:

  1. 进入一个文档数量超过 100 的知识库(可上传 100+ 个文档复现,或使用已有的大型知识库)
  2. 切换到"文档"tab,观察文档列表是否显示全部文档
  3. 确认列表中可见文档数量与顶部 tab 标签上显示的总数一致
  4. 在分页选择中切换到 "all",确认所有文档都被加载

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.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.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:

  • Ensure knowledge base document lists load all documents by requesting up to the repository's full document count from the backend instead of relying on the default 100-item page size.

Enhancements:

  • Derive model metadata from provider configuration when model-level metadata is missing, including modalities, tool-call support, reasoning capability, and context limits.
  • Include reasoning support information when creating or updating provider sources so it is correctly propagated through the system.

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. area:webui The bug / feature is about webui(dashboard) of astrbot. feature:knowledge-base The bug / feature is about knowledge base labels May 31, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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

high

问题分析\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.kbwatch 监听器,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)

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

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

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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

Labels

area:webui The bug / feature is about webui(dashboard) of astrbot. feature:knowledge-base The bug / feature is about knowledge base 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