feat: 添加默认查询参数提取功能,优化知识库检索配置加载

This commit is contained in:
Wenjie Zhang 2026-05-06 23:09:45 +08:00
parent ab513e2619
commit 7b664e35d0
3 changed files with 17 additions and 9 deletions

View File

@ -453,6 +453,7 @@ class KnowledgeBase(ABC):
"llm_info": llm_info.model_dump() if hasattr(llm_info, "model_dump") else llm_info,
"metadata": kwargs,
"created_at": utc_isoformat(),
"query_params": self._get_default_query_params(db_id),
}
await self._persist_kb(db_id)
@ -642,6 +643,15 @@ class KnowledgeBase(ABC):
return query_params_meta.get("options", {})
return {}
def _get_default_query_params(self, db_id: str) -> dict[str, Any]:
"""从 get_query_params_config 中提取所有参数的默认值,返回 {"options": {...}}"""
config = self.get_query_params_config(db_id)
defaults = {}
for opt in config.get("options", []):
if "default" in opt:
defaults[opt["key"]] = opt["default"]
return {"options": defaults}
def get_database_info(self, db_id: str, include_files: bool = True) -> dict | None:
"""
获取数据库详细信息
@ -1046,7 +1056,7 @@ class KnowledgeBase(ABC):
"kb_type": kb.kb_type,
"embed_info": kb.embed_info,
"llm_info": kb.llm_info,
"query_params": kb.query_params,
"query_params": kb.query_params or self._get_default_query_params(kb.db_id),
"metadata": ensure_chunk_defaults_in_additional_params(kb.additional_params),
"created_at": utc_isoformat(kb.created_at) if kb.created_at else utc_isoformat(),
}

View File

@ -363,6 +363,10 @@ class EvaluationService:
kb_row = await self.kb_repo.get_by_id(db_id)
query_params = (kb_row.query_params if kb_row else None) or {}
retrieval_config = query_params.get("options", {}) if isinstance(query_params, dict) else {}
if not retrieval_config:
kb_instance = await knowledge_base.aget_kb(db_id)
if kb_instance:
retrieval_config = kb_instance._get_default_query_params(db_id).get("options", {})
logger.info(f"从知识库 {db_id} 加载检索配置: {list(retrieval_config.keys())}")
except Exception as e:
logger.error(f"获取知识库检索配置失败: {e}")

View File

@ -681,8 +681,8 @@ const switchToUser = async (user) => {
.log-container {
height: calc(80vh - 200px);
overflow-y: auto;
background: var(--gray-0);
color: var(--gray-1000);
background: #1e1f1f;
color: #ffffff;
border-radius: 5px;
font-family: 'Consolas', 'Monaco', monospace;
font-size: 12px;
@ -754,12 +754,6 @@ const switchToUser = async (user) => {
color: var(--gray-500);
}
@media (prefers-color-scheme: dark) {
.log-container {
background: var(--gray-900);
}
}
:fullscreen .log-container {
height: calc(100vh - 160px);
}