If RAG is toggled on but the active scope (thread or KB) has zero indexed documents, exposing search_knowledge_base to the model just wastes a tool-call turn — the model calls the tool, gets back 'no matching chunks', and has to re-plan. The system prompt nudge that instructs the model to call the tool before answering is similarly counterproductive. Frontend: before computing ragToolPathTaken in chat-adapter, fetch the document list for the current scope (KB or thread) and require docs to exist. The flag now gates both the system prompt injection and the enabled_tools list. Defensive fallback: if the docs lookup fails the flag stays true so we don't silently swallow RAG. Backend: add _drop_rag_tool_if_scope_empty in routes/inference.py that counts rag_documents for the request's rag_scope and strips search_knowledge_base from the tool list when 0. Applied at both chat-completion tool-filter sites so the protection works regardless of which streaming path serves the request. |
||
|---|---|---|
| .. | ||
| assets | ||
| auth | ||
| core | ||
| loggers | ||
| models | ||
| plugins | ||
| requirements | ||
| routes | ||
| state | ||
| storage | ||
| tests | ||
| utils | ||
| __init__.py | ||
| _platform_compat.py | ||
| colab.py | ||
| main.py | ||
| run.py | ||
| startup_banner.py | ||