baodan/api/insurance/kb/retrieval_routes.py

27 lines
817 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""知识库检索路由(独立 Blueprint
POST /retrieval/search 向量检索
"""
from flask import Blueprint, request, jsonify
from insurance.kb.service import KBService
from insurance.middleware.auth_middleware import jwt_required
retrieval_bp = Blueprint("retrieval", __name__)
kb_service = KBService()
@retrieval_bp.route("/search", methods=["POST"])
@jwt_required
def retrieval_search():
"""向量检索接口:独立于对话,直接检索知识库。"""
data = request.get_json()
query = data.get("query", "")
filters = data.get("filters", {})
top_k = data.get("top_k", 5)
if not query:
return jsonify({"code": 1001, "message": "请输入搜索内容", "data": None}), 400
result = kb_service.retrieval_search(query, filters, top_k)
return jsonify(result)