diff --git a/docs/assets/search-settings-rrf.png b/docs/assets/search-settings-rrf.png new file mode 100644 index 00000000..ac525b76 Binary files /dev/null and b/docs/assets/search-settings-rrf.png differ diff --git a/frontend/src/api/retrieval.ts b/frontend/src/api/retrieval.ts index 24598d11..740599f9 100644 --- a/frontend/src/api/retrieval.ts +++ b/frontend/src/api/retrieval.ts @@ -9,6 +9,9 @@ export interface RetrievalConfig { rerank_top_k: number rerank_threshold: number rerank_model_id: string + rrf_k?: number + rrf_vector_weight?: number + rrf_keyword_weight?: number } // Get tenant retrieval config via KV API diff --git a/frontend/src/components/GlobalCommandPalette.vue b/frontend/src/components/GlobalCommandPalette.vue index e3b16608..891c402b 100644 --- a/frontend/src/components/GlobalCommandPalette.vue +++ b/frontend/src/components/GlobalCommandPalette.vue @@ -1,6 +1,6 @@ @@ -205,7 +213,7 @@ const { agentsEnabled: () => deploymentCapabilities.isSupported('agents'), }) -const drawerVisible = ref(false) +const settingsVisible = ref(false) const inputRef = ref(null) const scrollRef = ref(null) @@ -499,6 +507,11 @@ const shortcutFor = (flatIndex: number): number | undefined => { } const onKeyDown = (e: KeyboardEvent) => { + if (settingsVisible.value && e.key === 'Escape') { + e.preventDefault() + settingsVisible.value = false + return + } if (e.key === 'ArrowDown') { e.preventDefault() moveSelection(1) @@ -542,7 +555,7 @@ const onInputKeyDown = (e: KeyboardEvent) => { } const handleClose = () => { - drawerVisible.value = false + settingsVisible.value = false commandPaletteStore.closePalette() } @@ -599,7 +612,7 @@ watch(open, (val) => { } else { clearResults() query.value = '' - drawerVisible.value = false + settingsVisible.value = false activeKbScope.value = null } }) @@ -860,9 +873,24 @@ onUnmounted(() => { } } -.cmdk-retrieval-drawer { - .section-header { - font-weight: 600; - } +.cmdk-settings-popover { + position: relative; + width: min(420px, calc(100vw - 32px)); + max-height: min(680px, calc(100dvh - 140px)); + overflow-y: auto; + overscroll-behavior: contain; + box-sizing: border-box; + padding: 12px 14px 14px; + &__close { position: absolute; top: 12px; right: 12px; } +} + + + diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index e70ee24b..e283b0e0 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -2563,6 +2563,15 @@ export default { } }, retrievalSettings: { + recallTab: 'Recall', + rerankTab: 'Reranking', + rrfTitle: 'Result fusion (RRF)', + rrfKLabel: 'RRF smoothing constant (K)', + rrfKDescription: 'Larger values reduce the advantage of top-ranked results. Default: 60; 0 uses the default.', + rrfVectorWeightLabel: 'RRF vector weight', + rrfVectorWeightDescription: 'Controls the contribution of vector search to merged results. Default: 0.7; 0 uses the default. Weights do not need to sum to 1.', + rrfKeywordWeightLabel: 'RRF keyword weight', + rrfKeywordWeightDescription: 'Controls the contribution of keyword search to merged results. Default: 0.3; 0 uses the default. Weights do not need to sum to 1.', title: 'Search Settings', description: 'Configure global retrieval parameters for knowledge search and message search', embeddingTopKLabel: 'Vector Search Top K', diff --git a/frontend/src/i18n/locales/ja-JP.ts b/frontend/src/i18n/locales/ja-JP.ts index 9d6a2a34..91128ef4 100644 --- a/frontend/src/i18n/locales/ja-JP.ts +++ b/frontend/src/i18n/locales/ja-JP.ts @@ -2563,6 +2563,15 @@ export default { } }, retrievalSettings: { + recallTab: '検索候補', + rerankTab: '再ランキング', + rrfTitle: '結果の統合(RRF)', + rrfKLabel: 'RRF 平滑化定数 (K)', + rrfKDescription: '値が大きいほど上位の検索結果の優位性が小さくなります。既定値は 60。0 は既定値を使用します。', + rrfVectorWeightLabel: 'RRF ベクトル重み', + rrfVectorWeightDescription: '統合結果に対するベクトル検索の影響を調整します。既定値は 0.7。0 は既定値を使用します。重みの合計を 1 にする必要はありません。', + rrfKeywordWeightLabel: 'RRF キーワード重み', + rrfKeywordWeightDescription: '統合結果に対するキーワード検索の影響を調整します。既定値は 0.3。0 は既定値を使用します。重みの合計を 1 にする必要はありません。', title: '検索設定', description: 'ナレッジベース検索とメッセージ検索に共通する検索パラメータを設定します', embeddingTopKLabel: 'ベクトル検索のTop K', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index abb6ac76..60670f11 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -5606,6 +5606,15 @@ export default { howToEnable: '지식 그래프를 활성화하는 방법?' }, retrievalSettings: { + recallTab: '검색 후보', + rerankTab: '재순위 지정', + rrfTitle: '결과 통합 (RRF)', + rrfKLabel: 'RRF 평활 상수 (K)', + rrfKDescription: '값이 클수록 상위 검색 결과의 우위가 줄어듭니다. 기본값은 60이며, 0은 기본값을 사용합니다.', + rrfVectorWeightLabel: 'RRF 벡터 가중치', + rrfVectorWeightDescription: '통합 결과에 대한 벡터 검색의 영향을 조정합니다. 기본값은 0.7이며, 0은 기본값을 사용합니다. 가중치의 합이 1일 필요는 없습니다.', + rrfKeywordWeightLabel: 'RRF 키워드 가중치', + rrfKeywordWeightDescription: '통합 결과에 대한 키워드 검색의 영향을 조정합니다. 기본값은 0.3이며, 0은 기본값을 사용합니다. 가중치의 합이 1일 필요는 없습니다.', title: '검색 설정', description: '전역 검색 파라미터를 설정합니다. 지식베이스 검색과 메시지 검색이 이 설정을 공유합니다', embeddingTopKLabel: '벡터 검색 Top K', diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index 591a063a..c3aa7aeb 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -5606,6 +5606,15 @@ export default { howToEnable: 'Как включить граф знаний?' }, retrievalSettings: { + recallTab: 'Отбор', + rerankTab: 'Переранжирование', + rrfTitle: 'Объединение результатов (RRF)', + rrfKLabel: 'Константа сглаживания RRF (K)', + rrfKDescription: 'Чем больше значение, тем меньше преимущество первых результатов. По умолчанию: 60; 0 использует значение по умолчанию.', + rrfVectorWeightLabel: 'Вес векторного поиска RRF', + rrfVectorWeightDescription: 'Влияние векторного поиска на объединённые результаты. По умолчанию: 0.7; 0 использует значение по умолчанию. Сумма весов не обязана равняться 1.', + rrfKeywordWeightLabel: 'Вес поиска по ключевым словам RRF', + rrfKeywordWeightDescription: 'Влияние поиска по ключевым словам на объединённые результаты. По умолчанию: 0.3; 0 использует значение по умолчанию. Сумма весов не обязана равняться 1.', title: 'Настройки поиска', description: 'Настройте глобальные параметры поиска, общие для поиска по знаниям и сообщениям', embeddingTopKLabel: 'Векторный поиск Top K', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index 79e7bbe7..38c5d300 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -5608,6 +5608,15 @@ export default { howToEnable: '如何启用知识图谱?' }, retrievalSettings: { + recallTab: '召回', + rerankTab: '重排序', + rrfTitle: '结果融合(RRF)', + rrfKLabel: 'RRF 平滑常数 (K)', + rrfKDescription: '值越大,排名靠前结果的优势越小。默认 60;设为 0 使用默认值。', + rrfVectorWeightLabel: 'RRF 向量权重', + rrfVectorWeightDescription: '控制向量检索对融合结果的影响。默认 0.7;设为 0 使用默认值。两项权重之和无需等于 1。', + rrfKeywordWeightLabel: 'RRF 关键词权重', + rrfKeywordWeightDescription: '控制关键词检索对融合结果的影响。默认 0.3;设为 0 使用默认值。两项权重之和无需等于 1。', title: '搜索设置', description: '配置知识库搜索和消息搜索的全局检索参数', embeddingTopKLabel: '向量检索数量 (Top K)', diff --git a/frontend/src/i18n/locales/zh-TW.ts b/frontend/src/i18n/locales/zh-TW.ts index ca069c27..c61831d6 100644 --- a/frontend/src/i18n/locales/zh-TW.ts +++ b/frontend/src/i18n/locales/zh-TW.ts @@ -5608,6 +5608,15 @@ export default { howToEnable: '如何啟用知識圖譜?' }, retrievalSettings: { + recallTab: '召回', + rerankTab: '重排序', + rrfTitle: '結果融合(RRF)', + rrfKLabel: 'RRF 平滑常數 (K)', + rrfKDescription: '值越大,排名靠前結果的優勢越小。預設 60;設為 0 使用預設值。', + rrfVectorWeightLabel: 'RRF 向量權重', + rrfVectorWeightDescription: '控制向量檢索對融合結果的影響。預設 0.7;設為 0 使用預設值。兩項權重之和無需等於 1。', + rrfKeywordWeightLabel: 'RRF 關鍵詞權重', + rrfKeywordWeightDescription: '控制關鍵詞檢索對融合結果的影響。預設 0.3;設為 0 使用預設值。兩項權重之和無需等於 1。', title: '搜尋設定', description: '設定知識庫搜尋和訊息搜尋的全局檢索參數', embeddingTopKLabel: '向量檢索數量 (Top K)', diff --git a/frontend/src/views/settings/RetrievalSettings.test.ts b/frontend/src/views/settings/RetrievalSettings.test.ts new file mode 100644 index 00000000..11c48474 --- /dev/null +++ b/frontend/src/views/settings/RetrievalSettings.test.ts @@ -0,0 +1,136 @@ +import assert from 'node:assert/strict' +import { readFileSync } from 'node:fs' +import { test } from 'node:test' +import { runInNewContext } from 'node:vm' +import { compileScript, parse } from '@vue/compiler-sfc' +import ts from 'typescript' +import * as vue from 'vue' + +const source = readFileSync(new URL('./RetrievalSettings.vue', import.meta.url), 'utf8') +const { descriptor } = parse(source) +const script = compileScript(descriptor, { id: 'retrieval-settings-test' }).content +const compiled = ts.transpileModule(script, { + compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 }, +}).outputText + +const baseConfig = { + embedding_top_k: 50, + vector_threshold: 0.15, + keyword_threshold: 0.3, + rerank_top_k: 10, + rerank_threshold: 0.2, + rerank_model_id: 'existing-model', +} + +type RrfField = 'rrf_k' | 'rrf_vector_weight' | 'rrf_keyword_weight' +type SettingsState = { + localConfig: Record + handleParamChange: () => void + handleRrfChange: (field: RrfField, value: number | string) => void +} + +async function editConfig( + config: Record, + edit: (state: SettingsState) => void, + canEdit = true, +) { + let mounted: (() => Promise) | undefined + const timers = new Map void>() + let timerID = 0 + const setTimeout = (callback: () => void) => { + timers.set(++timerID, callback) + return timerID + } + const clearTimeout = (id: number) => timers.delete(id) + const writes: Record[] = [] + const mocks: Record = { + vue: { ...vue, onMounted: (callback: () => Promise) => { mounted = callback } }, + 'tdesign-vue-next': { MessagePlugin: { success() {}, error() {} } }, + 'vue-i18n': { useI18n: () => ({ t: (key: string) => key }) }, + '@/components/ModelSelector.vue': {}, + '@/stores/auth': { useAuthStore: () => ({ hasRole: () => canEdit }) }, + '@/api/retrieval': { + getTenantRetrievalConfig: async () => ({ data: config }), + updateTenantRetrievalConfig: async (body: Record) => { + // Exercise the JSON serialization used for the PUT request. + writes.push(JSON.parse(JSON.stringify(body))) + return { data: body } + }, + }, + } + const sandbox = { + exports: {} as { default: { setup: (props: object, ctx: object) => SettingsState } }, + require: (name: string) => { + assert.ok(name in mocks, `Unexpected component import: ${name}`) + return mocks[name] + }, + console, setTimeout, clearTimeout, window: { setTimeout, clearTimeout }, + } + runInNewContext(compiled, sandbox) + const state = sandbox.exports.default.setup({}, { expose() {} }) + assert.ok(mounted) + await mounted() + assert.equal(writes.length, 0, 'loading the config must not save it') + for (const [id, callback] of timers) { + timers.delete(id) + callback() + } + edit(state) + for (const [id, callback] of timers) { + timers.delete(id) + callback() + } + await Promise.resolve() + return writes +} + +for (const [name, rrf] of [ + ['custom RRF parameters', { rrf_k: 90, rrf_vector_weight: 0.2, rrf_keyword_weight: 0.8 }], + ['omitted RRF parameters', {}], + ['explicit zero RRF parameters', { rrf_k: 0, rrf_vector_weight: 0, rrf_keyword_weight: 0 }], +] as const) { + test(`editing Top K preserves ${name} in the serialized PUT body`, async () => { + const config = { ...baseConfig, ...rrf } + const writes = await editConfig(config, state => { + state.localConfig.embedding_top_k = 25 + state.handleParamChange() + }) + assert.equal(writes.length, 1) + assert.deepEqual(writes[0], { ...config, embedding_top_k: 25 }) + }) +} + +for (const [field, value] of [ + ['rrf_k', 90], + ['rrf_vector_weight', 1.25], + ['rrf_keyword_weight', 0.45], +] as const) { + test(`editing ${field} saves the new value and preserves the other settings`, async () => { + const config = { ...baseConfig, rrf_k: 75, rrf_vector_weight: 0.85, rrf_keyword_weight: 0.15 } + const writes = await editConfig(config, state => state.handleRrfChange(field, value)) + assert.deepEqual(writes, [{ ...config, [field]: value }]) + }) +} + +test('RRF edits coalesce into one save and zero selects the server default', async () => { + const writes = await editConfig(baseConfig, state => { + state.handleRrfChange('rrf_k', 80) + state.handleRrfChange('rrf_k', 0) + state.handleRrfChange('rrf_vector_weight', 0) + state.handleRrfChange('rrf_keyword_weight', 0) + }) + assert.deepEqual(writes, [{ ...baseConfig, rrf_k: 0, rrf_vector_weight: 0, rrf_keyword_weight: 0 }]) +}) + +test('cleared, invalid and fractional K inputs do not overwrite saved values', async () => { + const writes = await editConfig({ ...baseConfig, rrf_k: 75, rrf_vector_weight: 0.8 }, state => { + for (const value of ['', -1, NaN, Infinity]) state.handleRrfChange('rrf_vector_weight', value) + state.handleRrfChange('rrf_k', 1.5) + }) + assert.deepEqual(writes, []) +}) + +test('non-admins cannot change RRF configuration', async () => { + const writes = await editConfig(baseConfig, state => state.handleRrfChange('rrf_k', 90), false) + assert.deepEqual(writes, []) +}) diff --git a/frontend/src/views/settings/RetrievalSettings.vue b/frontend/src/views/settings/RetrievalSettings.vue index 401d3765..c7de474d 100644 --- a/frontend/src/views/settings/RetrievalSettings.vue +++ b/frontend/src/views/settings/RetrievalSettings.vue @@ -1,115 +1,146 @@