mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-07 03:18:23 -05:00
[GH-ISSUE #15046] feat: Indexing to improve performance #32978
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @decent-engineer-decent-datascientist on GitHub (Jun 16, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/15046
Check Existing Issues
Problem Description
When using Open-WebUI with a SQLite or pSQL backend, database queries (such as filtering, sorting, and joining) can become noticeably slow as data grows, particularly for common tables (e.g., chat, tag, function).
Currently, not indexes are created by default. Indexes that would drastically improve performance must be created manually. Many users may not be aware of best practices for index creation or which queries would benefit most.
Desired Solution you'd like
Automatically create indexes for databases upon initial setup or first use of key tables. Example indices include:
WHERE folder_id = ...CREATE INDEX folder_id_idx ON chat(folder_id);WHERE user_id = ...CREATE INDEX user_id_idx ON tag(user_id);WHERE user_id = ... AND pinned = ...CREATE INDEX user_id_pinned_idx ON chat(user_id, pinned);WHERE user_id = ... ORDER BY updated_at DESCCREATE INDEX updated_at_user_id_idx ON chat(updated_at, user_id);WHERE user_id = ... AND archived = ...CREATE INDEX user_id_archived_idx ON chat(user_id, archived);WHERE is_global = ...CREATE INDEX is_global_idx ON function(is_global);WHERE folder_id = ... AND user_id = ...CREATE INDEX folder_id_user_id_idx ON chat(folder_id, user_id);Alternatives Considered
Additional Context
I recently analyzed query logs for a PostgreSQL deployment and found that similar indexes provide major performance boosts on SQLite as well. Given the overlap in SQL functionality, this feature would make Open-WebUI more performant "out-of-the-box" for SQLite users (who may be on resource-limited systems). Additionally, automated index management would help less-technical users avoid sluggishness as their dataset grows.
It would be as simple as doing this for new instances:
backend/open_webui/models/chats.py:
@decent-engineer-decent-datascientist commented on GitHub (Jun 16, 2025):
Happy to open a PR on this, with the indices I've tested. That being said, @tjbck, seeing as there are no indices in the models right now, I don't want to commit work that goes against any design decisions.
@decent-engineer-decent-datascientist commented on GitHub (Jun 19, 2025):
If we're interested, I've added PR #15155
@richard-a-adams commented on GitHub (Jul 3, 2025):
Hi,
Thanks for suggesting these improvements. Am I able to create these indexes on an already existing postgreSQL db and get these performance improvements? Or does it require further code changes to the interface to get any benefits?
Not too familiar with DBs as a whole so thanks for any information you can provide.
@decent-engineer-decent-datascientist commented on GitHub (Jul 3, 2025):
If you apply the indices properly, no code changes need to happen. Make a
backup.
On Wed, Jul 2, 2025 at 8:46 PM Richard-Adams @.***>
wrote:
@richard-a-adams commented on GitHub (Jul 3, 2025):
Great, thanks.
Would you be able to provide any advice or guidance on how to apple the indices properly?
Of course making a backup before doing these changes is the first step but anything after that?
@spammenotinoz commented on GitHub (Jul 25, 2025):
Thank-you this helped dramatically, do you have any other index suggestions to help workspace functions such as models, knowledge and prompts?
@AsianDesignMajor commented on GitHub (Aug 9, 2025):
@decent-engineer-decent-datascientist Are the compound indexes the only way to do this? I'm no expert at indexes, but I would think applying single-field indexes would keep the sizes down - it appears you're indexing the same field in more than one place. Would the speed improvement really change all that much (I'm going to apply this to a PSQL back-end)?
So, would it be OK, for example, to do:
I'm also curious if there's other tables / fields that are in the OWUI code as frequent join conditions, that could benefit from an index long-term (like, for example, indexing user_id across any tables with that field, as I would think joining user_id between certain tables in OWUI queries would be a "given" if a table has that field in it - like the "function" table, probably others.)
EDIT 2: I went through the tables and added indexes on user_id in any table that has that field, so would this be OK, you think, in addition to the ones above?
@ivanbaldo commented on GitHub (Aug 11, 2025):
@AsianDesignMajor no, multiple column indexes are a good thing if done right, and in many cases is what you really want to do.
This is an excellent resource to understand these things https://use-the-index-luke.com/ if you are interested.
Thanks!!!
@hheydaroff commented on GitHub (Nov 19, 2025):
This is what is needed on OpenWebUI. The backend implementation requires a major upgrade. Is there any follow up plan on this? For the cases where multiple users are onboarded, it becomes a bottleneck for performance.
@tjbck commented on GitHub (Nov 21, 2025):
This was added a long time ago.
@hheydaroff commented on GitHub (Nov 21, 2025):
Excuse me, my bad. I had not properly checked the PR. It has not solved the issues though. Current implementation covers only high-impact compound indexes but leaves single-column indexes on frequently-queried fields unindexed:
user_idcolumns used in frequent join operationsfunctionandmodeltables not yet indexedi.e. from a reddit post:
In general, my feeling is that quite some
INDEXes are missing.@Classic298 commented on GitHub (Nov 21, 2025):
@hheydaroff
check the dev branch, tim just pushed through a group user table migration for frequently accessed user objects.
please do not use reddit as a source...
@hheydaroff commented on GitHub (Nov 21, 2025):
@Classic298, will check. thanks for the input!