2024-11-05 11:02:31 +08:00
|
|
|
#
|
|
|
|
|
# Copyright 2024 The InfiniFlow Authors. All Rights Reserved.
|
|
|
|
|
#
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
|
#
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
#
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
#
|
|
|
|
|
import json
|
2025-03-26 19:33:14 +08:00
|
|
|
import re
|
2025-08-27 17:16:55 +08:00
|
|
|
|
2026-01-22 11:20:26 +08:00
|
|
|
import logging
|
|
|
|
|
|
2026-04-27 14:02:19 +08:00
|
|
|
from quart import Response, request
|
2026-01-23 02:36:21 +01:00
|
|
|
|
2024-11-05 11:02:31 +08:00
|
|
|
from agent.canvas import Canvas
|
2025-08-13 16:41:01 +08:00
|
|
|
from api.db.db_models import APIToken
|
2024-11-05 11:02:31 +08:00
|
|
|
from api.db.services.api_service import API4ConversationService
|
2026-04-24 10:02:22 +08:00
|
|
|
from api.db.services.canvas_service import UserCanvasService
|
2025-07-23 18:10:05 +08:00
|
|
|
from api.db.services.canvas_service import completion as agent_completion
|
2026-03-17 18:51:26 +08:00
|
|
|
from api.db.services.user_canvas_version import UserCanvasVersionService
|
2025-12-08 09:43:03 +08:00
|
|
|
from api.db.services.conversation_service import async_iframe_completion as iframe_completion
|
2026-04-27 14:02:19 +08:00
|
|
|
from api.db.services.dialog_service import DialogService, async_ask, gen_mindmap
|
2026-01-28 13:29:34 +08:00
|
|
|
from api.db.services.doc_metadata_service import DocMetadataService
|
2024-11-19 14:51:33 +08:00
|
|
|
from api.db.services.knowledgebase_service import KnowledgebaseService
|
2025-04-03 15:51:37 +07:00
|
|
|
from api.db.services.llm_service import LLMBundle
|
2026-04-27 14:02:19 +08:00
|
|
|
from common.metadata_utils import apply_meta_data_filter
|
2025-08-18 12:05:11 +08:00
|
|
|
from api.db.services.search_service import SearchService
|
2026-03-05 17:27:17 +08:00
|
|
|
from api.db.services.user_service import UserTenantService
|
|
|
|
|
from api.db.joint_services.tenant_model_service import get_tenant_default_model_by_type, get_model_config_by_id, \
|
|
|
|
|
get_model_config_by_type_and_name
|
2025-10-31 16:42:01 +08:00
|
|
|
from common.misc_utils import get_uuid
|
2026-04-24 10:02:22 +08:00
|
|
|
from api.utils.api_utils import check_duplicate_ids, get_error_data_result, get_json_result, \
|
2025-12-01 14:24:06 +08:00
|
|
|
get_result, get_request_json, server_error_response, token_required, validate_request
|
2025-08-18 12:05:11 +08:00
|
|
|
from rag.app.tag import label_question
|
2025-09-23 10:19:25 +08:00
|
|
|
from rag.prompts.template import load_prompt
|
2026-04-27 14:02:19 +08:00
|
|
|
from rag.prompts.generator import cross_languages, keyword_extraction
|
|
|
|
|
from common.constants import RetCode, LLMType
|
2025-11-06 09:36:38 +08:00
|
|
|
from common import settings
|
2026-04-30 18:13:27 +03:00
|
|
|
from api.utils.reference_metadata_utils import (
|
|
|
|
|
enrich_chunks_with_document_metadata,
|
|
|
|
|
resolve_reference_metadata_preferences,
|
|
|
|
|
)
|
2025-01-02 16:59:54 +08:00
|
|
|
|
2025-12-11 17:38:17 +08:00
|
|
|
|
2024-11-05 11:02:31 +08:00
|
|
|
@token_required
|
2025-12-01 14:24:06 +08:00
|
|
|
async def create_agent_session(tenant_id, agent_id):
|
2026-03-05 17:26:39 +08:00
|
|
|
req = await get_request_json()
|
|
|
|
|
user_id = req.get("user_id") or request.args.get("user_id", tenant_id)
|
2026-03-13 16:31:17 +08:00
|
|
|
release_mode = bool(req.get("release", request.args.get("release", False)))
|
|
|
|
|
|
2024-12-25 10:48:59 +08:00
|
|
|
if not UserCanvasService.query(user_id=tenant_id, id=agent_id):
|
2024-12-24 15:59:11 +08:00
|
|
|
return get_error_data_result("You cannot access the agent.")
|
2024-11-05 11:02:31 +08:00
|
|
|
|
2026-03-13 16:31:17 +08:00
|
|
|
try:
|
|
|
|
|
cvs, dsl = UserCanvasService.get_agent_dsl_with_release(agent_id, release_mode, tenant_id)
|
|
|
|
|
except LookupError:
|
|
|
|
|
return get_error_data_result("Agent not found.")
|
|
|
|
|
except PermissionError as e:
|
|
|
|
|
return get_error_data_result(str(e))
|
|
|
|
|
|
2025-08-27 17:16:55 +08:00
|
|
|
session_id = get_uuid()
|
2026-03-13 16:31:17 +08:00
|
|
|
canvas = Canvas(dsl, tenant_id, agent_id, canvas_id=cvs.id)
|
2024-12-20 17:34:16 +08:00
|
|
|
canvas.reset()
|
2025-08-27 17:16:55 +08:00
|
|
|
|
2024-12-20 17:34:16 +08:00
|
|
|
cvs.dsl = json.loads(str(canvas))
|
2026-03-17 18:51:26 +08:00
|
|
|
# Get the version title based on release_mode
|
|
|
|
|
version_title = UserCanvasVersionService.get_latest_version_title(cvs.id, release_mode=release_mode)
|
|
|
|
|
conv = {
|
|
|
|
|
"id": session_id,
|
|
|
|
|
"dialog_id": cvs.id,
|
|
|
|
|
"user_id": user_id,
|
|
|
|
|
"message": [{"role": "assistant", "content": canvas.get_prologue()}],
|
|
|
|
|
"source": "agent",
|
|
|
|
|
"dsl": cvs.dsl,
|
|
|
|
|
"version_title": version_title
|
|
|
|
|
}
|
2025-08-25 14:09:28 +08:00
|
|
|
API4ConversationService.save(**conv)
|
2024-11-06 18:03:45 +08:00
|
|
|
conv["agent_id"] = conv.pop("dialog_id")
|
2024-11-05 11:02:31 +08:00
|
|
|
return get_result(data=conv)
|
|
|
|
|
|
|
|
|
|
|
2025-03-26 19:33:14 +08:00
|
|
|
@manager.route("/agents/<agent_id>/sessions", methods=["DELETE"]) # noqa: F821
|
2025-03-03 17:15:16 +08:00
|
|
|
@token_required
|
2025-11-18 17:05:16 +08:00
|
|
|
async def delete_agent_session(tenant_id, agent_id):
|
2025-04-09 19:10:08 +08:00
|
|
|
errors = []
|
|
|
|
|
success_count = 0
|
2025-12-01 14:24:06 +08:00
|
|
|
req = await get_request_json()
|
2025-03-03 17:15:16 +08:00
|
|
|
cvs = UserCanvasService.query(user_id=tenant_id, id=agent_id)
|
|
|
|
|
if not cvs:
|
|
|
|
|
return get_error_data_result(f"You don't own the agent {agent_id}")
|
2025-03-26 19:33:14 +08:00
|
|
|
|
2025-03-03 17:15:16 +08:00
|
|
|
if not req:
|
2026-03-06 18:16:42 +08:00
|
|
|
return get_result()
|
2025-03-03 17:15:16 +08:00
|
|
|
|
2026-03-06 18:16:42 +08:00
|
|
|
ids = req.get("ids")
|
2025-03-03 17:15:16 +08:00
|
|
|
if not ids:
|
2026-03-12 09:47:42 +08:00
|
|
|
if req.get("delete_all") is True:
|
|
|
|
|
ids = [conv.id for conv in API4ConversationService.query(dialog_id=agent_id)]
|
|
|
|
|
if not ids:
|
|
|
|
|
return get_result()
|
|
|
|
|
else:
|
|
|
|
|
return get_result()
|
2026-03-06 18:16:42 +08:00
|
|
|
|
|
|
|
|
conv_list = ids
|
2025-03-26 19:33:14 +08:00
|
|
|
|
2025-04-09 19:10:08 +08:00
|
|
|
unique_conv_ids, duplicate_messages = check_duplicate_ids(conv_list, "session")
|
|
|
|
|
conv_list = unique_conv_ids
|
|
|
|
|
|
2025-03-03 17:15:16 +08:00
|
|
|
for session_id in conv_list:
|
|
|
|
|
conv = API4ConversationService.query(id=session_id, dialog_id=agent_id)
|
|
|
|
|
if not conv:
|
2025-04-09 19:10:08 +08:00
|
|
|
errors.append(f"The agent doesn't own the session {session_id}")
|
|
|
|
|
continue
|
2025-03-03 17:15:16 +08:00
|
|
|
API4ConversationService.delete_by_id(session_id)
|
2025-04-09 19:10:08 +08:00
|
|
|
success_count += 1
|
2025-07-23 18:10:05 +08:00
|
|
|
|
2025-04-09 19:10:08 +08:00
|
|
|
if errors:
|
|
|
|
|
if success_count > 0:
|
2025-10-10 09:17:36 +08:00
|
|
|
return get_result(data={"success_count": success_count, "errors": errors},
|
|
|
|
|
message=f"Partially deleted {success_count} sessions with {len(errors)} errors")
|
2025-04-09 19:10:08 +08:00
|
|
|
else:
|
|
|
|
|
return get_error_data_result(message="; ".join(errors))
|
2025-07-23 18:10:05 +08:00
|
|
|
|
2025-04-09 19:10:08 +08:00
|
|
|
if duplicate_messages:
|
|
|
|
|
if success_count > 0:
|
2025-10-10 09:17:36 +08:00
|
|
|
return get_result(
|
|
|
|
|
message=f"Partially deleted {success_count} sessions with {len(duplicate_messages)} errors",
|
|
|
|
|
data={"success_count": success_count, "errors": duplicate_messages})
|
2025-04-09 19:10:08 +08:00
|
|
|
else:
|
|
|
|
|
return get_error_data_result(message=";".join(duplicate_messages))
|
2025-07-23 18:10:05 +08:00
|
|
|
|
2025-03-03 17:15:16 +08:00
|
|
|
return get_result()
|
|
|
|
|
|
2025-03-26 19:33:14 +08:00
|
|
|
|
2024-12-09 12:38:04 +08:00
|
|
|
|
2025-03-26 19:33:14 +08:00
|
|
|
@manager.route("/chatbots/<dialog_id>/completions", methods=["POST"]) # noqa: F821
|
2025-11-18 17:05:16 +08:00
|
|
|
async def chatbot_completions(dialog_id):
|
2025-12-01 14:24:06 +08:00
|
|
|
req = await get_request_json()
|
2024-12-09 12:38:04 +08:00
|
|
|
|
2025-03-26 19:33:14 +08:00
|
|
|
token = request.headers.get("Authorization").split()
|
2024-12-09 12:38:04 +08:00
|
|
|
if len(token) != 2:
|
2026-02-24 19:14:24 +08:00
|
|
|
return get_error_data_result(message='Authorization is not valid!')
|
2024-12-09 12:38:04 +08:00
|
|
|
token = token[1]
|
|
|
|
|
objs = APIToken.query(beta=token)
|
|
|
|
|
if not objs:
|
2024-12-26 16:08:17 +08:00
|
|
|
return get_error_data_result(message='Authentication error: API key is invalid!"')
|
2024-12-09 12:38:04 +08:00
|
|
|
|
|
|
|
|
if "quote" not in req:
|
|
|
|
|
req["quote"] = False
|
|
|
|
|
|
|
|
|
|
if req.get("stream", True):
|
2024-12-09 17:37:36 +08:00
|
|
|
resp = Response(iframe_completion(dialog_id, **req), mimetype="text/event-stream")
|
2024-12-09 12:38:04 +08:00
|
|
|
resp.headers.add_header("Cache-control", "no-cache")
|
|
|
|
|
resp.headers.add_header("Connection", "keep-alive")
|
|
|
|
|
resp.headers.add_header("X-Accel-Buffering", "no")
|
|
|
|
|
resp.headers.add_header("Content-Type", "text/event-stream; charset=utf-8")
|
|
|
|
|
return resp
|
|
|
|
|
|
2025-12-08 09:43:03 +08:00
|
|
|
async for answer in iframe_completion(dialog_id, **req):
|
2024-12-09 12:38:04 +08:00
|
|
|
return get_result(data=answer)
|
|
|
|
|
|
2025-12-22 16:47:21 +08:00
|
|
|
return None
|
2024-12-09 12:38:04 +08:00
|
|
|
|
2025-08-18 19:01:45 +08:00
|
|
|
@manager.route("/chatbots/<dialog_id>/info", methods=["GET"]) # noqa: F821
|
2025-12-01 14:24:06 +08:00
|
|
|
async def chatbots_inputs(dialog_id):
|
2025-08-18 19:01:45 +08:00
|
|
|
token = request.headers.get("Authorization").split()
|
|
|
|
|
if len(token) != 2:
|
2026-02-24 19:14:24 +08:00
|
|
|
return get_error_data_result(message='Authorization is not valid!')
|
2025-08-18 19:01:45 +08:00
|
|
|
token = token[1]
|
|
|
|
|
objs = APIToken.query(beta=token)
|
|
|
|
|
if not objs:
|
|
|
|
|
return get_error_data_result(message='Authentication error: API key is invalid!"')
|
|
|
|
|
|
|
|
|
|
e, dialog = DialogService.get_by_id(dialog_id)
|
|
|
|
|
if not e:
|
|
|
|
|
return get_error_data_result(f"Can't find dialog by ID: {dialog_id}")
|
|
|
|
|
|
|
|
|
|
return get_result(
|
|
|
|
|
data={
|
|
|
|
|
"title": dialog.name,
|
|
|
|
|
"avatar": dialog.icon,
|
|
|
|
|
"prologue": dialog.prompt_config.get("prologue", ""),
|
2026-01-23 09:33:50 +08:00
|
|
|
"has_tavily_key": bool(dialog.prompt_config.get("tavily_api_key", "").strip()),
|
2025-08-18 19:01:45 +08:00
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2025-03-26 19:33:14 +08:00
|
|
|
@manager.route("/agentbots/<agent_id>/completions", methods=["POST"]) # noqa: F821
|
2025-11-18 17:05:16 +08:00
|
|
|
async def agent_bot_completions(agent_id):
|
2025-12-01 14:24:06 +08:00
|
|
|
req = await get_request_json()
|
2024-12-09 12:38:04 +08:00
|
|
|
|
2025-08-08 17:45:53 +08:00
|
|
|
token = request.headers.get("Authorization").split()
|
|
|
|
|
if len(token) != 2:
|
2026-02-24 19:14:24 +08:00
|
|
|
return get_error_data_result(message='Authorization is not valid!')
|
2025-08-08 17:45:53 +08:00
|
|
|
token = token[1]
|
|
|
|
|
objs = APIToken.query(beta=token)
|
|
|
|
|
if not objs:
|
|
|
|
|
return get_error_data_result(message='Authentication error: API key is invalid!"')
|
|
|
|
|
|
2024-12-09 12:38:04 +08:00
|
|
|
if req.get("stream", True):
|
2026-03-05 17:26:39 +08:00
|
|
|
async def stream():
|
|
|
|
|
try:
|
|
|
|
|
async for answer in agent_completion(objs[0].tenant_id, agent_id, **req):
|
|
|
|
|
yield answer
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logging.exception(e)
|
|
|
|
|
error_result = get_error_data_result(message=str(e) or "Unknown error")
|
|
|
|
|
yield "data:" + json.dumps(
|
|
|
|
|
{
|
|
|
|
|
"event": "message",
|
|
|
|
|
"data": {"content": f"Error {error_result['code']}: {error_result['message']}\n\n"},
|
|
|
|
|
**error_result,
|
|
|
|
|
},
|
|
|
|
|
ensure_ascii=False,
|
|
|
|
|
) + "\n\n"
|
|
|
|
|
|
|
|
|
|
resp = Response(stream(), mimetype="text/event-stream")
|
2024-12-09 12:38:04 +08:00
|
|
|
resp.headers.add_header("Cache-control", "no-cache")
|
|
|
|
|
resp.headers.add_header("Connection", "keep-alive")
|
|
|
|
|
resp.headers.add_header("X-Accel-Buffering", "no")
|
|
|
|
|
resp.headers.add_header("Content-Type", "text/event-stream; charset=utf-8")
|
|
|
|
|
return resp
|
|
|
|
|
|
2026-03-05 17:26:39 +08:00
|
|
|
try:
|
|
|
|
|
async for answer in agent_completion(objs[0].tenant_id, agent_id, **req):
|
|
|
|
|
return get_result(data=answer)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logging.exception(e)
|
|
|
|
|
return get_error_data_result(message=str(e) or "Unknown error")
|
2025-07-30 19:41:09 +08:00
|
|
|
|
2025-12-22 16:47:21 +08:00
|
|
|
return None
|
2025-07-30 19:41:09 +08:00
|
|
|
|
|
|
|
|
@manager.route("/agentbots/<agent_id>/inputs", methods=["GET"]) # noqa: F821
|
2025-12-01 14:24:06 +08:00
|
|
|
async def begin_inputs(agent_id):
|
2025-08-08 17:45:53 +08:00
|
|
|
token = request.headers.get("Authorization").split()
|
|
|
|
|
if len(token) != 2:
|
2026-02-24 19:14:24 +08:00
|
|
|
return get_error_data_result(message='Authorization is not valid!')
|
2025-08-08 17:45:53 +08:00
|
|
|
token = token[1]
|
|
|
|
|
objs = APIToken.query(beta=token)
|
|
|
|
|
if not objs:
|
|
|
|
|
return get_error_data_result(message='Authentication error: API key is invalid!"')
|
|
|
|
|
|
2025-07-30 19:41:09 +08:00
|
|
|
e, cvs = UserCanvasService.get_by_id(agent_id)
|
|
|
|
|
if not e:
|
|
|
|
|
return get_error_data_result(f"Can't find agent by ID: {agent_id}")
|
|
|
|
|
|
2025-12-25 21:18:13 +08:00
|
|
|
canvas = Canvas(json.dumps(cvs.dsl), objs[0].tenant_id, canvas_id=cvs.id)
|
2025-10-10 09:17:36 +08:00
|
|
|
return get_result(
|
|
|
|
|
data={"title": cvs.title, "avatar": cvs.avatar, "inputs": canvas.get_component_input_form("begin"),
|
|
|
|
|
"prologue": canvas.get_prologue(), "mode": canvas.get_mode()})
|
2025-08-18 12:05:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@manager.route("/searchbots/ask", methods=["POST"]) # noqa: F821
|
|
|
|
|
@validate_request("question", "kb_ids")
|
2025-11-18 17:05:16 +08:00
|
|
|
async def ask_about_embedded():
|
2025-08-18 12:05:11 +08:00
|
|
|
token = request.headers.get("Authorization").split()
|
|
|
|
|
if len(token) != 2:
|
2026-02-24 19:14:24 +08:00
|
|
|
return get_error_data_result(message='Authorization is not valid!')
|
2025-08-18 12:05:11 +08:00
|
|
|
token = token[1]
|
|
|
|
|
objs = APIToken.query(beta=token)
|
|
|
|
|
if not objs:
|
|
|
|
|
return get_error_data_result(message='Authentication error: API key is invalid!"')
|
|
|
|
|
|
2025-12-01 14:24:06 +08:00
|
|
|
req = await get_request_json()
|
2025-08-18 12:05:11 +08:00
|
|
|
uid = objs[0].tenant_id
|
|
|
|
|
|
2025-08-19 09:33:33 +08:00
|
|
|
search_id = req.get("search_id", "")
|
|
|
|
|
search_config = {}
|
|
|
|
|
if search_id:
|
|
|
|
|
if search_app := SearchService.get_detail(search_id):
|
|
|
|
|
search_config = search_app.get("search_config", {})
|
|
|
|
|
|
2025-12-08 09:43:03 +08:00
|
|
|
async def stream():
|
2025-08-18 12:05:11 +08:00
|
|
|
nonlocal req, uid
|
|
|
|
|
try:
|
2025-12-08 09:43:03 +08:00
|
|
|
async for ans in async_ask(req["question"], req["kb_ids"], uid, search_config=search_config):
|
2025-08-18 12:05:11 +08:00
|
|
|
yield "data:" + json.dumps({"code": 0, "message": "", "data": ans}, ensure_ascii=False) + "\n\n"
|
|
|
|
|
except Exception as e:
|
2025-10-10 09:17:36 +08:00
|
|
|
yield "data:" + json.dumps(
|
|
|
|
|
{"code": 500, "message": str(e), "data": {"answer": "**ERROR**: " + str(e), "reference": []}},
|
|
|
|
|
ensure_ascii=False) + "\n\n"
|
2025-08-18 12:05:11 +08:00
|
|
|
yield "data:" + json.dumps({"code": 0, "message": "", "data": True}, ensure_ascii=False) + "\n\n"
|
|
|
|
|
|
|
|
|
|
resp = Response(stream(), mimetype="text/event-stream")
|
|
|
|
|
resp.headers.add_header("Cache-control", "no-cache")
|
|
|
|
|
resp.headers.add_header("Connection", "keep-alive")
|
|
|
|
|
resp.headers.add_header("X-Accel-Buffering", "no")
|
|
|
|
|
resp.headers.add_header("Content-Type", "text/event-stream; charset=utf-8")
|
|
|
|
|
return resp
|
|
|
|
|
|
|
|
|
|
|
2025-08-27 17:16:55 +08:00
|
|
|
@manager.route("/searchbots/retrieval_test", methods=["POST"]) # noqa: F821
|
2025-08-18 12:05:11 +08:00
|
|
|
@validate_request("kb_id", "question")
|
2025-11-18 17:05:16 +08:00
|
|
|
async def retrieval_test_embedded():
|
2025-08-18 12:05:11 +08:00
|
|
|
token = request.headers.get("Authorization").split()
|
|
|
|
|
if len(token) != 2:
|
2026-02-24 19:14:24 +08:00
|
|
|
return get_error_data_result(message='Authorization is not valid!')
|
2025-08-18 12:05:11 +08:00
|
|
|
token = token[1]
|
|
|
|
|
objs = APIToken.query(beta=token)
|
|
|
|
|
if not objs:
|
|
|
|
|
return get_error_data_result(message='Authentication error: API key is invalid!"')
|
|
|
|
|
|
2025-12-01 14:24:06 +08:00
|
|
|
req = await get_request_json()
|
2025-08-18 12:05:11 +08:00
|
|
|
page = int(req.get("page", 1))
|
|
|
|
|
size = int(req.get("size", 30))
|
|
|
|
|
question = req["question"]
|
|
|
|
|
kb_ids = req["kb_id"]
|
|
|
|
|
if isinstance(kb_ids, str):
|
|
|
|
|
kb_ids = [kb_ids]
|
2025-09-09 19:45:10 +08:00
|
|
|
if not kb_ids:
|
|
|
|
|
return get_json_result(data=False, message='Please specify dataset firstly.',
|
2025-11-04 15:12:53 +08:00
|
|
|
code=RetCode.DATA_ERROR)
|
2025-08-18 12:05:11 +08:00
|
|
|
doc_ids = req.get("doc_ids", [])
|
|
|
|
|
similarity_threshold = float(req.get("similarity_threshold", 0.0))
|
|
|
|
|
vector_similarity_weight = float(req.get("vector_similarity_weight", 0.3))
|
|
|
|
|
use_kg = req.get("use_kg", False)
|
|
|
|
|
top = int(req.get("top_k", 1024))
|
2026-04-29 14:10:24 +00:00
|
|
|
if top <= 0:
|
|
|
|
|
return get_error_data_result("`top_k` must be greater than 0")
|
2025-08-18 12:05:11 +08:00
|
|
|
langs = req.get("cross_languages", [])
|
top_k parameter ignored, always returned page_size results (#12753)
### What problem does this PR solve?
**Backend**
\rag\nlp\search.py
*Before the fix*
The top_k parameter was not applied to limit the total number of chunks,
and the rerank model also uses the exact whole valid_idx rather than
assigning valid_idx = valid_idx[:top] firstly.
*After the fix*
The top_k limit is applied to the total results before pagination, using
a default value of top = 1024 if top_k is not modified.
session.py
*Before the fix:*
When the frontend calls the retrieval API with `search_id`, the backend
only reads `meta_data_filter` from the saved `search_config`. The
`rerank_id`, `top_k`, `similarity_threshold`, and
`vector_similarity_weight` parameters are only taken from the direct
request body. Since the frontend doesn't pass these parameters
explicitly (it only passes `search_id`), they always fall back to
default values:
- `similarity_threshold` = 0.0
- `vector_similarity_weight` = 0.3
- `top_k` = 1024
- `rerank_id` = "" (no rerank)
This means user settings saved in the Search Settings page have no
effect on actual search results.
*After the fix:*
When a `search_id` is provided, the backend now reads all relevant
configuration from the saved `search_config`, including `rerank_id`,
`top_k`, `similarity_threshold`, and `vector_similarity_weight`. Request
parameters can still override these values if explicitly provided,
allowing flexibility. The rerank model is now properly instantiated
using the configured `rerank_id`, making the rerank feature actually
work.
**Frontend**
\web\src\pages\next-search\search-setting.tsx
*Before the fix*
search-setting.tsx file, the top_k input box is only displayed when
rerank is enabled (wrapped in the rerankModelDisabled condition). If the
rerank switch is turned off, the top_k input field will be hidden, but
the form value will remain unchanged. In other words: - When rerank is
enabled, users can modify top_k (default 1024). - When rerank is
disabled, top_k retains the previous value, but it's not visible on the
interface. Therefore, the backend will always receive the top_k
parameter; it's just that the frontend UI binds this configuration item
to the rerank switch. When rerank is turned off, top_k will not
automatically reset to 1024, but will retain its original value.
*After the fix*
On the contrary, if we switch off the button rerank model, the value
top-k will be reset to 1024. By the way, If we use top-k in an
individual method, rather than put it into the method retrieval, we can
control it separately
Now all methods valid
Using rerank
<img width="2378" height="1565" alt="Screenshot 2026-01-21 190206"
src="https://github.com/user-attachments/assets/fa2b0df0-1334-4ca3-b169-da6c5fd59935"
/>
Not using rerank
<img width="2596" height="1559" alt="Screenshot 2026-01-21 190229"
src="https://github.com/user-attachments/assets/c5a80522-a0e1-40e7-b349-42fe86df3138"
/>
Before fixing they are the same
### Type of change
- Bug Fix (non-breaking change which fixes an issue)
2026-01-22 15:33:42 +08:00
|
|
|
rerank_id = req.get("rerank_id", "")
|
2026-03-05 17:27:17 +08:00
|
|
|
tenant_rerank_id = req.get("tenant_rerank_id", "")
|
2025-08-18 12:05:11 +08:00
|
|
|
tenant_id = objs[0].tenant_id
|
|
|
|
|
if not tenant_id:
|
|
|
|
|
return get_error_data_result(message="permission denined.")
|
2026-04-30 18:13:27 +03:00
|
|
|
search_config = {}
|
2025-08-18 12:05:11 +08:00
|
|
|
|
2025-12-11 17:38:17 +08:00
|
|
|
async def _retrieval():
|
top_k parameter ignored, always returned page_size results (#12753)
### What problem does this PR solve?
**Backend**
\rag\nlp\search.py
*Before the fix*
The top_k parameter was not applied to limit the total number of chunks,
and the rerank model also uses the exact whole valid_idx rather than
assigning valid_idx = valid_idx[:top] firstly.
*After the fix*
The top_k limit is applied to the total results before pagination, using
a default value of top = 1024 if top_k is not modified.
session.py
*Before the fix:*
When the frontend calls the retrieval API with `search_id`, the backend
only reads `meta_data_filter` from the saved `search_config`. The
`rerank_id`, `top_k`, `similarity_threshold`, and
`vector_similarity_weight` parameters are only taken from the direct
request body. Since the frontend doesn't pass these parameters
explicitly (it only passes `search_id`), they always fall back to
default values:
- `similarity_threshold` = 0.0
- `vector_similarity_weight` = 0.3
- `top_k` = 1024
- `rerank_id` = "" (no rerank)
This means user settings saved in the Search Settings page have no
effect on actual search results.
*After the fix:*
When a `search_id` is provided, the backend now reads all relevant
configuration from the saved `search_config`, including `rerank_id`,
`top_k`, `similarity_threshold`, and `vector_similarity_weight`. Request
parameters can still override these values if explicitly provided,
allowing flexibility. The rerank model is now properly instantiated
using the configured `rerank_id`, making the rerank feature actually
work.
**Frontend**
\web\src\pages\next-search\search-setting.tsx
*Before the fix*
search-setting.tsx file, the top_k input box is only displayed when
rerank is enabled (wrapped in the rerankModelDisabled condition). If the
rerank switch is turned off, the top_k input field will be hidden, but
the form value will remain unchanged. In other words: - When rerank is
enabled, users can modify top_k (default 1024). - When rerank is
disabled, top_k retains the previous value, but it's not visible on the
interface. Therefore, the backend will always receive the top_k
parameter; it's just that the frontend UI binds this configuration item
to the rerank switch. When rerank is turned off, top_k will not
automatically reset to 1024, but will retain its original value.
*After the fix*
On the contrary, if we switch off the button rerank model, the value
top-k will be reset to 1024. By the way, If we use top-k in an
individual method, rather than put it into the method retrieval, we can
control it separately
Now all methods valid
Using rerank
<img width="2378" height="1565" alt="Screenshot 2026-01-21 190206"
src="https://github.com/user-attachments/assets/fa2b0df0-1334-4ca3-b169-da6c5fd59935"
/>
Not using rerank
<img width="2596" height="1559" alt="Screenshot 2026-01-21 190229"
src="https://github.com/user-attachments/assets/c5a80522-a0e1-40e7-b349-42fe86df3138"
/>
Before fixing they are the same
### Type of change
- Bug Fix (non-breaking change which fixes an issue)
2026-01-22 15:33:42 +08:00
|
|
|
nonlocal similarity_threshold, vector_similarity_weight, top, rerank_id
|
2025-12-03 14:19:53 +08:00
|
|
|
local_doc_ids = list(doc_ids) if doc_ids else []
|
|
|
|
|
tenant_ids = []
|
|
|
|
|
_question = question
|
|
|
|
|
|
2025-12-12 17:12:38 +08:00
|
|
|
meta_data_filter = {}
|
|
|
|
|
chat_mdl = None
|
2025-12-03 14:19:53 +08:00
|
|
|
if req.get("search_id", ""):
|
2026-04-30 18:13:27 +03:00
|
|
|
nonlocal search_config
|
|
|
|
|
detail = SearchService.get_detail(req.get("search_id", ""))
|
|
|
|
|
if detail:
|
|
|
|
|
search_config = detail.get("search_config", {})
|
|
|
|
|
meta_data_filter = search_config.get("meta_data_filter", {})
|
2025-12-12 17:12:38 +08:00
|
|
|
if meta_data_filter.get("method") in ["auto", "semi_auto"]:
|
2026-03-05 17:27:17 +08:00
|
|
|
chat_id = search_config.get("chat_id", "")
|
|
|
|
|
if chat_id:
|
|
|
|
|
chat_model_config = get_model_config_by_type_and_name(tenant_id, LLMType.CHAT, chat_id)
|
|
|
|
|
else:
|
|
|
|
|
chat_model_config = get_tenant_default_model_by_type(tenant_id, LLMType.CHAT)
|
|
|
|
|
chat_mdl = LLMBundle(tenant_id, chat_model_config)
|
top_k parameter ignored, always returned page_size results (#12753)
### What problem does this PR solve?
**Backend**
\rag\nlp\search.py
*Before the fix*
The top_k parameter was not applied to limit the total number of chunks,
and the rerank model also uses the exact whole valid_idx rather than
assigning valid_idx = valid_idx[:top] firstly.
*After the fix*
The top_k limit is applied to the total results before pagination, using
a default value of top = 1024 if top_k is not modified.
session.py
*Before the fix:*
When the frontend calls the retrieval API with `search_id`, the backend
only reads `meta_data_filter` from the saved `search_config`. The
`rerank_id`, `top_k`, `similarity_threshold`, and
`vector_similarity_weight` parameters are only taken from the direct
request body. Since the frontend doesn't pass these parameters
explicitly (it only passes `search_id`), they always fall back to
default values:
- `similarity_threshold` = 0.0
- `vector_similarity_weight` = 0.3
- `top_k` = 1024
- `rerank_id` = "" (no rerank)
This means user settings saved in the Search Settings page have no
effect on actual search results.
*After the fix:*
When a `search_id` is provided, the backend now reads all relevant
configuration from the saved `search_config`, including `rerank_id`,
`top_k`, `similarity_threshold`, and `vector_similarity_weight`. Request
parameters can still override these values if explicitly provided,
allowing flexibility. The rerank model is now properly instantiated
using the configured `rerank_id`, making the rerank feature actually
work.
**Frontend**
\web\src\pages\next-search\search-setting.tsx
*Before the fix*
search-setting.tsx file, the top_k input box is only displayed when
rerank is enabled (wrapped in the rerankModelDisabled condition). If the
rerank switch is turned off, the top_k input field will be hidden, but
the form value will remain unchanged. In other words: - When rerank is
enabled, users can modify top_k (default 1024). - When rerank is
disabled, top_k retains the previous value, but it's not visible on the
interface. Therefore, the backend will always receive the top_k
parameter; it's just that the frontend UI binds this configuration item
to the rerank switch. When rerank is turned off, top_k will not
automatically reset to 1024, but will retain its original value.
*After the fix*
On the contrary, if we switch off the button rerank model, the value
top-k will be reset to 1024. By the way, If we use top-k in an
individual method, rather than put it into the method retrieval, we can
control it separately
Now all methods valid
Using rerank
<img width="2378" height="1565" alt="Screenshot 2026-01-21 190206"
src="https://github.com/user-attachments/assets/fa2b0df0-1334-4ca3-b169-da6c5fd59935"
/>
Not using rerank
<img width="2596" height="1559" alt="Screenshot 2026-01-21 190229"
src="https://github.com/user-attachments/assets/c5a80522-a0e1-40e7-b349-42fe86df3138"
/>
Before fixing they are the same
### Type of change
- Bug Fix (non-breaking change which fixes an issue)
2026-01-22 15:33:42 +08:00
|
|
|
# Apply search_config settings if not explicitly provided in request
|
|
|
|
|
if not req.get("similarity_threshold"):
|
|
|
|
|
similarity_threshold = float(search_config.get("similarity_threshold", similarity_threshold))
|
|
|
|
|
if not req.get("vector_similarity_weight"):
|
|
|
|
|
vector_similarity_weight = float(search_config.get("vector_similarity_weight", vector_similarity_weight))
|
|
|
|
|
if not req.get("top_k"):
|
|
|
|
|
top = int(search_config.get("top_k", top))
|
|
|
|
|
if not req.get("rerank_id"):
|
|
|
|
|
rerank_id = search_config.get("rerank_id", "")
|
2025-12-11 10:45:21 +08:00
|
|
|
else:
|
2025-12-12 17:12:38 +08:00
|
|
|
meta_data_filter = req.get("meta_data_filter") or {}
|
|
|
|
|
if meta_data_filter.get("method") in ["auto", "semi_auto"]:
|
2026-03-05 17:27:17 +08:00
|
|
|
chat_model_config = get_tenant_default_model_by_type(tenant_id, LLMType.CHAT)
|
|
|
|
|
chat_mdl = LLMBundle(tenant_id, chat_model_config)
|
2025-12-12 17:12:38 +08:00
|
|
|
|
|
|
|
|
if meta_data_filter:
|
2026-01-28 13:29:34 +08:00
|
|
|
metas = DocMetadataService.get_flatted_meta_by_kbs(kb_ids)
|
2025-12-12 17:12:38 +08:00
|
|
|
local_doc_ids = await apply_meta_data_filter(meta_data_filter, metas, _question, chat_mdl, local_doc_ids)
|
2025-12-11 10:45:21 +08:00
|
|
|
|
2025-08-18 12:05:11 +08:00
|
|
|
tenants = UserTenantService.query(user_id=tenant_id)
|
|
|
|
|
for kb_id in kb_ids:
|
|
|
|
|
for tenant in tenants:
|
2025-08-27 17:16:55 +08:00
|
|
|
if KnowledgebaseService.query(tenant_id=tenant.tenant_id, id=kb_id):
|
2025-08-18 12:05:11 +08:00
|
|
|
tenant_ids.append(tenant.tenant_id)
|
|
|
|
|
break
|
|
|
|
|
else:
|
2025-12-17 10:03:33 +08:00
|
|
|
return get_json_result(data=False, message="Only owner of dataset authorized for this operation.",
|
2025-11-04 15:12:53 +08:00
|
|
|
code=RetCode.OPERATING_ERROR)
|
2025-08-18 12:05:11 +08:00
|
|
|
|
|
|
|
|
e, kb = KnowledgebaseService.get_by_id(kb_ids[0])
|
|
|
|
|
if not e:
|
|
|
|
|
return get_error_data_result(message="Knowledgebase not found!")
|
|
|
|
|
|
|
|
|
|
if langs:
|
2025-12-11 17:38:17 +08:00
|
|
|
_question = await cross_languages(kb.tenant_id, None, _question, langs)
|
2026-03-05 17:27:17 +08:00
|
|
|
if kb.tenant_embd_id:
|
|
|
|
|
embd_model_config = get_model_config_by_id(kb.tenant_embd_id)
|
|
|
|
|
else:
|
|
|
|
|
embd_model_config = get_model_config_by_type_and_name(kb.tenant_id, LLMType.EMBEDDING, kb.embd_id)
|
|
|
|
|
embd_mdl = LLMBundle(kb.tenant_id, embd_model_config)
|
2025-08-18 12:05:11 +08:00
|
|
|
|
|
|
|
|
rerank_mdl = None
|
2026-03-05 17:27:17 +08:00
|
|
|
if tenant_rerank_id:
|
|
|
|
|
rerank_model_config = get_model_config_by_id(tenant_rerank_id)
|
|
|
|
|
rerank_mdl = LLMBundle(kb.tenant_id, rerank_model_config)
|
|
|
|
|
elif rerank_id:
|
|
|
|
|
rerank_model_config = get_model_config_by_type_and_name(tenant_id, LLMType.RERANK, rerank_id)
|
|
|
|
|
rerank_mdl = LLMBundle(kb.tenant_id, rerank_model_config)
|
2025-08-18 12:05:11 +08:00
|
|
|
|
|
|
|
|
if req.get("keyword", False):
|
2026-03-05 17:27:17 +08:00
|
|
|
default_chat_model = get_tenant_default_model_by_type(kb.tenant_id, LLMType.CHAT)
|
|
|
|
|
chat_mdl = LLMBundle(kb.tenant_id, default_chat_model)
|
2025-12-11 17:38:17 +08:00
|
|
|
_question += await keyword_extraction(chat_mdl, _question)
|
2025-08-18 12:05:11 +08:00
|
|
|
|
2025-12-03 14:19:53 +08:00
|
|
|
labels = label_question(_question, [kb])
|
2026-01-15 12:28:49 +08:00
|
|
|
ranks = await settings.retriever.retrieval(
|
2025-12-03 14:19:53 +08:00
|
|
|
_question, embd_mdl, tenant_ids, kb_ids, page, size, similarity_threshold, vector_similarity_weight, top,
|
|
|
|
|
local_doc_ids, rerank_mdl=rerank_mdl, highlight=req.get("highlight"), rank_feature=labels
|
2025-08-27 17:16:55 +08:00
|
|
|
)
|
2025-08-18 12:05:11 +08:00
|
|
|
if use_kg:
|
2026-03-05 17:27:17 +08:00
|
|
|
default_chat_model = get_tenant_default_model_by_type(kb.tenant_id, LLMType.CHAT)
|
2025-12-31 14:40:27 +08:00
|
|
|
ck = await settings.kg_retriever.retrieval(_question, tenant_ids, kb_ids, embd_mdl,
|
2026-03-05 17:27:17 +08:00
|
|
|
LLMBundle(kb.tenant_id, default_chat_model))
|
2025-08-18 12:05:11 +08:00
|
|
|
if ck["content_with_weight"]:
|
|
|
|
|
ranks["chunks"].insert(0, ck)
|
|
|
|
|
|
|
|
|
|
for c in ranks["chunks"]:
|
|
|
|
|
c.pop("vector", None)
|
2026-04-30 18:13:27 +03:00
|
|
|
|
|
|
|
|
include_metadata, metadata_fields = _resolve_reference_metadata(req, search_config)
|
|
|
|
|
if include_metadata:
|
|
|
|
|
enrich_chunks_with_document_metadata(ranks["chunks"], metadata_fields)
|
|
|
|
|
|
2025-08-18 12:05:11 +08:00
|
|
|
ranks["labels"] = labels
|
|
|
|
|
|
|
|
|
|
return get_json_result(data=ranks)
|
2025-12-03 14:19:53 +08:00
|
|
|
|
|
|
|
|
try:
|
2025-12-11 17:38:17 +08:00
|
|
|
return await _retrieval()
|
2025-08-18 12:05:11 +08:00
|
|
|
except Exception as e:
|
|
|
|
|
if str(e).find("not_found") > 0:
|
2025-10-10 09:17:36 +08:00
|
|
|
return get_json_result(data=False, message="No chunk found! Check the chunk status please!",
|
2025-11-04 15:12:53 +08:00
|
|
|
code=RetCode.DATA_ERROR)
|
2025-08-18 12:05:11 +08:00
|
|
|
return server_error_response(e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@manager.route("/searchbots/related_questions", methods=["POST"]) # noqa: F821
|
|
|
|
|
@validate_request("question")
|
2025-11-18 17:05:16 +08:00
|
|
|
async def related_questions_embedded():
|
2025-08-18 12:05:11 +08:00
|
|
|
token = request.headers.get("Authorization").split()
|
|
|
|
|
if len(token) != 2:
|
2026-02-24 19:14:24 +08:00
|
|
|
return get_error_data_result(message='Authorization is not valid!')
|
2025-08-18 12:05:11 +08:00
|
|
|
token = token[1]
|
|
|
|
|
objs = APIToken.query(beta=token)
|
|
|
|
|
if not objs:
|
|
|
|
|
return get_error_data_result(message='Authentication error: API key is invalid!"')
|
|
|
|
|
|
2025-12-01 14:24:06 +08:00
|
|
|
req = await get_request_json()
|
2025-08-18 12:05:11 +08:00
|
|
|
tenant_id = objs[0].tenant_id
|
|
|
|
|
if not tenant_id:
|
|
|
|
|
return get_error_data_result(message="permission denined.")
|
2025-08-19 09:33:33 +08:00
|
|
|
|
|
|
|
|
search_id = req.get("search_id", "")
|
|
|
|
|
search_config = {}
|
|
|
|
|
if search_id:
|
|
|
|
|
if search_app := SearchService.get_detail(search_id):
|
|
|
|
|
search_config = search_app.get("search_config", {})
|
|
|
|
|
|
2025-08-18 12:05:11 +08:00
|
|
|
question = req["question"]
|
2025-08-19 09:33:33 +08:00
|
|
|
|
|
|
|
|
chat_id = search_config.get("chat_id", "")
|
2026-03-05 17:27:17 +08:00
|
|
|
if chat_id:
|
|
|
|
|
chat_model_config = get_model_config_by_type_and_name(tenant_id, LLMType.CHAT, chat_id)
|
|
|
|
|
else:
|
|
|
|
|
chat_model_config = get_tenant_default_model_by_type(tenant_id, LLMType.CHAT)
|
|
|
|
|
chat_mdl = LLMBundle(tenant_id, chat_model_config)
|
2025-08-19 09:33:33 +08:00
|
|
|
|
|
|
|
|
gen_conf = search_config.get("llm_setting", {"temperature": 0.9})
|
2025-08-18 12:05:11 +08:00
|
|
|
prompt = load_prompt("related_question")
|
2025-12-03 14:19:53 +08:00
|
|
|
ans = await chat_mdl.async_chat(
|
2025-08-18 12:05:11 +08:00
|
|
|
prompt,
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
"role": "user",
|
|
|
|
|
"content": f"""
|
|
|
|
|
Keywords: {question}
|
|
|
|
|
Related search terms:
|
|
|
|
|
""",
|
|
|
|
|
}
|
|
|
|
|
],
|
2025-08-19 09:33:33 +08:00
|
|
|
gen_conf,
|
2025-08-18 12:05:11 +08:00
|
|
|
)
|
|
|
|
|
return get_json_result(data=[re.sub(r"^[0-9]\. ", "", a) for a in ans.split("\n") if re.match(r"^[0-9]\. ", a)])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@manager.route("/searchbots/detail", methods=["GET"]) # noqa: F821
|
2025-12-01 14:24:06 +08:00
|
|
|
async def detail_share_embedded():
|
2025-08-18 12:05:11 +08:00
|
|
|
token = request.headers.get("Authorization").split()
|
|
|
|
|
if len(token) != 2:
|
2026-02-24 19:14:24 +08:00
|
|
|
return get_error_data_result(message='Authorization is not valid!')
|
2025-08-18 12:05:11 +08:00
|
|
|
token = token[1]
|
|
|
|
|
objs = APIToken.query(beta=token)
|
|
|
|
|
if not objs:
|
|
|
|
|
return get_error_data_result(message='Authentication error: API key is invalid!"')
|
|
|
|
|
|
|
|
|
|
search_id = request.args["search_id"]
|
|
|
|
|
tenant_id = objs[0].tenant_id
|
|
|
|
|
if not tenant_id:
|
|
|
|
|
return get_error_data_result(message="permission denined.")
|
|
|
|
|
try:
|
|
|
|
|
tenants = UserTenantService.query(user_id=tenant_id)
|
|
|
|
|
for tenant in tenants:
|
|
|
|
|
if SearchService.query(tenant_id=tenant.tenant_id, id=search_id):
|
|
|
|
|
break
|
|
|
|
|
else:
|
2025-10-10 09:17:36 +08:00
|
|
|
return get_json_result(data=False, message="Has no permission for this operation.",
|
2025-11-04 15:12:53 +08:00
|
|
|
code=RetCode.OPERATING_ERROR)
|
2025-08-18 12:05:11 +08:00
|
|
|
|
|
|
|
|
search = SearchService.get_detail(search_id)
|
|
|
|
|
if not search:
|
|
|
|
|
return get_error_data_result(message="Can't find this Search App!")
|
|
|
|
|
return get_json_result(data=search)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
return server_error_response(e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@manager.route("/searchbots/mindmap", methods=["POST"]) # noqa: F821
|
|
|
|
|
@validate_request("question", "kb_ids")
|
2025-11-18 17:05:16 +08:00
|
|
|
async def mindmap():
|
2025-08-18 12:05:11 +08:00
|
|
|
token = request.headers.get("Authorization").split()
|
|
|
|
|
if len(token) != 2:
|
2026-02-24 19:14:24 +08:00
|
|
|
return get_error_data_result(message='Authorization is not valid!')
|
2025-08-18 12:05:11 +08:00
|
|
|
token = token[1]
|
|
|
|
|
objs = APIToken.query(beta=token)
|
|
|
|
|
if not objs:
|
|
|
|
|
return get_error_data_result(message='Authentication error: API key is invalid!"')
|
|
|
|
|
|
|
|
|
|
tenant_id = objs[0].tenant_id
|
2025-12-01 14:24:06 +08:00
|
|
|
req = await get_request_json()
|
2025-08-19 09:33:33 +08:00
|
|
|
|
|
|
|
|
search_id = req.get("search_id", "")
|
2025-08-19 17:25:44 +08:00
|
|
|
search_app = SearchService.get_detail(search_id) if search_id else {}
|
2025-08-19 09:33:33 +08:00
|
|
|
|
2025-12-11 13:54:47 +08:00
|
|
|
mind_map =await gen_mindmap(req["question"], req["kb_ids"], tenant_id, search_app.get("search_config", {}))
|
2025-08-18 12:05:11 +08:00
|
|
|
if "error" in mind_map:
|
|
|
|
|
return server_error_response(Exception(mind_map["error"]))
|
|
|
|
|
return get_json_result(data=mind_map)
|
2026-01-22 11:20:26 +08:00
|
|
|
|
2026-04-30 18:13:27 +03:00
|
|
|
|
|
|
|
|
def _resolve_reference_metadata(req, search_config=None):
|
|
|
|
|
return resolve_reference_metadata_preferences(req, search_config)
|