mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-07 11:28:35 -05:00
[GH-ISSUE #22181] issue: v0.8.8 - RAG not triggered for custom model with attached Knowledge Base #35181
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 @CallSohail on GitHub (Mar 3, 2026).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/22181
Check Existing Issues
Installation Method
Docker
Open WebUI Version
v0.8.8-cuda
Ollama Version (if applicable)
0.15.6
Operating System
Debian 12
Browser (if applicable)
Chrome (latest)
Confirmation
README.md.Expected Behavior
When a Knowledge Base is permanently attached to a custom model via Model Settings (Workspace → Models → Edit → Knowledge), asking questions should automatically trigger the full RAG pipeline with hybrid search.
This should work the same way as manually attaching the KB using # in the chat area.
Actual Behavior
RAG is NOT triggered when KB is attached via Model Settings.
RAG IS triggered when same KB is attached via # in chat.
Same model, same KB, same question - different behavior depending on HOW the KB is attached.
Steps to Reproduce
OpenWebUI v0.8.8-cuda, PostgreSQL 16
Create Knowledge Base:
Create Custom Model:
Test 1 - KB attached via Model Settings:
Test 2 - KB attached via # in chat:
Logs & Screenshots
Test 1 - KB attached via Model Settings (NOT WORKING):
Logs show only basic API calls, NO retrieval:
No
query_doc, nohybrid_search- RAG completely skipped.Test 2 - KB attached via # in chat (WORKING):
Logs show full hybrid search pipeline:
Hybrid search triggered, reranker applied, scores calculated.
Additional Information
Configuration:
The KB is correctly attached in Model Settings (visible in UI).
Same KB, same model, same question - only difference is attachment method.
Attaching via Model Settings should auto-inject RAG context like # does.
This appears to be a regression or missing feature in v0.8.8.
@druellan commented on GitHub (Mar 3, 2026):
I have the same issue, since 0.8.x
I tested with a new model, a new knowledge base all of them in public or sharing the same level of access. The KB search never triggers.
In my case I'm not using hybrid search, no reranker, qdrant as vector, but I'm using PostgreSQL 17.
I can't reproduce it in a fresh install with SQLLite, so, my current hypothesis is probably a mismatch in the permissions system or something not correctly migrated in the PSQL database.
@Classic298 commented on GitHub (Mar 3, 2026):
@CallSohail in your first screenshot, the model didn't even use the builtin tools to query the knowledge base.
@druellan native or not native tool calling? cannot reproduce. steps to reproduce?
@Classic298 commented on GitHub (Mar 3, 2026):
how can i reproduce this?
@Classic298 commented on GitHub (Mar 3, 2026):
@CallSohail A few questions to narrow this down:
GLOBAL_LOG_LEVEL=DEBUG? The default log level hides the relevant code paths. Set this env var, reproduce the issue, and share the full output.@druellan Same questions — could you also share DEBUG-level logs when reproducing? Your observation that it works on SQLite but not PostgreSQL is very helpful.
The code path for model-attached KBs (non-native FC) does add the KB items to the retrieval pipeline and should trigger hybrid search. But several error handlers in that path swallow exceptions silently at non-DEBUG log levels, so we need DEBUG logs to see where the flow breaks.
@druellan commented on GitHub (Mar 4, 2026):
Hey @Classic298 sorry the vague report, still working on it but I wanted to chime in.
I can't reproduce it locally on a fresh OWUI intallation, so, still no steps to reproduce it, but I'm going to see if I can gather some logs from production. I bet that besides the postgreSQL another factor that ties both cases is the fact the we both upgraded from early versions
@CallSohail commented on GitHub (Mar 4, 2026):
@Classic298
1. Native function calling: No, it's disabled. When I enable it, the model does call
query_knowledge_basesbuiltin tool but it only uses simple vector search — hybrid search and reranker are bypassed.2. DEBUG logs with
GLOBAL_LOG_LEVEL=DEBUG:As you can see:
tool_ids: None,files: None, nohybrid_searchlogs, noquery_collectionlogs anywhere. The KB attached via Model Settings is not being picked up by the retrieval pipeline. Same question with#KBNamein chat triggers full hybrid search with scores.3. Database: PostgreSQL with pgvector.
@CallSohail commented on GitHub (Mar 4, 2026):
@Classic298
Root Cause Diagnosis: KB via Model Settings Not Injected
1. Where Model Settings Are Loaded Before
process_chat_payloadIn
backend/open_webui/main.py, thechat_completionendpoint (line ~1679) does the following before callingprocess_chat_payload:The
request.app.state.MODELSdict is populated byget_all_models()inutils/models.py, which callscustom_model.model_dump()and assigns the result tomodel["info"]. BecauseModelMetausesmodel_config = ConfigDict(extra="allow"), theknowledgelist (set via Workspace → Models → Edit → Knowledge) is preserved inmodel["info"]["meta"]["knowledge"]. The model object itself is correctly populated — knowledge IS inmodel["info"]["meta"]["knowledge"].Then, at main.py ~line 1769-1779, metadata is built with:
At this point, if the user sent no files in the request,
metadata["files"]isNone. This is what your DEBUG log at line 2072 is showing — it is the metadata snapshot taken at request entry time, before KB injection. The'files': Nonein the log is expected and does not indicate a bug by itself.2. The Code Path That Should Inject Model-Attached KBs
Inside
process_chat_payload(middleware.py), the KB injection for Default mode happens at lines 2179–2222:Then, further down at lines 2300–2378, the
filesare extracted and placed into metadata:Finally,
chat_completion_files_handleris called at line 2641:And
chat_completion_files_handlerreads frombody.get("metadata", {}).get("files", None)at line 1819 — that is, it readsmetadata["files"]which should now contain the KB.The injection is architecturally correct in Default mode — the flow is well-designed. The failures are caused by the issues below.
3. Why
#KBNameWorks But Model Settings KB Fails#KBNamein chat → The frontendChat.svelteappends a file reference to thefilesarray when the user types#KBNameand selects a KB. This is sent as part ofform_data["files"]in the request body. Whenmetadata["files"]is constructed in main.py, it already contains the KB reference, so even before the middleware injection logic, the KB is in the pipeline.chat_completion_files_handlersees it immediately.Model Settings KB → No file reference is sent by the frontend in
form_data["files"]. Instead, the KB lives only inmodel["info"]["meta"]["knowledge"]. The injection must happen server-side in the middleware block at lines 2179–2222. This path has two failure modes:Failure Mode A — Native Function Calling (
function_calling == "native"):If the model or system has
function_calling = "native"set (inmetadata["params"]), the entire block is bypassed. In native mode,get_builtin_tools()intools.pyinstead addsquery_knowledge_filesas a tool for the model to call autonomously (lines 431–438 of tools.py). The model must then decide to call it — it does not receive context-injected chunks. If the model doesn't call the tool, or if the tool parameters don't match, the KB is never retrieved. This is a fundamental behavioral difference.Failure Mode B —
NoneCoercion (the Python Gotcha):At middleware.py line 2220:
Python's
dict.get(key, default)returnsdefaultonly when the key is absent. If the frontend (or a prior filter) explicitly setsform_data["files"] = None, this returnsNone, not[]. Then:This exception propagates up unchecked — there is no
try/exceptaround this block.4. Silent Error Handlers Swallowing Exceptions
The exception from Failure Mode B propagates to
process_chatin main.py (line 1882):log.debug(...)is invisible at INFO, WARNING, or ERROR log levels. Unless you run withLOG_LEVEL=DEBUG, this exception is completely invisible in server logs. The user sees an error in the chat UI (fromchat:message:errorevent) but there is nothing in the server log to trace it to the KB injection code.Additionally, at line 2645–2646 in
chat_completion_files_handler:5. Complete Execution Order Summary
6. Specific Fixes
Fix 1 — None-safe
filesinitialization (middleware.py line 2220):This uses the truthiness check so both missing keys and
Nonevalues return[].Fix 2 — Also fix the folder handling at line 2176 for consistency:
Fix 3 — Elevate the error log in main.py line 1883:
Fix 4 — Native FC path needs explicit context injection for model-attached KBs. In
tools.pylines 431–438, when the model has attached knowledge andquery_knowledge_filesis the designated tool, the current assumption is that the model will call it. For reliability, consider adding the knowledge files toform_data["files"]even in native FC mode, so the content is available viaadd_file_context()at line 2597. Alternatively, document this behavior gap clearly.7. Verifying
model["info"]["meta"]["knowledge"]Reaches MiddlewareTo confirm the model object is the problem vs. the injection logic, add this temporary log immediately before the guard:
This will immediately tell you whether:
model_knowledgeis falsy (model object missing knowledge inrequest.app.state.MODELS)function_calling == "native"is silently bypassing injectionNone.extend()Help from AI :)
@Classic298 commented on GitHub (Mar 4, 2026):
None of this is the "root cause" unlike you claimed and a lot of the "gotchas" you described are intended behaviour.
Of course the native tool calling should bypass the classical automatic forced RAG injection. That's how it is supposed to work.
I will hide your commend for this reason. Thanks for the additional logs, I will research this issue again later today - I would appreciate further logs and steps to reproduce because otherwise i will not be able to reproduce it, not log the issue, not debug it, and not fix it.
I need steps to reproduce and logs.
Thanks