From 113a64ad1a4bb958fc8d662176411b609d21b79f Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Mon, 12 Oct 2026 21:32:52 +0200 Subject: [PATCH] perf: speed up one-word chat search (#32268) Chat search checks the whole query and each word in it separately. With a single word those are the same check, so every chat got searched twice. It is now searched once, with the same results. On PostgreSQL with 2164 chats (533 MB of chat data) a one-word search is about 40% faster: | search | before | after | |---|---|---| | proxy | 6.0 s | 3.6 s | | opnsense | 6.1 s | 3.8 s | | no match | 5.4 s | 3.0 s | Refs #32266 --- backend/open_webui/models/chats.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/models/chats.py b/backend/open_webui/models/chats.py index b0881bc6c3..933dcce4dc 100644 --- a/backend/open_webui/models/chats.py +++ b/backend/open_webui/models/chats.py @@ -2180,7 +2180,8 @@ class ChatTable: search_text_words = [word for word in search_text_words if not word.startswith(CHAT_SEARCH_FILTER_PREFIXES)] phrase_query = ' '.join(search_text_words).strip() - search_terms = chat_search_terms(phrase_query) + # A single-word query is already fully covered by the phrase match + search_terms = [term for term in chat_search_terms(phrase_query) if term != phrase_query] async with get_async_db_context(db) as session: stmt = select(Chat).filter(Chat.user_id == user_id)