feat(common problems fuzzy query): 增加常用问题模糊查询兜底
This commit is contained in:
1 parent
b69c725992
commit
5a269f940d
18 files changed
+411
-58
No files matched your search
@@ -3,10 +3,11 @@
|
||||
* 用途:常用问题 / FAQ 缓存的创建与编辑对话框。字段多,宽 680px,两列短字段。
|
||||
* 依赖:element-plus 对话框和表单、QuestionFormState、AdminAgentOption。
|
||||
* 逻辑:QuestionsPage 打开本组件。提交时 emit save 或 review,由 useQuestionsAdmin 调接口。样式跟页面已引入的 Element 皮肤走。
|
||||
* is_enabled 仅控制工作台首页入口;cache_enabled 单独控制聊天是否跳过 Dify。
|
||||
* is_enabled 仅控制工作台首页入口;cache_enabled 单独控制聊天是否跳过 Dify;
|
||||
* fuzzy_enabled 在精确未命中时按阈值兜底直答,以 cache_enabled 为前提(关闭缓存时联动取消勾选)。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { computed, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import {
|
||||
ElAlert,
|
||||
@@ -43,6 +44,19 @@ const { t } = useI18n();
|
||||
/** 启用 FAQ 缓存时标准答案为必填。 */
|
||||
const answerRequired = computed(() => props.form.cache_enabled);
|
||||
|
||||
/** 模糊匹配只在 FAQ 缓存开启时有意义,控制阈值输入的显隐与开关可用态。 */
|
||||
const fuzzyAvailable = computed(() => props.form.cache_enabled && props.form.fuzzy_enabled);
|
||||
|
||||
/**
|
||||
* 关闭 FAQ 缓存时联动取消模糊匹配,避免提交出「缓存关、模糊开」的无效组合。
|
||||
*/
|
||||
watch(
|
||||
() => props.form.cache_enabled,
|
||||
(enabled) => {
|
||||
if (!enabled) props.form.fuzzy_enabled = false;
|
||||
},
|
||||
);
|
||||
|
||||
/** 是否处于 KB 更新后的待复审状态。 */
|
||||
const isStale = computed(() => Boolean(props.form.stale_at));
|
||||
|
||||
@@ -143,6 +157,23 @@ function submitForm(): void {
|
||||
<ElFormItem class="question-form-span">
|
||||
<ElCheckbox v-model="form.cache_enabled">{{ t('admin.question.fields.cacheEnabled') }}</ElCheckbox>
|
||||
</ElFormItem>
|
||||
<ElFormItem class="question-form-span">
|
||||
<ElCheckbox v-model="form.fuzzy_enabled" :disabled="!form.cache_enabled">
|
||||
<span class="question-check-label">{{ t('admin.question.fields.fuzzyEnabled') }}</span>
|
||||
<span class="hx-element-hint question-check-hint">{{ t('admin.question.fields.fuzzyEnabledHelp') }}</span>
|
||||
</ElCheckbox>
|
||||
</ElFormItem>
|
||||
<ElFormItem v-if="fuzzyAvailable" class="question-form-span" :label="t('admin.question.fields.fuzzyThreshold')">
|
||||
<ElInputNumber
|
||||
v-model="form.fuzzy_threshold"
|
||||
:min="0.5"
|
||||
:max="1"
|
||||
:step="0.05"
|
||||
:precision="2"
|
||||
controls-position="right"
|
||||
/>
|
||||
<p class="hx-element-hint">{{ t('admin.question.fields.fuzzyThresholdHelp') }}</p>
|
||||
</ElFormItem>
|
||||
|
||||
<p class="question-section-label question-form-span">{{ t('admin.question.sections.matching') }}</p>
|
||||
<ElFormItem class="question-form-span" :label="t('admin.question.fields.content')" required>
|
||||
|
||||
@@ -108,6 +108,8 @@ export function useQuestionsAdmin() {
|
||||
aliasesText: aliasesToText(q.aliases),
|
||||
cache_enabled: q.cache_enabled,
|
||||
is_enabled: q.is_enabled,
|
||||
fuzzy_enabled: Boolean(q.fuzzy_enabled),
|
||||
fuzzy_threshold: typeof q.fuzzy_threshold === 'number' ? q.fuzzy_threshold : 0.8,
|
||||
agent_id: q.agent_id,
|
||||
sort_order: q.sort_order,
|
||||
expires_at: q.expires_at ? q.expires_at.slice(0, 16) : '',
|
||||
|
||||
@@ -11,6 +11,8 @@ export interface AdminQuickQuestionRow {
|
||||
aliases?: string[];
|
||||
cache_enabled: boolean;
|
||||
is_enabled: boolean;
|
||||
fuzzy_enabled?: boolean;
|
||||
fuzzy_threshold?: number | null;
|
||||
hit_count: number;
|
||||
agent_id: number;
|
||||
agent_name?: string;
|
||||
@@ -32,6 +34,8 @@ export interface QuestionFormState {
|
||||
aliasesText: string;
|
||||
cache_enabled: boolean;
|
||||
is_enabled: boolean;
|
||||
fuzzy_enabled: boolean;
|
||||
fuzzy_threshold: number;
|
||||
agent_id?: number;
|
||||
sort_order: number;
|
||||
expires_at: string;
|
||||
@@ -47,6 +51,8 @@ export const createEmptyQuestionForm = (): QuestionFormState => ({
|
||||
aliasesText: '',
|
||||
cache_enabled: false,
|
||||
is_enabled: true,
|
||||
fuzzy_enabled: false,
|
||||
fuzzy_threshold: 0.8,
|
||||
agent_id: undefined,
|
||||
sort_order: 0,
|
||||
expires_at: '',
|
||||
@@ -70,7 +76,7 @@ export const textToAliases = (text: string): string[] => {
|
||||
return result;
|
||||
};
|
||||
|
||||
/** 构建提交 API 的 payload。 */
|
||||
/** 构建提交 API 的 payload。模糊匹配以 FAQ 缓存为前提,缓存关闭时一并提交关闭。 */
|
||||
export const buildQuestionPayload = (
|
||||
form: QuestionFormState,
|
||||
options?: { clearStale?: boolean },
|
||||
@@ -81,6 +87,8 @@ export const buildQuestionPayload = (
|
||||
aliases: textToAliases(form.aliasesText),
|
||||
cache_enabled: form.cache_enabled,
|
||||
is_enabled: form.is_enabled,
|
||||
fuzzy_enabled: form.cache_enabled && form.fuzzy_enabled,
|
||||
fuzzy_threshold: form.fuzzy_threshold,
|
||||
agent_id: form.agent_id,
|
||||
sort_order: form.sort_order,
|
||||
expires_at: form.expires_at || null,
|
||||
|
||||
@@ -1587,6 +1587,10 @@
|
||||
"isEnabled": "Show on workspace",
|
||||
"isEnabledHelp": "Only controls the homepage shortcut. It does not affect whether chat returns the cached answer.",
|
||||
"cacheHelp": "When enabled, matched queries return the preset answer below without calling Dify. Independent of the homepage shortcut.",
|
||||
"fuzzyEnabled": "Enable fuzzy matching",
|
||||
"fuzzyEnabledHelp": "When no exact match is found, answer directly by similarity (tolerates added words or synonym swaps).",
|
||||
"fuzzyThreshold": "Fuzzy match threshold",
|
||||
"fuzzyThresholdHelp": "0.50–1.00, default 0.80. Answers only when similarity reaches this value; lower is more permissive, higher is more conservative.",
|
||||
"expiresAt": "Expires At",
|
||||
"expiresAtHelp": "Optional. After expiry the entry will not match. Leave empty for no expiry."
|
||||
},
|
||||
|
||||
@@ -1587,6 +1587,10 @@
|
||||
"isEnabled": "แสดงในหน้า workspace",
|
||||
"isEnabledHelp": "ควบคุมเฉพาะทางลัดบนหน้าแรก ไม่มีผลว่าแชทจะตอบจาก cache หรือไม่",
|
||||
"cacheHelp": "เมื่อเปิดใช้ คำถามที่จับคู่ได้จะส่งคำตอบด้านล่างโดยไม่เรียก Dify ไม่ขึ้นกับว่าจะแสดงบนหน้าแรกหรือไม่",
|
||||
"fuzzyEnabled": "เปิดใช้การจับคู่แบบคลุมเครือ",
|
||||
"fuzzyEnabledHelp": "หากไม่มีข้อความใดตรงเป๊ะ จะตอบกลับทันทีตามความคล้ายคลึง (รองรับการเติมคำหรือใช้คำพ้องความหมาย)",
|
||||
"fuzzyThreshold": "เกณฑ์การจับคู่แบบคลุมเครือ",
|
||||
"fuzzyThresholdHelp": "0.50–1.00 ค่าเริ่มต้น 0.80 จะตอบกลับทันทีเมื่อความคล้ายคลึงถึงเกณฑ์ ยิ่งต่ำยิ่งจับคู่ง่าย ยิ่งสูงยิ่งเข้มงวด",
|
||||
"expiresAt": "หมดอายุเมื่อ",
|
||||
"expiresAtHelp": "ไม่บังคับ หลังหมดอายุจะไม่จับคู่ ปล่อยว่างหากไม่มีวันหมดอายุ"
|
||||
},
|
||||
|
||||
@@ -1715,6 +1715,10 @@
|
||||
"isEnabled": "在前台展示",
|
||||
"isEnabledHelp": "仅控制工作台首页是否出现快捷入口,不影响聊天是否直答。",
|
||||
"cacheHelp": "开启后,匹配成功的问题将直接返回下方标准答案,不再调用 Dify。与是否在前台展示无关。",
|
||||
"fuzzyEnabled": "启用模糊匹配",
|
||||
"fuzzyEnabledHelp": "精确未命中时,按相似度兜底直答(容忍加字、换近义词等差异)。",
|
||||
"fuzzyThreshold": "模糊匹配阈值",
|
||||
"fuzzyThresholdHelp": "0.50–1.00,默认 0.80。相似度达到该值才直答;调低更容易命中,调高更保守。",
|
||||
"expiresAt": "过期时间",
|
||||
"expiresAtHelp": "可选。到期后不再命中缓存,留空表示长期有效。"
|
||||
},
|
||||
|
||||
@@ -1587,6 +1587,10 @@
|
||||
"isEnabled": "在前台展示",
|
||||
"isEnabledHelp": "僅控制工作台首頁是否出現快捷入口,不影響聊天是否直答。",
|
||||
"cacheHelp": "開啟後,匹配成功的問題將直接返回下方標準答案,不再呼叫 Dify。與是否在前台展示無關。",
|
||||
"fuzzyEnabled": "啟用模糊匹配",
|
||||
"fuzzyEnabledHelp": "精確未命中時,按相似度兜底直答(容忍加字、換近義詞等差異)。",
|
||||
"fuzzyThreshold": "模糊匹配閾值",
|
||||
"fuzzyThresholdHelp": "0.50–1.00,預設 0.80。相似度達到該值才直答;調低更容易命中,調高更保守。",
|
||||
"expiresAt": "過期時間",
|
||||
"expiresAtHelp": "可選。到期後不再命中快取,留空表示長期有效。"
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user