feat: 添加知识库名称检查,防止重复创建相同名称的知识库 #466
This commit is contained in:
parent
386c5d5dad
commit
9fa8ce288f
@ -38,14 +38,16 @@
|
||||
- 优化 RAG 检索,支持根据文件 pattern 来检索(Agentic Mode)
|
||||
- 重构智能体对于“工具变更/模型变更”的处理逻辑,无需导入更复杂的中间件
|
||||
- 重构知识库的 Agentic 配置逻辑,与 Tools 解耦
|
||||
- 新增Sqlite Web UI 方便通过Web页面管理数据库中数据[#463](https://github.com/xerrors/Yuxi-Know/pull/463))
|
||||
- 新增Sqlite Web UI 方便通过Web页面管理数据库中数据[#463](https://github.com/xerrors/Yuxi-Know/pull/463)
|
||||
- 将工具与知识库解耦,在 context 中就完成解耦,虽然最终都是在 Agent 中的 get_tools 中获取
|
||||
- 优化chunk逻辑,移除 QA 分割,集成到普通分块中
|
||||
- 重构知识库处理逻辑,分为 上传—解析—入库 三个阶段
|
||||
- 重构 MCP 相关配置,使用数据库来控制 [#469](https://github.com/xerrors/Yuxi-Know/pull/469)
|
||||
|
||||
### 修复
|
||||
|
||||
- 修复知识图谱上传的向量配置错误,并新增模型选择以及 batch size 选择
|
||||
- 修复部分场景下获取工具列表报错 [#470](https://github.com/xerrors/Yuxi-Know/pull/470)
|
||||
|
||||
## v0.4
|
||||
|
||||
|
||||
@ -89,6 +89,13 @@ async def create_database(
|
||||
f"embed_model_name {embed_model_name}"
|
||||
)
|
||||
try:
|
||||
# 先检查名称是否已存在
|
||||
if knowledge_base.database_name_exists(database_name):
|
||||
raise HTTPException(
|
||||
status_code=409,
|
||||
detail=f"知识库名称 '{database_name}' 已存在,请使用其他名称",
|
||||
)
|
||||
|
||||
additional_params = {**(additional_params or {})}
|
||||
additional_params["auto_generate_questions"] = False # 默认不生成问题
|
||||
|
||||
@ -119,9 +126,11 @@ async def create_database(
|
||||
await agent_manager.reload_all()
|
||||
|
||||
return database_info
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
logger.error(f"创建数据库失败 {e}, {traceback.format_exc()}")
|
||||
return {"message": f"创建数据库失败 {e}", "status": "failed"}
|
||||
raise HTTPException(status_code=400, detail=f"创建数据库失败: {e}")
|
||||
|
||||
|
||||
@knowledge.get("/databases/{db_id}")
|
||||
|
||||
@ -233,6 +233,20 @@ class KnowledgeBaseManager:
|
||||
|
||||
return {"databases": all_databases}
|
||||
|
||||
def database_name_exists(self, database_name: str) -> bool:
|
||||
"""检查知识库名称是否已存在
|
||||
|
||||
Args:
|
||||
database_name: 要检查的知识库名称
|
||||
|
||||
Returns:
|
||||
True 如果名称已存在,False 否则
|
||||
"""
|
||||
for db_id, meta in self.global_databases_meta.items():
|
||||
if meta.get("name", "").lower() == database_name.lower():
|
||||
return True
|
||||
return False
|
||||
|
||||
async def create_folder(self, db_id: str, folder_name: str, parent_id: str = None) -> dict:
|
||||
"""Create a folder in the database."""
|
||||
kb_instance = self._get_kb_for_database(db_id)
|
||||
@ -258,6 +272,10 @@ class KnowledgeBaseManager:
|
||||
available_types = list(KnowledgeBaseFactory.get_available_types().keys())
|
||||
raise ValueError(f"Unsupported knowledge base type: {kb_type}. Available types: {available_types}")
|
||||
|
||||
# 检查名称是否已存在
|
||||
if self.database_name_exists(database_name):
|
||||
raise ValueError(f"知识库名称 '{database_name}' 已存在,请使用其他名称")
|
||||
|
||||
kb_instance = self._get_or_create_kb_instance(kb_type)
|
||||
|
||||
db_info = kb_instance.create_database(database_name, description, embed_info, **kwargs)
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
</template>
|
||||
</HeaderComponent>
|
||||
|
||||
<a-modal :open="state.openNewDatabaseModel" title="新建知识库" @ok="handleCreateDatabase" @cancel="cancelCreateDatabase" class="new-database-modal" width="800px">
|
||||
<a-modal :open="state.openNewDatabaseModel" title="新建知识库" :confirm-loading="dbState.creating" @ok="handleCreateDatabase" @cancel="cancelCreateDatabase" class="new-database-modal" width="800px">
|
||||
|
||||
<!-- 知识库类型选择 -->
|
||||
<h3>知识库类型<span style="color: var(--color-error-500)">*</span></h3>
|
||||
@ -172,8 +172,8 @@ import { useRouter, useRoute } from 'vue-router';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useConfigStore } from '@/stores/config';
|
||||
import { useDatabaseStore } from '@/stores/database';
|
||||
import { Database, FileDigit, Waypoints, Building2, DatabaseZap } from 'lucide-vue-next';
|
||||
import { LockOutlined, InfoCircleOutlined, QuestionCircleOutlined, PlusOutlined } from '@ant-design/icons-vue';
|
||||
import { Database, Waypoints, DatabaseZap } from 'lucide-vue-next';
|
||||
import { LockOutlined, InfoCircleOutlined, PlusOutlined } from '@ant-design/icons-vue';
|
||||
import { typeApi } from '@/apis/knowledge_api';
|
||||
import HeaderComponent from '@/components/HeaderComponent.vue';
|
||||
import ModelSelectorComponent from '@/components/ModelSelectorComponent.vue';
|
||||
@ -266,6 +266,7 @@ const resetNewDatabase = () => {
|
||||
|
||||
const cancelCreateDatabase = () => {
|
||||
state.openNewDatabaseModel = false
|
||||
resetNewDatabase()
|
||||
}
|
||||
|
||||
// 知识库类型相关工具方法
|
||||
|
||||
Loading…
Reference in New Issue
Block a user