Eliminates N+1 database query in the add_files_to_knowledge_batch endpoint. Previously, when batch-adding files to a knowledge base, each file was fetched individually.
Add validation to check all requested files were found
Performance Impact
Before: N+1 queries (1 per file in batch)
After: 1 query total using SQL IN clause
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
Note
Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/open-webui/open-webui/pull/21006
**Author:** [@Classic298](https://github.com/Classic298)
**Created:** 1/28/2026
**Status:** ✅ Merged
**Merged:** 2/9/2026
**Merged by:** [@tjbck](https://github.com/tjbck)
**Base:** `dev` ← **Head:** `knowledge-query`
---
### 📝 Commits (1)
- [`190d472`](https://github.com/open-webui/open-webui/commit/190d47221617c9128045b0d73edf0fce721a8534) fix: resolve N+1 query in knowledge batch file add
### 📊 Changes
**1 file changed** (+12 additions, -10 deletions)
<details>
<summary>View changed files</summary>
📝 `backend/open_webui/routers/knowledge.py` (+12 -10)
</details>
### 📄 Description
## Summary
Eliminates N+1 database query in the add_files_to_knowledge_batch endpoint. Previously, when batch-adding files to a knowledge base, each file was fetched individually.
## Changes
routers/knowledge.py add_files_to_knowledge_batch endpoint:
- Replace loop calling get_file_by_id per file
- Use single get_files_by_ids batch call
- Add validation to check all requested files were found
## Performance Impact
Before: N+1 queries (1 per file in batch)
After: 1 query total using SQL IN clause
### Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms.
> [!NOTE]
> Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/21006
Author: @Classic298
Created: 1/28/2026
Status: ✅ Merged
Merged: 2/9/2026
Merged by: @tjbck
Base:
dev← Head:knowledge-query📝 Commits (1)
190d472fix: resolve N+1 query in knowledge batch file add📊 Changes
1 file changed (+12 additions, -10 deletions)
View changed files
📝
backend/open_webui/routers/knowledge.py(+12 -10)📄 Description
Summary
Eliminates N+1 database query in the add_files_to_knowledge_batch endpoint. Previously, when batch-adding files to a knowledge base, each file was fetched individually.
Changes
routers/knowledge.py add_files_to_knowledge_batch endpoint:
Performance Impact
Before: N+1 queries (1 per file in batch)
After: 1 query total using SQL IN clause
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.