feat: 支持知识库的分片、重叠设置等
This commit is contained in:
@@ -5,8 +5,8 @@
|
||||
<div v-if="!installed" class="d-flex align-center justify-center flex-column"
|
||||
style="flex-grow: 1; width: 100%; height: 100%;">
|
||||
<h2>还没有安装知识库插件</h2>
|
||||
<v-btn style="margin-top: 16px;" variant="tonal" color="primary"
|
||||
@click="installPlugin" :loading="installing">
|
||||
<v-btn style="margin-top: 16px;" variant="tonal" color="primary" @click="installPlugin"
|
||||
:loading="installing">
|
||||
立即安装
|
||||
</v-btn>
|
||||
</div>
|
||||
@@ -49,9 +49,9 @@
|
||||
<div style="padding: 16px; text-align: center;">
|
||||
<small style="color: #a3a3a3">Tips: 在聊天页面通过 /kb 指令了解如何使用!</small>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<!-- 创建知识库对话框 -->
|
||||
@@ -73,9 +73,11 @@
|
||||
<v-textarea v-model="newKB.description" label="描述" variant="outlined" placeholder="知识库的简短描述..."
|
||||
rows="3"></v-textarea>
|
||||
|
||||
<v-select v-model="newKB.embedding_provider_id" :items="embeddingProviderConfigs" :item-props="embeddingModelProps" label="Embedding(嵌入)模型"
|
||||
variant="outlined" class="mt-2">
|
||||
<v-select v-model="newKB.embedding_provider_id" :items="embeddingProviderConfigs"
|
||||
:item-props="embeddingModelProps" label="Embedding(嵌入)模型" variant="outlined" class="mt-2">
|
||||
</v-select>
|
||||
|
||||
<small>Tips: 一旦选择了一个知识库的嵌入模型,请不要再修改该提供商的模型或者向量维度信息,否则将严重影响该知识库的召回率甚至报错。</small>
|
||||
</v-form>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
@@ -122,6 +124,18 @@
|
||||
</v-btn>
|
||||
</v-card-title>
|
||||
|
||||
<div v-if="currentKB._embedding_provider_config" class="px-6 py-2">
|
||||
<v-chip class="mr-2" color="primary" variant="tonal" size="small" rounded="sm">
|
||||
<v-icon start size="small">mdi-database</v-icon>
|
||||
嵌入模型: {{ currentKB._embedding_provider_config.embedding_model }}
|
||||
</v-chip>
|
||||
<v-chip color="secondary" variant="tonal" size="small" rounded="sm">
|
||||
<v-icon start size="small">mdi-vector-point</v-icon>
|
||||
向量维度: {{ currentKB._embedding_provider_config.embedding_dimensions }}
|
||||
</v-chip>
|
||||
<small style="margin-left: 8px;">💡 使用方式: 在聊天页中输入 “/kb use {{ currentKB.collection_name }}”</small>
|
||||
</div>
|
||||
|
||||
<v-card-text>
|
||||
<v-tabs v-model="activeTab">
|
||||
<v-tab value="upload">上传文件</v-tab>
|
||||
@@ -144,6 +158,54 @@
|
||||
<p class="mt-2">拖放文件到这里或点击上传</p>
|
||||
</div>
|
||||
|
||||
<!-- 优化后的分片长度和重叠长度设置 -->
|
||||
<v-card class="mt-4 chunk-settings-card" variant="outlined" color="grey-lighten-4">
|
||||
<v-card-title class="pa-4 pb-0 d-flex align-center">
|
||||
<v-icon color="primary" class="mr-2">mdi-puzzle-outline</v-icon>
|
||||
<span class="text-subtitle-1 font-weight-bold">分片设置</span>
|
||||
<v-tooltip location="top">
|
||||
<template v-slot:activator="{ props }">
|
||||
<v-icon v-bind="props" class="ml-2" size="small" color="grey">
|
||||
mdi-information-outline
|
||||
</v-icon>
|
||||
</template>
|
||||
<span>
|
||||
分片长度决定每块文本的大小,重叠长度决定相邻文本块之间的重叠程度。<br>
|
||||
较小的分片更精确但会增加数量,适当的重叠可提高检索准确性。
|
||||
</span>
|
||||
</v-tooltip>
|
||||
</v-card-title>
|
||||
<v-card-text class="pa-4 pt-2">
|
||||
<div class="d-flex flex-wrap" style="gap: 8px">
|
||||
<v-text-field
|
||||
v-model="chunkSize"
|
||||
label="分片长度"
|
||||
type="number"
|
||||
hint="控制每个文本块大小,留空使用默认值"
|
||||
persistent-hint
|
||||
variant="outlined"
|
||||
density="comfortable"
|
||||
class="flex-grow-1 chunk-field"
|
||||
prepend-inner-icon="mdi-text-box-outline"
|
||||
min="50"
|
||||
></v-text-field>
|
||||
|
||||
<v-text-field
|
||||
v-model="overlap"
|
||||
label="重叠长度"
|
||||
type="number"
|
||||
hint="控制相邻文本块重叠度,留空使用默认值"
|
||||
persistent-hint
|
||||
variant="outlined"
|
||||
density="comfortable"
|
||||
class="flex-grow-1 chunk-field"
|
||||
prepend-inner-icon="mdi-vector-intersection"
|
||||
min="0"
|
||||
></v-text-field>
|
||||
</div>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
|
||||
<div class="selected-files mt-4" v-if="selectedFile">
|
||||
<div type="info" variant="tonal" class="d-flex align-center">
|
||||
<div>
|
||||
@@ -301,6 +363,8 @@ export default {
|
||||
},
|
||||
activeTab: 'upload',
|
||||
selectedFile: null,
|
||||
chunkSize: null,
|
||||
overlap: null,
|
||||
uploading: false,
|
||||
searchQuery: '',
|
||||
searchResults: [],
|
||||
@@ -323,7 +387,7 @@ export default {
|
||||
embeddingModelProps(providerConfig) {
|
||||
return {
|
||||
title: providerConfig.embedding_model,
|
||||
subtitle: `提供商 ID: ${providerConfig.id}`,
|
||||
subtitle: `提供商 ID: ${providerConfig.id} | 嵌入模型维度: ${providerConfig.embedding_dimensions}`,
|
||||
}
|
||||
},
|
||||
checkPlugin() {
|
||||
@@ -439,6 +503,9 @@ export default {
|
||||
this.searchQuery = '';
|
||||
this.searchResults = [];
|
||||
this.searchPerformed = false;
|
||||
// 重置分片长度和重叠长度参数
|
||||
this.chunkSize = null;
|
||||
this.overlap = null;
|
||||
},
|
||||
|
||||
triggerFileInput() {
|
||||
@@ -492,6 +559,15 @@ export default {
|
||||
const formData = new FormData();
|
||||
formData.append('file', this.selectedFile);
|
||||
formData.append('collection_name', this.currentKB.collection_name);
|
||||
|
||||
// 添加可选的分片长度和重叠长度参数
|
||||
if (this.chunkSize && this.chunkSize > 0) {
|
||||
formData.append('chunk_size', this.chunkSize);
|
||||
}
|
||||
|
||||
if (this.overlap && this.overlap >= 0) {
|
||||
formData.append('chunk_overlap', this.overlap);
|
||||
}
|
||||
|
||||
axios.post('/api/plug/alkaid/kb/collection/add_file', formData, {
|
||||
headers: {
|
||||
@@ -500,7 +576,7 @@ export default {
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data.status === 'ok') {
|
||||
this.showSnackbar('文件上传成功');
|
||||
this.showSnackbar('操作成功: ' + response.data.message);
|
||||
this.selectedFile = null;
|
||||
|
||||
// 刷新知识库列表,获取更新的数量
|
||||
@@ -792,4 +868,28 @@ export default {
|
||||
.kb-card:hover .kb-actions {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.chunk-settings-card {
|
||||
border: 1px solid rgba(92, 107, 192, 0.2) !important;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.chunk-settings-card:hover {
|
||||
border-color: rgba(92, 107, 192, 0.4) !important;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07) !important;
|
||||
}
|
||||
|
||||
.chunk-field :deep(.v-field__input) {
|
||||
padding-top: 8px;
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
|
||||
.chunk-field :deep(.v-field__prepend-inner) {
|
||||
padding-right: 8px;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.chunk-field:focus-within :deep(.v-field__prepend-inner) {
|
||||
opacity: 1;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user