Update get_knowledge.py

pull/992/head
2829798842 2025-05-27 20:25:40 +08:00 committed by GitHub
parent cf987f36de
commit 2546f5e7fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 8 deletions

View File

@ -13,12 +13,12 @@ class SearchKnowledgeTool(BaseTool):
"""从知识库中搜索相关信息的工具""" """从知识库中搜索相关信息的工具"""
name = "search_knowledge" name = "search_knowledge"
description = "使用工具从知识库中搜索相关信息" description = "Use tool to search relevant information from the knowledge base"
parameters = { parameters = {
"type": "object", "type": "object",
"properties": { "properties": {
"query": {"type": "string", "description": "搜索查询关键词"}, "query": {"type": "string", "description": "Search query keywords"},
"threshold": {"type": "number", "description": "相似度阈值0.0到1.0之间"}, "threshold": {"type": "number", "description": "Similarity threshold, between 0.0 and 1.0"},
}, },
"required": ["query"], "required": ["query"],
} }
@ -42,14 +42,14 @@ class SearchKnowledgeTool(BaseTool):
if embedding: if embedding:
knowledge_info = self.get_info_from_db(embedding, limit=3, threshold=threshold) knowledge_info = self.get_info_from_db(embedding, limit=3, threshold=threshold)
if knowledge_info: if knowledge_info:
content = f"你知道这些知识: {knowledge_info}" content = f"You know this knowledge: {knowledge_info}"
else: else:
content = f"你不太了解有关{query}的知识" content = f"You don't know much about {query}"
return {"type": "knowledge", "id": query, "content": content} return {"type": "knowledge", "id": query, "content": content}
return {"type": "info", "id": query, "content": f"无法获取关于'{query}'的嵌入向量,你知识库炸了"} return {"type": "info", "id": query, "content": f"Unable to get embedding vector for '{query}', knowledge base failed"}
except Exception as e: except Exception as e:
logger.error(f"知识库搜索工具执行失败: {str(e)}") logger.error(f"Knowledge base search tool execution failed: {str(e)}")
return {"type": "info", "id": query, "content": f"知识库搜索失败,炸了: {str(e)}"} return {"type": "info", "id": query, "content": f"Knowledge base search failed: {str(e)}"}
@staticmethod @staticmethod
def _cosine_similarity(vec1: List[float], vec2: List[float]) -> float: def _cosine_similarity(vec1: List[float], vec2: List[float]) -> float: