Skip to content

Commit 02c68a0

Browse files
committed
feat: 添加隐私设置功能,支持创建私有知识库并在界面中显示锁定图标
1 parent 2936f84 commit 02c68a0

File tree

4 files changed

+54
-7
lines changed

4 files changed

+54
-7
lines changed

src/knowledge/base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,12 @@ def create_database(
136136
"""
137137
from src.utils import hashstr
138138

139-
db_id = f"kb_{hashstr(database_name, with_salt=True)}"
139+
from src.utils import hashstr
140+
141+
# 从 kwargs 中获取 is_private 配置
142+
is_private = kwargs.get('is_private', False)
143+
prefix = "kb_private_" if is_private else "kb_"
144+
db_id = f"{prefix}{hashstr(database_name, with_salt=True)}"
140145

141146
# 创建数据库记录
142147
# 确保 Pydantic 模型被转换为字典,以便 JSON 序列化

src/knowledge/implementations/chroma.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
class ChromaKB(KnowledgeBase):
23-
"""基于 ChromaDB 的向量知识库实现"""
23+
"""基于 ChromaDB 的向量库"""
2424

2525
def __init__(self, work_dir: str, **kwargs):
2626
"""

src/knowledge/implementations/milvus.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
class MilvusKB(KnowledgeBase):
24-
"""基于 Milvus 的生产级向量知识库实现"""
24+
"""基于 Milvus 的生产级向量库"""
2525

2626
def __init__(self, work_dir: str, **kwargs):
2727
"""

web/src/views/DataBaseView.vue

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@
7676
placeholder="新建知识库描述"
7777
:auto-size="{ minRows: 5, maxRows: 10 }"
7878
/>
79+
80+
<h3 style="margin-top: 20px;">隐私设置</h3>
81+
<div class="privacy-config">
82+
<a-switch
83+
v-model:checked="newDatabase.is_private"
84+
checked-children="私有"
85+
un-checked-children="公开"
86+
size="default"
87+
/>
88+
<span style="margin-left: 12px;">设置为私有知识库</span>
89+
<a-tooltip title="在部分智能体的设计中,可以根据隐私标志来决定启用什么模型和策略。例如,对于私有知识库,可以选择更严格的数据处理和访问控制策略,以保护敏感信息的安全性和隐私性。">
90+
<InfoCircleOutlined style="margin-left: 8px; color: var(--gray-500); cursor: help;" />
91+
</a-tooltip>
92+
</div>
7993
<template #footer>
8094
<a-button key="back" @click="cancelCreateDatabase">取消</a-button>
8195
<a-button key="submit" type="primary" :loading="state.creating" @click="createDatabase">创建</a-button>
@@ -104,6 +118,12 @@
104118
:key="database.db_id"
105119
class="database dbcard"
106120
@click="navigateToDatabase(database.db_id)">
121+
<!-- 私有知识库锁定图标 -->
122+
<LockOutlined
123+
v-if="database.metadata?.is_private"
124+
class="private-lock-icon"
125+
title="私有知识库"
126+
/>
107127
<div class="top">
108128
<div class="icon">
109129
<component :is="getKbTypeIcon(database.kb_type || 'lightrag')" />
@@ -132,7 +152,7 @@
132152
>
133153
{{ getKbTypeLabel(database.kb_type || 'lightrag') }}
134154
</a-tag>
135-
</div>
155+
</div>
136156

137157
<!-- <button @click="deleteDatabase(database.collection_name)">删除</button> -->
138158
</div>
@@ -146,6 +166,7 @@ import { useRouter, useRoute } from 'vue-router';
146166
import { useConfigStore } from '@/stores/config';
147167
import { message } from 'ant-design-vue'
148168
import { BookPlus, Database, Zap, FileDigit, Waypoints, Building2 } from 'lucide-vue-next';
169+
import { LockOutlined, InfoCircleOutlined } from '@ant-design/icons-vue';
149170
import { databaseApi, typeApi } from '@/apis/knowledge_api';
150171
import HeaderComponent from '@/components/HeaderComponent.vue';
151172
import ModelSelectorComponent from '@/components/ModelSelectorComponent.vue';
@@ -189,6 +210,7 @@ const emptyEmbedInfo = {
189210
description: '',
190211
embed_model_name: configStore.config?.embed_model,
191212
kb_type: 'chroma', // 默认为 Milvus
213+
is_private: false, // 默认为公开知识库
192214
// Vector 知识库特有配置
193215
storage: '', // 存储方式配置
194216
// LightRAG 特有配置
@@ -391,7 +413,9 @@ const createDatabase = () => {
391413
description: newDatabase.description?.trim() || '',
392414
embed_model_name: newDatabase.embed_model_name || configStore.config.embed_model,
393415
kb_type: newDatabase.kb_type,
394-
additional_params: {}
416+
additional_params: {
417+
is_private: newDatabase.is_private || false
418+
}
395419
}
396420
397421
// 添加类型特有的配置
@@ -450,6 +474,12 @@ onMounted(() => {
450474
margin: 12px 0;
451475
}
452476
477+
.privacy-config {
478+
display: flex;
479+
align-items: center;
480+
margin-bottom: 12px;
481+
}
482+
453483
.kb-type-cards {
454484
display: grid;
455485
grid-template-columns: repeat(3, 1fr);
@@ -473,7 +503,6 @@ onMounted(() => {
473503
474504
&:hover {
475505
border-color: var(--main-color);
476-
transform: translateY(-1px);
477506
}
478507
479508
// 为不同知识库类型设置不同的悬停颜色
@@ -577,7 +606,7 @@ onMounted(() => {
577606
color: var(--gray-600);
578607
line-height: 1.5;
579608
margin-bottom: 12px;
580-
min-height: 40px;
609+
// min-height: 40px;
581610
}
582611
583612
.card-features {
@@ -687,6 +716,19 @@ onMounted(() => {
687716
cursor: pointer;
688717
display: flex;
689718
flex-direction: column;
719+
position: relative; // 为绝对定位的锁定图标提供参考
720+
721+
.private-lock-icon {
722+
position: absolute;
723+
top: 24px;
724+
right: 16px;
725+
color: var(--gray-700);
726+
background: var(--gray-100);
727+
font-size: 12px;
728+
border-radius: 6px;
729+
padding: 5px;
730+
z-index: 1;
731+
}
690732
691733
.top {
692734
display: flex;

0 commit comments

Comments
 (0)