feat: 收敛知识库检索调度与评分语义
- 固定 rag.engine 与 Milvus 配置,补齐启动期检索基础设施校验 - 支持调用方配置 retrievalMode,并统一知识库检索入口与结果来源展示 - 修正关键词检索 knowledgeId 过滤、混合检索评分归一化与本地 ES 默认配置
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import type { FormInstance } from 'element-plus';
|
||||
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { InfoFilled } from '@element-plus/icons-vue';
|
||||
import {
|
||||
@@ -80,29 +80,6 @@ watch(
|
||||
|
||||
const embeddingLlmList = ref<any>([]);
|
||||
const rerankerLlmList = ref<any>([]);
|
||||
const vecotrDatabaseList = ref<any>([
|
||||
{ value: 'milvus', label: 'Milvus' },
|
||||
{ value: 'redis', label: 'Redis' },
|
||||
{ value: 'opensearch', label: 'OpenSearch' },
|
||||
{ value: 'elasticsearch', label: 'ElasticSearch' },
|
||||
{ value: 'aliyun', label: $t('documentCollection.alibabaCloud') },
|
||||
{ value: 'qcloud', label: $t('documentCollection.tencentCloud') },
|
||||
]);
|
||||
|
||||
const milvusVectorStoreConfigPlaceholder =
|
||||
'uri=http://127.0.0.1:19530\n' +
|
||||
'databaseName=default\n' +
|
||||
'token=\n' +
|
||||
'username=\n' +
|
||||
'password=\n' +
|
||||
'autoCreateCollection=true';
|
||||
|
||||
const vectorStoreConfigPlaceholder = computed(() => {
|
||||
return entity.value?.vectorStoreType === 'milvus'
|
||||
? milvusVectorStoreConfigPlaceholder
|
||||
: '';
|
||||
});
|
||||
|
||||
const getEmbeddingLlmListData = async () => {
|
||||
try {
|
||||
const url = `/api/v1/documentCollection/modelList?modelType=embeddingModel`;
|
||||
@@ -146,15 +123,6 @@ const rules = ref({
|
||||
{ required: true, message: $t('message.required'), trigger: 'blur' },
|
||||
],
|
||||
title: [{ required: true, message: $t('message.required'), trigger: 'blur' }],
|
||||
vectorStoreType: [
|
||||
{ required: true, message: $t('message.required'), trigger: 'blur' },
|
||||
],
|
||||
vectorStoreCollection: [
|
||||
{ required: true, message: $t('message.required'), trigger: 'blur' },
|
||||
],
|
||||
vectorStoreConfig: [
|
||||
{ required: true, message: $t('message.required'), trigger: 'blur' },
|
||||
],
|
||||
vectorEmbedModelId: [
|
||||
{ required: true, message: $t('message.required'), trigger: 'blur' },
|
||||
],
|
||||
@@ -239,50 +207,6 @@ async function save() {
|
||||
:placeholder="$t('documentCollection.placeholder.description')"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<!-- <ElFormItem
|
||||
prop="vectorStoreEnable"
|
||||
:label="$t('documentCollection.vectorStoreEnable')"
|
||||
>
|
||||
<ElSwitch v-model="entity.vectorStoreEnable" />
|
||||
</ElFormItem>-->
|
||||
<ElFormItem
|
||||
prop="vectorStoreType"
|
||||
:label="$t('documentCollection.vectorStoreType')"
|
||||
>
|
||||
<ElSelect
|
||||
v-model="entity.vectorStoreType"
|
||||
:placeholder="$t('documentCollection.placeholder.vectorStoreType')"
|
||||
>
|
||||
<ElOption
|
||||
v-for="item in vecotrDatabaseList"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value || ''"
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem
|
||||
prop="vectorStoreCollection"
|
||||
:label="$t('documentCollection.vectorStoreCollection')"
|
||||
>
|
||||
<ElInput
|
||||
v-model.trim="entity.vectorStoreCollection"
|
||||
:placeholder="
|
||||
$t('documentCollection.placeholder.vectorStoreCollection')
|
||||
"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem
|
||||
prop="vectorStoreConfig"
|
||||
:label="$t('documentCollection.vectorStoreConfig')"
|
||||
>
|
||||
<ElInput
|
||||
v-model.trim="entity.vectorStoreConfig"
|
||||
:rows="4"
|
||||
type="textarea"
|
||||
:placeholder="vectorStoreConfigPlaceholder"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem prop="vectorEmbedModelId">
|
||||
<template #label>
|
||||
<span style="display: flex; align-items: center">
|
||||
@@ -373,12 +297,6 @@ async function save() {
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem
|
||||
prop="searchEngineEnable"
|
||||
:label="$t('documentCollection.searchEngineEnable')"
|
||||
>
|
||||
<ElSwitch v-model="entity.searchEngineEnable" />
|
||||
</ElFormItem>
|
||||
<ElFormItem style="margin-top: 20px; text-align: right">
|
||||
<ElButton
|
||||
type="primary"
|
||||
|
||||
@@ -60,15 +60,6 @@ onMounted(async () => {
|
||||
const saveForm = ref<FormInstance>();
|
||||
const dialogVisible = ref(false);
|
||||
const isAdd = ref(true);
|
||||
const vecotrDatabaseList = ref<any>([
|
||||
{ value: 'milvus', label: 'Milvus' },
|
||||
{ value: 'redis', label: 'Redis' },
|
||||
{ value: 'opensearch', label: 'OpenSearch' },
|
||||
{ value: 'elasticsearch', label: 'ElasticSearch' },
|
||||
{ value: 'aliyun', label: $t('documentCollection.alibabaCloud') },
|
||||
{ value: 'qcloud', label: $t('documentCollection.tencentCloud') },
|
||||
]);
|
||||
|
||||
const defaultEntity = {
|
||||
collectionType: 'DOCUMENT',
|
||||
alias: '',
|
||||
@@ -125,15 +116,6 @@ const rules = ref({
|
||||
{ required: true, message: $t('message.required'), trigger: 'blur' },
|
||||
],
|
||||
title: [{ required: true, message: $t('message.required'), trigger: 'blur' }],
|
||||
vectorStoreType: [
|
||||
{ required: true, message: $t('message.required'), trigger: 'blur' },
|
||||
],
|
||||
vectorStoreCollection: [
|
||||
{ required: true, message: $t('message.required'), trigger: 'blur' },
|
||||
],
|
||||
vectorStoreConfig: [
|
||||
{ required: true, message: $t('message.required'), trigger: 'blur' },
|
||||
],
|
||||
vectorEmbedModelId: [
|
||||
{ required: true, message: $t('message.required'), trigger: 'blur' },
|
||||
],
|
||||
@@ -307,49 +289,6 @@ defineExpose({
|
||||
:placeholder="$t('documentCollection.placeholder.description')"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<!-- <ElFormItem
|
||||
prop="vectorStoreEnable"
|
||||
:label="$t('documentCollection.vectorStoreEnable')"
|
||||
>
|
||||
<ElSwitch v-model="entity.vectorStoreEnable" />
|
||||
</ElFormItem>-->
|
||||
<ElFormItem
|
||||
prop="vectorStoreType"
|
||||
:label="$t('documentCollection.vectorStoreType')"
|
||||
>
|
||||
<ElSelect
|
||||
v-model="entity.vectorStoreType"
|
||||
:placeholder="$t('documentCollection.placeholder.vectorStoreType')"
|
||||
>
|
||||
<ElOption
|
||||
v-for="item in vecotrDatabaseList"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value || ''"
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem
|
||||
prop="vectorStoreCollection"
|
||||
:label="$t('documentCollection.vectorStoreCollection')"
|
||||
>
|
||||
<ElInput
|
||||
v-model.trim="entity.vectorStoreCollection"
|
||||
:placeholder="
|
||||
$t('documentCollection.placeholder.vectorStoreCollection')
|
||||
"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem
|
||||
prop="vectorStoreConfig"
|
||||
:label="$t('documentCollection.vectorStoreConfig')"
|
||||
>
|
||||
<ElInput
|
||||
v-model.trim="entity.vectorStoreConfig"
|
||||
:rows="4"
|
||||
type="textarea"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem prop="vectorEmbedModelId">
|
||||
<template #label>
|
||||
<span style="display: flex; align-items: center">
|
||||
@@ -440,12 +379,6 @@ defineExpose({
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem
|
||||
prop="searchEngineEnable"
|
||||
:label="$t('documentCollection.searchEngineEnable')"
|
||||
>
|
||||
<ElSwitch v-model="entity.searchEngineEnable" />
|
||||
</ElFormItem>
|
||||
</ElForm>
|
||||
</EasyFlowFormModal>
|
||||
</template>
|
||||
|
||||
@@ -3,20 +3,40 @@ import { ref } from 'vue';
|
||||
|
||||
import { $t } from '@easyflow/locales';
|
||||
|
||||
import { ElButton, ElInput, ElMessage } from 'element-plus';
|
||||
import { ElButton, ElInput, ElMessage, ElOption, ElSelect } from 'element-plus';
|
||||
|
||||
import { api } from '#/api/request';
|
||||
import PreviewSearchKnowledge from '#/views/ai/documentCollection/PreviewSearchKnowledge.vue';
|
||||
|
||||
type RetrievalMode = 'HYBRID' | 'KEYWORD' | 'VECTOR';
|
||||
|
||||
interface SearchResultItem {
|
||||
sorting: number;
|
||||
content: string;
|
||||
score?: number;
|
||||
hitSource?: 'BOTH' | 'KEYWORD' | 'VECTOR';
|
||||
vectorScore?: number;
|
||||
keywordScore?: number;
|
||||
}
|
||||
|
||||
const props = defineProps({
|
||||
knowledgeId: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
});
|
||||
const searchDataList = ref([]);
|
||||
|
||||
const searchDataList = ref<SearchResultItem[]>([]);
|
||||
const keyword = ref('');
|
||||
const retrievalMode = ref<RetrievalMode>('HYBRID');
|
||||
const previewSearchKnowledgeRef = ref();
|
||||
|
||||
const retrievalModeOptions = [
|
||||
{ label: $t('bot.retrievalModes.hybrid'), value: 'HYBRID' },
|
||||
{ label: $t('bot.retrievalModes.vector'), value: 'VECTOR' },
|
||||
{ label: $t('bot.retrievalModes.keyword'), value: 'KEYWORD' },
|
||||
];
|
||||
|
||||
const handleSearch = () => {
|
||||
if (!keyword.value) {
|
||||
ElMessage.error($t('message.pleaseInputContent'));
|
||||
@@ -24,12 +44,22 @@ const handleSearch = () => {
|
||||
}
|
||||
previewSearchKnowledgeRef.value.loadingContent(true);
|
||||
api
|
||||
.get(
|
||||
`/api/v1/documentCollection/search?knowledgeId=${props.knowledgeId}&keyword=${keyword.value}`,
|
||||
)
|
||||
.get('/api/v1/documentCollection/search', {
|
||||
params: {
|
||||
knowledgeId: props.knowledgeId,
|
||||
keyword: keyword.value,
|
||||
retrievalMode: retrievalMode.value,
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
previewSearchKnowledgeRef.value.loadingContent(false);
|
||||
searchDataList.value = res.data;
|
||||
})
|
||||
.catch(() => {
|
||||
ElMessage.error($t('documentCollection.searchFailed'));
|
||||
searchDataList.value = [];
|
||||
})
|
||||
.finally(() => {
|
||||
previewSearchKnowledgeRef.value.loadingContent(false);
|
||||
});
|
||||
};
|
||||
</script>
|
||||
@@ -40,7 +70,16 @@ const handleSearch = () => {
|
||||
<ElInput
|
||||
v-model="keyword"
|
||||
:placeholder="$t('common.searchPlaceholder')"
|
||||
@keyup.enter="handleSearch"
|
||||
/>
|
||||
<ElSelect v-model="retrievalMode" class="retrieval-select">
|
||||
<ElOption
|
||||
v-for="item in retrievalModeOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</ElSelect>
|
||||
<ElButton type="primary" @click="handleSearch">
|
||||
{{ $t('button.query') }}
|
||||
</ElButton>
|
||||
@@ -48,6 +87,7 @@ const handleSearch = () => {
|
||||
<div class="search-result">
|
||||
<PreviewSearchKnowledge
|
||||
:data="searchDataList"
|
||||
:retrieval-mode="retrievalMode"
|
||||
ref="previewSearchKnowledgeRef"
|
||||
/>
|
||||
</div>
|
||||
@@ -68,6 +108,12 @@ const handleSearch = () => {
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.retrieval-select {
|
||||
width: 180px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.search-result {
|
||||
padding-top: 20px;
|
||||
flex: 1;
|
||||
|
||||
@@ -10,9 +10,6 @@ import {
|
||||
ElFormItem,
|
||||
ElInputNumber,
|
||||
ElMessage,
|
||||
ElOption,
|
||||
ElSelect,
|
||||
ElSwitch,
|
||||
ElTooltip,
|
||||
} from 'element-plus';
|
||||
|
||||
@@ -32,7 +29,6 @@ const props = defineProps({
|
||||
onMounted(() => {
|
||||
getDocumentCollectionConfig();
|
||||
});
|
||||
const searchEngineEnable = ref(false);
|
||||
const baseOptions = ref<Record<string, any>>({});
|
||||
const getDocumentCollectionConfig = () => {
|
||||
api
|
||||
@@ -46,16 +42,13 @@ const getDocumentCollectionConfig = () => {
|
||||
: 5;
|
||||
searchConfig.simThreshold = options.simThreshold
|
||||
? Number(options.simThreshold)
|
||||
: 0.5;
|
||||
searchConfig.searchEngineType = options.searchEngineType || 'lucene';
|
||||
searchEngineEnable.value = !!data.searchEngineEnable;
|
||||
: 0.6;
|
||||
});
|
||||
};
|
||||
|
||||
const searchConfig = reactive({
|
||||
docRecallMaxNum: 5,
|
||||
simThreshold: 0.5,
|
||||
searchEngineType: 'lucene',
|
||||
simThreshold: 0.6,
|
||||
});
|
||||
|
||||
const submitConfig = () => {
|
||||
@@ -69,9 +62,7 @@ const submitConfig = () => {
|
||||
...baseOptions.value,
|
||||
docRecallMaxNum: searchConfig.docRecallMaxNum,
|
||||
simThreshold: searchConfig.simThreshold,
|
||||
searchEngineType: searchConfig.searchEngineType,
|
||||
},
|
||||
searchEngineEnable: searchEngineEnable.value,
|
||||
};
|
||||
|
||||
api
|
||||
@@ -85,26 +76,6 @@ const submitConfig = () => {
|
||||
console.error('保存配置失败:', error);
|
||||
});
|
||||
};
|
||||
|
||||
const searchEngineOptions = [
|
||||
{
|
||||
label: 'Lucene',
|
||||
value: 'lucene',
|
||||
},
|
||||
{
|
||||
label: 'ElasticSearch',
|
||||
value: 'elasticSearch',
|
||||
},
|
||||
];
|
||||
const handleSearchEngineEnableChange = () => {
|
||||
if (!props.manageable) {
|
||||
return;
|
||||
}
|
||||
api.post('/api/v1/documentCollection/update', {
|
||||
id: props.documentCollectionId,
|
||||
searchEngineEnable: searchEngineEnable.value,
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -176,71 +147,12 @@ const handleSearchEngineEnableChange = () => {
|
||||
/>
|
||||
</div>
|
||||
</ElFormItem>
|
||||
|
||||
<!-- 搜索引擎启用开关 -->
|
||||
<ElFormItem class="form-item">
|
||||
<div class="form-item-label">
|
||||
<span>{{
|
||||
$t('documentCollectionSearch.searchEngineEnable.label')
|
||||
}}</span>
|
||||
<ElTooltip
|
||||
:content="$t('documentCollectionSearch.searchEngineEnable.tooltip')"
|
||||
placement="top"
|
||||
effect="dark"
|
||||
class="label-tooltip"
|
||||
>
|
||||
<InfoFilled class="info-icon" />
|
||||
</ElTooltip>
|
||||
</div>
|
||||
<div class="form-item-content">
|
||||
<ElSwitch
|
||||
v-model="searchEngineEnable"
|
||||
@change="handleSearchEngineEnableChange"
|
||||
:active-text="$t('documentCollectionSearch.switch.on')"
|
||||
:inactive-text="$t('documentCollectionSearch.switch.off')"
|
||||
class="form-control switch-control"
|
||||
/>
|
||||
</div>
|
||||
</ElFormItem>
|
||||
|
||||
<!-- 通过 searchEngineEnable 控制显示/隐藏 -->
|
||||
<ElFormItem
|
||||
v-if="searchEngineEnable"
|
||||
prop="searchEngineType"
|
||||
class="form-item"
|
||||
>
|
||||
<div class="form-item-label">
|
||||
<span>{{
|
||||
$t('documentCollectionSearch.searchEngineType.label')
|
||||
}}</span>
|
||||
<ElTooltip
|
||||
:content="$t('documentCollectionSearch.searchEngineType.tooltip')"
|
||||
placement="top"
|
||||
effect="dark"
|
||||
class="label-tooltip"
|
||||
>
|
||||
<InfoFilled class="info-icon" />
|
||||
</ElTooltip>
|
||||
</div>
|
||||
<div class="form-item-content">
|
||||
<ElSelect
|
||||
v-model="searchConfig.searchEngineType"
|
||||
:placeholder="
|
||||
$t('documentCollectionSearch.searchEngineType.placeholder')
|
||||
"
|
||||
class="form-control"
|
||||
>
|
||||
<ElOption
|
||||
v-for="option in searchEngineOptions"
|
||||
:key="option.value"
|
||||
:label="option.label"
|
||||
:value="option.value"
|
||||
/>
|
||||
</ElSelect>
|
||||
</div>
|
||||
</ElFormItem>
|
||||
</ElForm>
|
||||
|
||||
<div class="config-hint">
|
||||
{{ $t('documentCollectionSearch.engineHint') }}
|
||||
</div>
|
||||
|
||||
<div class="config-footer">
|
||||
<ElButton
|
||||
type="primary"
|
||||
@@ -352,6 +264,13 @@ const handleSearchEngineEnableChange = () => {
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.config-hint {
|
||||
margin: 12px 0 4px;
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.config-footer {
|
||||
position: sticky;
|
||||
bottom: 0;
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { $t } from '@easyflow/locales';
|
||||
|
||||
import { Document } from '@element-plus/icons-vue';
|
||||
import { ElButton, ElIcon } from 'element-plus';
|
||||
// 定义类型接口(与 React 版本一致)
|
||||
import { ElButton, ElIcon, ElTag } from 'element-plus';
|
||||
|
||||
type RetrievalMode = 'HYBRID' | 'KEYWORD' | 'VECTOR';
|
||||
type HitSource = 'BOTH' | 'KEYWORD' | 'VECTOR';
|
||||
|
||||
interface PreviewItem {
|
||||
sorting: string;
|
||||
sorting: number | string;
|
||||
content: string;
|
||||
score: string;
|
||||
score?: number | string;
|
||||
hitSource?: HitSource;
|
||||
}
|
||||
|
||||
const props = defineProps({
|
||||
hideScore: {
|
||||
type: Boolean,
|
||||
@@ -46,8 +53,37 @@ const props = defineProps({
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
retrievalMode: {
|
||||
type: String as () => RetrievalMode,
|
||||
default: 'HYBRID',
|
||||
},
|
||||
});
|
||||
|
||||
const loadingStatus = ref(false);
|
||||
|
||||
const resolveHitSourceLabel = (hitSource?: HitSource) => {
|
||||
if (hitSource === 'VECTOR') {
|
||||
return $t('documentCollection.hitSources.vector');
|
||||
}
|
||||
if (hitSource === 'KEYWORD') {
|
||||
return $t('documentCollection.hitSources.keyword');
|
||||
}
|
||||
if (hitSource === 'BOTH') {
|
||||
return $t('documentCollection.hitSources.both');
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
const resolveHitSourceType = (hitSource?: HitSource) => {
|
||||
if (hitSource === 'VECTOR') {
|
||||
return 'success';
|
||||
}
|
||||
if (hitSource === 'KEYWORD') {
|
||||
return 'warning';
|
||||
}
|
||||
return 'info';
|
||||
};
|
||||
|
||||
defineExpose({
|
||||
loadingContent: (state: boolean) => {
|
||||
loadingStatus.value = state;
|
||||
@@ -89,10 +125,22 @@ defineExpose({
|
||||
{{ item.sorting ?? index + 1 }}
|
||||
</div>
|
||||
<div class="el-list-item-meta">
|
||||
<div v-if="!hideScore">
|
||||
<div v-if="!hideScore" class="score-text">
|
||||
{{ $t('documentCollection.similarityScore') }}: {{ item.score }}
|
||||
</div>
|
||||
<div class="content-desc">{{ item.content }}</div>
|
||||
<div
|
||||
v-if="retrievalMode === 'HYBRID' && item.hitSource"
|
||||
class="hit-source-row"
|
||||
>
|
||||
<ElTag
|
||||
size="small"
|
||||
effect="plain"
|
||||
:type="resolveHitSourceType(item.hitSource)"
|
||||
>
|
||||
{{ resolveHitSourceLabel(item.hitSource) }}
|
||||
</ElTag>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -203,10 +251,20 @@ defineExpose({
|
||||
}
|
||||
}
|
||||
|
||||
.score-text {
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.hit-source-row {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.el-list-item {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
align-items: flex-start;
|
||||
padding: 18px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user