Clarify chat retrieval failures

This commit is contained in:
2026-07-08 11:55:22 +08:00
parent ac72b6a94a
commit eda2c5af76
3 changed files with 26 additions and 5 deletions

View File

@@ -107,7 +107,7 @@ class ChatService:
db.commit() db.commit()
raise HTTPException( raise HTTPException(
status_code=status.HTTP_502_BAD_GATEWAY, status_code=status.HTTP_502_BAD_GATEWAY,
detail="外部服务暂时不可用,请稍后再试", detail=str(exc),
) from exc ) from exc
cost_ms = int((perf_counter() - started_at) * 1000) cost_ms = int((perf_counter() - started_at) * 1000)

View File

@@ -267,8 +267,14 @@ class FeishuKnowledgeService:
if config.search_url: if config.search_url:
try: try:
return cls._retrieve_from_search(question, scopes, config) return cls._retrieve_from_search(question, scopes, config)
except ExternalServiceError: except ExternalServiceError as exc:
pass try:
return cls._retrieve_from_feishu(question, scopes)
except ExternalServiceError as fallback_exc:
raise ExternalServiceError(
f"{exc};飞书直读也失败:{fallback_exc}",
provider="feishu",
) from fallback_exc
return cls._retrieve_from_feishu(question, scopes) return cls._retrieve_from_feishu(question, scopes)
@classmethod @classmethod
@@ -298,19 +304,34 @@ class FeishuKnowledgeService:
"""从飞书知识库检索文档内容""" """从飞书知识库检索文档内容"""
from app.services.rag_service import RetrievedChunk from app.services.rag_service import RetrievedChunk
settings = get_settings()
if not settings.feishu_app_id or not settings.feishu_app_secret:
raise ExternalServiceError(
"未配置飞书应用凭证,无法读取飞书知识库。请配置 FEISHU_APP_ID/FEISHU_APP_SECRET"
"或在系统配置中填写可用的飞书搜索接口地址。",
provider="feishu",
)
# 收集所有文档片段 # 收集所有文档片段
all_chunks: list[tuple[KnowledgeScope, str, str, str | None]] = [] all_chunks: list[tuple[KnowledgeScope, str, str, str | None]] = []
load_errors: list[str] = []
for scope in scopes: for scope in scopes:
try: try:
documents = cls._load_documents(scope) documents = cls._load_documents(scope)
except ExternalServiceError: except ExternalServiceError as exc:
load_errors.append(f"{scope.name}{exc}")
continue continue
for title, content, source_url in documents: for title, content, source_url in documents:
all_chunks.append((scope, title, content, source_url)) all_chunks.append((scope, title, content, source_url))
if not all_chunks: if not all_chunks:
if load_errors:
raise ExternalServiceError(
"飞书知识库读取失败:" + "".join(load_errors[:3]),
provider="feishu",
)
return [] return []
# 关键词匹配评分(简单但够用的检索方式) # 关键词匹配评分(简单但够用的检索方式)

View File

@@ -181,7 +181,7 @@ async function scrollToBottom() {
<section class="chat-area"> <section class="chat-area">
<div v-if="messages.length === 0" class="empty-state"> <div v-if="messages.length === 0" class="empty-state">
<strong>可以开始提问了</strong> <strong>可以开始提问了</strong>
<p>当前阶段已接入后端 mock 聊天链路后续会替换为真实飞书知识库检索</p> <p>当前已接入真实知识库检索链路若外部服务未配置或权限不足会在回复区提示具体原因</p>
</div> </div>
<ChatMessage <ChatMessage
v-for="message in messages" v-for="message in messages"