mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-03 18:59:38 -05:00
enh: kb metadata search
This commit is contained in:
@@ -157,7 +157,7 @@ def get_citation_source_from_tool_result(
|
||||
- document: list of document contents
|
||||
- metadata: list of metadata objects with source, file_id, name fields
|
||||
|
||||
Returns a list of sources (usually one, but query_knowledge_bases may return multiple).
|
||||
Returns a list of sources (usually one, but query_knowledge_files may return multiple).
|
||||
"""
|
||||
try:
|
||||
if tool_name == "search_web":
|
||||
@@ -217,7 +217,7 @@ def get_citation_source_from_tool_result(
|
||||
}
|
||||
]
|
||||
|
||||
elif tool_name == "query_knowledge_bases":
|
||||
elif tool_name == "query_knowledge_files":
|
||||
chunks = json.loads(tool_result)
|
||||
|
||||
# Group chunks by source for better citation display
|
||||
@@ -3343,7 +3343,7 @@ async def process_chat_response(
|
||||
in [
|
||||
"search_web",
|
||||
"view_knowledge_file",
|
||||
"query_knowledge_bases",
|
||||
"query_knowledge_files",
|
||||
]
|
||||
and tool_result
|
||||
):
|
||||
|
||||
@@ -68,9 +68,10 @@ from open_webui.tools.builtin import (
|
||||
write_note,
|
||||
list_knowledge_bases,
|
||||
search_knowledge_bases,
|
||||
search_knowledge_files,
|
||||
view_knowledge_file,
|
||||
query_knowledge_bases,
|
||||
search_knowledge_files,
|
||||
query_knowledge_files,
|
||||
view_knowledge_file,
|
||||
)
|
||||
|
||||
import copy
|
||||
@@ -406,21 +407,22 @@ def get_builtin_tools(
|
||||
builtin_functions.extend([get_current_timestamp, calculate_timestamp])
|
||||
|
||||
# Knowledge base tools - conditional injection based on model knowledge
|
||||
# If model has attached knowledge (any type), only provide query_knowledge_bases
|
||||
# If model has attached knowledge (any type), only provide query_knowledge_files
|
||||
# Otherwise, provide all KB browsing tools
|
||||
model_knowledge = model.get("info", {}).get("meta", {}).get("knowledge", [])
|
||||
if model_knowledge:
|
||||
# Model has attached knowledge - only allow semantic search within it
|
||||
builtin_functions.append(query_knowledge_bases)
|
||||
builtin_functions.append(query_knowledge_files)
|
||||
else:
|
||||
# No model knowledge - allow full KB browsing
|
||||
builtin_functions.extend(
|
||||
[
|
||||
list_knowledge_bases,
|
||||
search_knowledge_bases,
|
||||
search_knowledge_files,
|
||||
view_knowledge_file,
|
||||
query_knowledge_bases,
|
||||
search_knowledge_files,
|
||||
query_knowledge_files,
|
||||
view_knowledge_file,
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user