[GH-ISSUE #7029] Search fails with 500 Internal server error #14574

Closed
opened 2026-04-19 20:53:37 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @jakerdy on GitHub (Nov 19, 2024).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/7029

Bug Report


Installation Method

It works as python application without docker.

I just created venv, installed open_webui and setup systemd service so that it starts automatically.

Environment

  • Open WebUI Version: v0.3.35
  • Ollama (if applicable): 0.3.13
  • Operating System: Ubuntu server 22.04.3
  • Browser (if applicable): Chrome 130.0

Expected Behavior:

Search should work without errors.

Actual Behavior:

Browser shows 500 Error in Network tab of Dev-Tools. Console logged that fetch failed. In ui just infinitly spinning spinner, and nothing happens.

Description

Bug Summary:
I don't know what exactly breaks search but it not working for me. Maybe it some nasty characters in titles that returned from sketchy ollama models, maybe something else.

I also tried creating new user, that has no history. Made 2 new chats with OpenAI, that returns valid titles. But still, 500 Internal Server Error.

Logs and Screenshots

Browser Console Logs:
image

Python Server Logs:

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
    self.dialect.do_execute(
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/engine/default.py", line 941, in do_execute
    cursor.execute(statement, parameters)
sqlite3.OperationalError: near ">>": syntax error
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 401, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
    with collapse_excgroups():
  File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
    raise exc
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
    await func()
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 217, in stream_response
    return await super().stream_response(send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response
    async for chunk in self.body_iterator:
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 181, in body_stream
    raise app_exc
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
    with collapse_excgroups():
  File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
    raise exc
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
    await func()
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 217, in stream_response
    return await super().stream_response(send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response
    async for chunk in self.body_iterator:
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 181, in body_stream
    raise app_exc
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
    with collapse_excgroups():
  File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
    raise exc
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
    await func()
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 217, in stream_response
    return await super().stream_response(send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response
    async for chunk in self.body_iterator:
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 181, in body_stream
    raise app_exc
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
    with collapse_excgroups():
  File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
    raise exc
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
    await func()
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 217, in stream_response
    return await super().stream_response(send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response
    async for chunk in self.body_iterator:
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 181, in body_stream
    raise app_exc
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
    with collapse_excgroups():
  File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
    raise exc
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
    await func()
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 217, in stream_response
    return await super().stream_response(send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response
    async for chunk in self.body_iterator:
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 181, in body_stream
    raise app_exc
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/cors.py", line 85, in __call__
    await self.app(scope, receive, send)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
    with collapse_excgroups():
  File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
    raise exc
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
    await func()
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 217, in stream_response
    return await super().stream_response(send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response
    async for chunk in self.body_iterator:
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 181, in body_stream
    raise app_exc
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
    with collapse_excgroups():
  File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
    raise exc
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
    await func()
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 217, in stream_response
    return await super().stream_response(send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response
    async for chunk in self.body_iterator:
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 181, in body_stream
    raise app_exc
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
    with collapse_excgroups():
  File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
    raise exc
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap
    await func()
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 217, in stream_response
    return await super().stream_response(send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response
    async for chunk in self.body_iterator:
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 181, in body_stream
    raise app_exc
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/routing.py", line 756, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/routing.py", line 776, in app
    await route.handle(scope, receive, send)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/routing.py", line 485, in handle
    await self.app(scope, receive, send)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/cors.py", line 85, in __call__
    await self.app(scope, receive, send)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/routing.py", line 756, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/routing.py", line 776, in app
    await route.handle(scope, receive, send)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/routing.py", line 297, in handle
    await self.app(scope, receive, send)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/routing.py", line 77, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/routing.py", line 72, in app
    response = await func(request)
               ^^^^^^^^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/fastapi/routing.py", line 278, in app
    raw_response = await run_endpoint_function(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/fastapi/routing.py", line 191, in run_endpoint_function
    return await dependant.call(**values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/open_webui/apps/webui/routers/chats.py", line 149, in search_user_chats
    for chat in Chats.get_chats_by_user_id_and_search_text(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/open_webui/apps/webui/models/chats.py", line 568, in get_chats_by_user_id_and_search_text
    all_chats = query.offset(skip).limit(limit).all()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/orm/query.py", line 2673, in all
    return self._iter().all()  # type: ignore
           ^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/orm/query.py", line 2827, in _iter
    result: Union[ScalarResult[_T], Result[_T]] = self.session.execute(
                                                  ^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/orm/session.py", line 2362, in execute
    return self._execute_internal(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/orm/session.py", line 2247, in _execute_internal
    result: Result[Any] = compile_state_cls.orm_execute_statement(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/orm/context.py", line 293, in orm_execute_statement
    result = conn.execute(
             ^^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1418, in execute
    return meth(
           ^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection
    return connection._execute_clauseelement(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement
    ret = self._execute_context(
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
    return self._exec_single_context(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
    self._handle_dbapi_exception(
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 2355, in _handle_dbapi_exception
    raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
    self.dialect.do_execute(
  File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/engine/default.py", line 941, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) near ">>": syntax error
[SQL: SELECT chat.id AS chat_id, chat.user_id AS chat_user_id, chat.title AS chat_title, chat.chat AS chat_chat, chat.created_at AS chat_created_at, chat.updated_at AS chat_updated_at, chat.share_id AS chat_share_id, chat.archived AS chat_archived, chat.pinned AS chat_pinned, chat.meta AS chat_meta, chat.folder_id AS chat_folder_id
FROM chat
WHERE chat.user_id = ? AND chat.archived = 0 AND (lower(chat.title) LIKE lower(?) OR
                            EXISTS (
                                SELECT 1
                                FROM json_each(Chat.chat, '$.messages') AS message
                                WHERE LOWER(message.value->>'content') LIKE '%' || ? || '%'
                            )
                            ) ORDER BY chat.updated_at DESC
 LIMIT ? OFFSET ?]
[parameters: ('2d105115-89d8-4e58-9ed4-64279956c9b6', '%conver%', 'conver', 60, 0)]
(Background on this error at: https://sqlalche.me/e/20/e3q8)
Originally created by @jakerdy on GitHub (Nov 19, 2024). Original GitHub issue: https://github.com/open-webui/open-webui/issues/7029 # Bug Report --- ## Installation Method It works as python application without docker. I just created venv, installed open_webui and setup systemd service so that it starts automatically. ## Environment - **Open WebUI Version:** v0.3.35 - **Ollama (if applicable):** 0.3.13 - **Operating System:** Ubuntu server 22.04.3 - **Browser (if applicable):** Chrome 130.0 ## Expected Behavior: Search should work without errors. ## Actual Behavior: Browser shows 500 Error in Network tab of Dev-Tools. Console logged that fetch failed. In ui just infinitly spinning spinner, and nothing happens. ## Description **Bug Summary:** I don't know what exactly breaks search but it not working for me. Maybe it some nasty characters in titles that returned from sketchy ollama models, maybe something else. I also tried creating new user, that has no history. Made 2 new chats with OpenAI, that returns valid titles. But still, 500 Internal Server Error. ## Logs and Screenshots **Browser Console Logs:** ![image](https://github.com/user-attachments/assets/55a25094-3a92-47df-aec4-abad288d7ed3) **Python Server Logs:** ``` ERROR: Exception in ASGI application Traceback (most recent call last): File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context self.dialect.do_execute( File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/engine/default.py", line 941, in do_execute cursor.execute(statement, parameters) sqlite3.OperationalError: near ">>": syntax error The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 401, in run_asgi result = await app( # type: ignore[func-returns-value] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__ return await self.app(scope, receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__ await super().__call__(scope, receive, send) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__ await self.middleware_stack(scope, receive, send) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__ raise exc File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__ await self.app(scope, receive, _send) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__ with collapse_excgroups(): File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__ self.gen.throw(typ, value, traceback) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups raise exc File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap await func() File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 217, in stream_response return await super().stream_response(send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response async for chunk in self.body_iterator: File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 181, in body_stream raise app_exc File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro await self.app(scope, receive_or_disconnect, send_no_error) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__ with collapse_excgroups(): File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__ self.gen.throw(typ, value, traceback) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups raise exc File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap await func() File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 217, in stream_response return await super().stream_response(send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response async for chunk in self.body_iterator: File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 181, in body_stream raise app_exc File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro await self.app(scope, receive_or_disconnect, send_no_error) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__ with collapse_excgroups(): File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__ self.gen.throw(typ, value, traceback) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups raise exc File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap await func() File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 217, in stream_response return await super().stream_response(send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response async for chunk in self.body_iterator: File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 181, in body_stream raise app_exc File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro await self.app(scope, receive_or_disconnect, send_no_error) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__ with collapse_excgroups(): File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__ self.gen.throw(typ, value, traceback) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups raise exc File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap await func() File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 217, in stream_response return await super().stream_response(send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response async for chunk in self.body_iterator: File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 181, in body_stream raise app_exc File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro await self.app(scope, receive_or_disconnect, send_no_error) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__ with collapse_excgroups(): File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__ self.gen.throw(typ, value, traceback) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups raise exc File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap await func() File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 217, in stream_response return await super().stream_response(send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response async for chunk in self.body_iterator: File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 181, in body_stream raise app_exc File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro await self.app(scope, receive_or_disconnect, send_no_error) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/cors.py", line 85, in __call__ await self.app(scope, receive, send) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__ with collapse_excgroups(): File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__ self.gen.throw(typ, value, traceback) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups raise exc File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap await func() File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 217, in stream_response return await super().stream_response(send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response async for chunk in self.body_iterator: File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 181, in body_stream raise app_exc File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro await self.app(scope, receive_or_disconnect, send_no_error) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__ with collapse_excgroups(): File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__ self.gen.throw(typ, value, traceback) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups raise exc File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap await func() File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 217, in stream_response return await super().stream_response(send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response async for chunk in self.body_iterator: File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 181, in body_stream raise app_exc File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro await self.app(scope, receive_or_disconnect, send_no_error) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__ with collapse_excgroups(): File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__ self.gen.throw(typ, value, traceback) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups raise exc File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 261, in wrap await func() File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 217, in stream_response return await super().stream_response(send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/responses.py", line 250, in stream_response async for chunk in self.body_iterator: File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 181, in body_stream raise app_exc File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro await self.app(scope, receive_or_disconnect, send_no_error) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 65, in __call__ await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app raise exc File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app await app(scope, receive, sender) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/routing.py", line 756, in __call__ await self.middleware_stack(scope, receive, send) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/routing.py", line 776, in app await route.handle(scope, receive, send) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/routing.py", line 485, in handle await self.app(scope, receive, send) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__ await super().__call__(scope, receive, send) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__ await self.middleware_stack(scope, receive, send) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__ raise exc File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__ await self.app(scope, receive, _send) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/cors.py", line 85, in __call__ await self.app(scope, receive, send) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 65, in __call__ await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app raise exc File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app await app(scope, receive, sender) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/routing.py", line 756, in __call__ await self.middleware_stack(scope, receive, send) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/routing.py", line 776, in app await route.handle(scope, receive, send) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/routing.py", line 297, in handle await self.app(scope, receive, send) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/routing.py", line 77, in app await wrap_app_handling_exceptions(app, request)(scope, receive, send) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app raise exc File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app await app(scope, receive, sender) File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/starlette/routing.py", line 72, in app response = await func(request) ^^^^^^^^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/fastapi/routing.py", line 278, in app raw_response = await run_endpoint_function( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/fastapi/routing.py", line 191, in run_endpoint_function return await dependant.call(**values) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/open_webui/apps/webui/routers/chats.py", line 149, in search_user_chats for chat in Chats.get_chats_by_user_id_and_search_text( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/open_webui/apps/webui/models/chats.py", line 568, in get_chats_by_user_id_and_search_text all_chats = query.offset(skip).limit(limit).all() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/orm/query.py", line 2673, in all return self._iter().all() # type: ignore ^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/orm/query.py", line 2827, in _iter result: Union[ScalarResult[_T], Result[_T]] = self.session.execute( ^^^^^^^^^^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/orm/session.py", line 2362, in execute return self._execute_internal( ^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/orm/session.py", line 2247, in _execute_internal result: Result[Any] = compile_state_cls.orm_execute_statement( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/orm/context.py", line 293, in orm_execute_statement result = conn.execute( ^^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1418, in execute return meth( ^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/sql/elements.py", line 515, in _execute_on_connection return connection._execute_clauseelement( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1640, in _execute_clauseelement ret = self._execute_context( ^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context return self._exec_single_context( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context self._handle_dbapi_exception( File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 2355, in _handle_dbapi_exception raise sqlalchemy_exception.with_traceback(exc_info[2]) from e File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context self.dialect.do_execute( File "/mnt/ssd/sd/apps/open-webui/venv/lib/python3.11/site-packages/sqlalchemy/engine/default.py", line 941, in do_execute cursor.execute(statement, parameters) sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) near ">>": syntax error [SQL: SELECT chat.id AS chat_id, chat.user_id AS chat_user_id, chat.title AS chat_title, chat.chat AS chat_chat, chat.created_at AS chat_created_at, chat.updated_at AS chat_updated_at, chat.share_id AS chat_share_id, chat.archived AS chat_archived, chat.pinned AS chat_pinned, chat.meta AS chat_meta, chat.folder_id AS chat_folder_id FROM chat WHERE chat.user_id = ? AND chat.archived = 0 AND (lower(chat.title) LIKE lower(?) OR EXISTS ( SELECT 1 FROM json_each(Chat.chat, '$.messages') AS message WHERE LOWER(message.value->>'content') LIKE '%' || ? || '%' ) ) ORDER BY chat.updated_at DESC LIMIT ? OFFSET ?] [parameters: ('2d105115-89d8-4e58-9ed4-64279956c9b6', '%conver%', 'conver', 60, 0)] (Background on this error at: https://sqlalche.me/e/20/e3q8) ```
Author
Owner

@jakerdy commented on GitHub (Nov 19, 2024):

Some insights from ChatGPT:

The error you are encountering is due to the use of >> in your SQL query, which is not valid syntax for SQLite. In the query, this syntax is being used in the expression message.value->>'content' which is a PostgreSQL-specific operator for querying JSON data.

SQLite does not support the ->> operator. Instead, SQLite uses its own set of functions to work with JSON data. If you need to query JSON content in SQLite, you should use the json_extract() function.

Here’s how you can modify your query to be compatible with SQLite:

SELECT chat.id AS chat_id, chat.user_id AS chat_user_id, chat.title AS chat_title, 
       chat.chat AS chat_chat, chat.created_at AS chat_created_at, 
       chat.updated_at AS chat_updated_at, chat.share_id AS chat_share_id, 
       chat.archived AS chat_archived, chat.pinned AS chat_pinned, 
       chat.meta AS chat_meta, chat.folder_id AS chat_folder_id 
FROM chat 
WHERE chat.user_id = ? 
  AND chat.archived = 0 
  AND (
      lower(chat.title) LIKE lower(?) 
      OR EXISTS (
          SELECT 1 
          FROM json_each(chat.chat, '$.messages') AS message 
          WHERE LOWER(json_extract(message.value, '$.content')) 
          LIKE '%' || ? || '%'
      )
  ) 
ORDER BY chat.updated_at DESC  
LIMIT ? OFFSET ?

Explanation:

  • Replace message.value->>'content' with json_extract(message.value, '$.content'). This function extracts the content of the JSON field content from message.value.

Points to Consider:

  • Make sure that the JSON structure you're querying is correct and properly indexed, otherwise the performance might be affected.
  • Double-check that all tables and JSON fields you're referencing do indeed exist and that their paths are correctly specified.
  • SQLite's support for JSON is not as comprehensive as some other databases like PostgreSQL, so ensure that your data is modelled appropriately.
<!-- gh-comment-id:2485220899 --> @jakerdy commented on GitHub (Nov 19, 2024): Some insights from ChatGPT: The error you are encountering is due to the use of `>>` in your SQL query, which is not valid syntax for SQLite. In the query, this syntax is being used in the expression `message.value->>'content'` which is a PostgreSQL-specific operator for querying JSON data. SQLite does not support the `->>` operator. Instead, SQLite uses its own set of functions to work with JSON data. If you need to query JSON content in SQLite, you should use the `json_extract()` function. Here’s how you can modify your query to be compatible with SQLite: ```sql SELECT chat.id AS chat_id, chat.user_id AS chat_user_id, chat.title AS chat_title, chat.chat AS chat_chat, chat.created_at AS chat_created_at, chat.updated_at AS chat_updated_at, chat.share_id AS chat_share_id, chat.archived AS chat_archived, chat.pinned AS chat_pinned, chat.meta AS chat_meta, chat.folder_id AS chat_folder_id FROM chat WHERE chat.user_id = ? AND chat.archived = 0 AND ( lower(chat.title) LIKE lower(?) OR EXISTS ( SELECT 1 FROM json_each(chat.chat, '$.messages') AS message WHERE LOWER(json_extract(message.value, '$.content')) LIKE '%' || ? || '%' ) ) ORDER BY chat.updated_at DESC LIMIT ? OFFSET ? ``` **Explanation:** - Replace `message.value->>'content'` with `json_extract(message.value, '$.content')`. This function extracts the content of the JSON field `content` from `message.value`. **Points to Consider:** - Make sure that the JSON structure you're querying is correct and properly indexed, otherwise the performance might be affected. - Double-check that all tables and JSON fields you're referencing do indeed exist and that their paths are correctly specified. - SQLite's support for JSON is not as comprehensive as some other databases like PostgreSQL, so ensure that your data is modelled appropriately.
Author
Owner

@jakerdy commented on GitHub (Nov 19, 2024):

Ok, I found exact place where it breaks:
96c865404d/backend/open_webui/apps/webui/models/chats.py (L477)

I changed it from: WHERE LOWER(message.value->>'content') to WHERE LOWER(json_extract(message.value, '$.content')) and it stats working.

<!-- gh-comment-id:2485290151 --> @jakerdy commented on GitHub (Nov 19, 2024): Ok, I found exact place where it breaks: https://github.com/open-webui/open-webui/blob/96c865404d36637eafadb6d2dd2365c85d452648/backend/open_webui/apps/webui/models/chats.py#L477 I changed it from: `WHERE LOWER(message.value->>'content')` to `WHERE LOWER(json_extract(message.value, '$.content'))` and it stats working.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#14574