增加rag服务

This commit is contained in:
2026-09-09 14:21:07 +08:00
parent bdc4fba239
commit 7500d3ab56
31 changed files with 848 additions and 230 deletions
+79 -2
View File
@@ -53,6 +53,14 @@
<el-icon :size="16"><CloseBold /></el-icon>
无效
</el-button>
<el-button type="primary" :disabled="ids.length === 0" @click="handleVectorOp(1)">
<el-icon :size="16"><Refresh /></el-icon>
加入问题库
</el-button>
<el-button type="warning" :disabled="ids.length === 0" @click="handleVectorOp(0)">
<el-icon :size="16"><Delete /></el-icon>
移出问题库
</el-button>
</template>
<el-table v-loading="loading" :data="qnaList" @selection-change="handleSelectionChange" stripe border>
@@ -88,6 +96,20 @@
<el-text :type="stateType(scope.row.state)">{{ stateText(scope.row.state) }}</el-text>
</template>
</el-table-column>
<el-table-column label="置信度" align="center" prop="confidence" width="90">
<template #default="scope">
<el-tag :type="confidenceType(scope.row.confidence)">
{{ confidenceText(scope.row.confidence) }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="已入库" align="center" prop="embedded" width="80">
<template #default="scope">
<el-tag :type="scope.row.embedded === 1 ? 'success' : 'info'">
{{ scope.row.embedded === 1 ? "是" : "否" }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="提交时间" align="center" prop="editTime" width="180">
<template #default="scope">
{{ formatTimeToMinutes(scope.row.editTime) }}
@@ -98,7 +120,7 @@
{{ formatTimeToMinutes(scope.row.answerTime) }}
</template>
</el-table-column>
<el-table-column label="操作" align="center" fixed="right" width="100">
<el-table-column label="操作" align="center" fixed="right" width="120">
<template #default="scope">
<el-button type="success" link size="small" @click="handleOpenDialog(scope.row)">
<el-icon :size="14"><EditPen /></el-icon>
@@ -199,6 +221,9 @@ defineOptions({
import HelperAPI, { FullQnA, QnAPageQuery, UpdateQnA } from "@/api/helper";
import { ColoredType, innerTypes } from "@/enums/SoftwareEnum";
import { formatTimeToMinutes } from "@/utils/format";
import { usePageSize } from "@/composables/usePageSize";
import { ElMessageBox } from "element-plus";
import { EditPen, Plus, SemiSelect, CloseBold, Refresh, Delete } from "@element-plus/icons-vue";
const queryFormRef = ref();
const qnaFormRef = ref();
@@ -211,6 +236,7 @@ const queryParams = reactive<QnAPageQuery>({
pageNum: 1,
pageSize: 10,
});
usePageSize(queryParams, "website:question:pageSize");
const optionHide = "display: none";
function optionShow(value: number) {
if (value == 5 || value == 7) return optionHide;
@@ -229,7 +255,7 @@ watch(queryTypes, (types) => {
// console.log(queryParams.typeIds);
});
const qnaList = ref<FullQnA[]>();
const qnaList = ref<FullQnA[]>([]);
// 弹窗
const dialog = reactive({
@@ -314,6 +340,18 @@ function stateType(state: number) {
}
}
function confidenceText(confidence: number | undefined | null) {
if (confidence == null) return "";
return (confidence / 100).toFixed(2);
}
function confidenceType(confidence: number | undefined | null) {
if (confidence == null) return "info";
if (confidence >= 9000) return "success";
if (confidence >= 6000) return "warning";
return "danger";
}
function userText(nickname: string | undefined, userName: string | undefined) {
if (nickname) return nickname;
if (userName) return userName;
@@ -471,6 +509,45 @@ function handleState(state: number) {
);
}
/** 向量库操作:入库/移出 */
async function handleVectorOp(embedded: number) {
if (ids.value.length === 0) {
ElMessage.warning("请勾选问题");
return;
}
const action = embedded === 1 ? "加入" : "移出";
const actionType = embedded === 1 ? "info" : "warning";
// 预过滤:仅处理当前 embedded 状态相反的记录
const targetIds = qnaList.value
.filter((item) => ids.value.includes(item.helpId!) && item.embedded !== embedded)
.map((item) => item.helpId);
if (targetIds.length === 0) {
ElMessage.info(embedded === 1 ? "选中问题均已在库中" : "选中问题均未入库");
return;
}
try {
await ElMessageBox.confirm(`确定将选中的 ${targetIds.length} 个问题${action}问题库吗?`, `${action}问题库`, {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: actionType,
});
loading.value = true;
const res = await HelperAPI.updateVector(targetIds.join(","), embedded);
const successCount = res?.successIds?.length || 0;
ElMessage.success(`${action}成功 ${successCount} 条`);
handleQuery(); // 刷新列表
} catch (error) {
ElMessage.error(`${action}失败`);
} finally {
loading.value = false;
}
}
onMounted(() => {
handleQuery();
});