feat: 性能插桩、缓存清除端点、LLM top_p 与 JSON 强制输出

- chat_routes.py: 新增 8 阶段性能计时(stages_ms)+ SSE 输出
- sync_routes.py: 新增 POST /cache/clear 缓存清除端点
- engine.py: LLM 调用增加 top_p 参数
- intent_analyzer.py: response_format 加配置开关(INTENT_RESPONSE_FORMAT)
This commit is contained in:
lacerate551
2026-06-21 20:25:12 +08:00
parent c6a17ad1e4
commit 6d5a4b5b5e
4 changed files with 76 additions and 12 deletions

View File

@@ -315,3 +315,48 @@ def stop_sync_monitor() -> Tuple[Any, int]:
message="操作失败",
http_status=500
)
# ==================== 缓存管理 API ====================
@sync_bp.route('/cache/clear', methods=['POST'])
@require_gateway_auth
def clear_all_caches() -> Tuple[Any, int]:
"""
清除所有缓存层Query / Embedding / Rerank / Semantic / Intent 精确缓存)
用于测试和调试,不影响向量库数据。
Returns:
{"success": true, "message": "缓存已清除", "cleared": [...]}
"""
cleared = []
# 1. 精确匹配缓存Query / Embedding / Rerank
try:
from core.cache import get_cache_manager
cache = get_cache_manager()
if cache:
cache.clear_all()
cleared.append("query_cache")
cleared.append("embedding_cache")
cleared.append("rerank_cache")
except Exception as e:
logger.warning(f"清除精确缓存失败: {e}")
# 2. 语义缓存FAISS
try:
from core.semantic_cache import get_semantic_cache
sc = get_semantic_cache()
if sc:
sc.clear()
cleared.append("semantic_cache")
except Exception as e:
logger.warning(f"清除语义缓存失败: {e}")
logger.info(f"缓存清除完成: {cleared}")
return jsonify({
"success": True,
"message": f"已清除 {len(cleared)} 层缓存",
"cleared": cleared
})