feat: 添加知识库检索功能和改进模型路由错误处理

- 在ChatRequest中添加Citation事件类型,支持引用来源展示
- 实现聊天上下文准备服务,构建带源元数据的受限聊天上下文
- 添加ThreadedProcess类以支持Windows平台的子进程操作
- 改进检索引擎中的错误处理和向量搜索逻辑
- 实现严格的嵌入模型验证和索引重建机制
- 添加前端聊天界面的知识库检索开关
- 实现搜索历史记录功能和错误降级处理
- 更新模型路由设置提示信息以反映索引重建需求
This commit is contained in:
2026-09-04 13:02:08 +08:00
parent 8c644d0aae
commit 6eb97bf9ab
20 changed files with 448 additions and 26 deletions
+6 -2
View File
@@ -89,13 +89,17 @@ class RetrievalEngine:
and self.embedding is self._routed_defaults[0]
and self.vector_store is self._routed_defaults[1]
):
vec_hits = await routed_vectors.search_remote(request.query, top_k=recall, accept_local=isinstance(self.embedding, LocalEmbedding))
vec_hits = await routed_vectors.search_remote(
request.query, top_k=recall,
accept_local=isinstance(self.embedding, LocalEmbedding),
strict=isinstance(self.embedding, LocalEmbedding) and request.mode == SearchMode.vector,
)
if vec_hits is None:
if isinstance(self.embedding, LocalEmbedding):
if request.mode == SearchMode.hybrid:
return self._search_fts(request)
from app.errors import ApiError
raise ApiError(409, "SEMANTIC_INDEX_UNAVAILABLE", "语义索引未就绪。请配置 Embedding 或下载本地模型后重建索引")
raise ApiError(503, "EMBEDDING_UNAVAILABLE", "Embedding 服务未就绪,请检查模型路由和本地运行环境")
query_vec = await self.embedding.embed_query(request.query)
vec_hits = await self.vector_store.search(query_vec, top_k=recall)
record_embedding(source="local", model_id=self.embedding.model_id,