From 446301a443584b548fad82c2131f94228998af7d Mon Sep 17 00:00:00 2001 From: zxhlyh Date: Tue, 29 Jul 2025 11:10:16 +0800 Subject: [PATCH] fix: search method --- .../components/retrieval-setting/hooks.tsx | 2 +- .../retrieval-setting/search-method-option.tsx | 2 +- .../nodes/knowledge-base/hooks/use-config.ts | 13 +++++++++++-- .../knowledge-base/hooks/use-settings-display.ts | 2 +- .../workflow/nodes/knowledge-base/utils.ts | 9 +++++++++ 5 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 web/app/components/workflow/nodes/knowledge-base/utils.ts diff --git a/web/app/components/workflow/nodes/knowledge-base/components/retrieval-setting/hooks.tsx b/web/app/components/workflow/nodes/knowledge-base/components/retrieval-setting/hooks.tsx index 4b16c7d0e8..9d39f81182 100644 --- a/web/app/components/workflow/nodes/knowledge-base/components/retrieval-setting/hooks.tsx +++ b/web/app/components/workflow/nodes/knowledge-base/components/retrieval-setting/hooks.tsx @@ -46,7 +46,7 @@ export const useRetrievalSetting = (indexMethod?: IndexMethodEnum) => { }, [t]) const InvertedIndexOption: Option = useMemo(() => { return { - id: RetrievalSearchMethodEnum.keywordSearch, + id: RetrievalSearchMethodEnum.invertedIndex, icon: HybridSearch as any, title: t('dataset.retrieval.invertedIndex.title'), description: t('dataset.retrieval.invertedIndex.description'), diff --git a/web/app/components/workflow/nodes/knowledge-base/components/retrieval-setting/search-method-option.tsx b/web/app/components/workflow/nodes/knowledge-base/components/retrieval-setting/search-method-option.tsx index 74629f47ae..28389ca41e 100644 --- a/web/app/components/workflow/nodes/knowledge-base/components/retrieval-setting/search-method-option.tsx +++ b/web/app/components/workflow/nodes/knowledge-base/components/retrieval-setting/search-method-option.tsx @@ -194,7 +194,7 @@ const SearchMethodOption = ({ isScoreThresholdEnabled={isScoreThresholdEnabled} onScoreThresholdEnabledChange={onScoreThresholdEnabledChange} readonly={readonly} - hiddenScoreThreshold={searchMethod === RetrievalSearchMethodEnum.keywordSearch} + hiddenScoreThreshold={searchMethod === RetrievalSearchMethodEnum.invertedIndex} /> diff --git a/web/app/components/workflow/nodes/knowledge-base/hooks/use-config.ts b/web/app/components/workflow/nodes/knowledge-base/hooks/use-config.ts index aa3e449a9f..765d71a35b 100644 --- a/web/app/components/workflow/nodes/knowledge-base/hooks/use-config.ts +++ b/web/app/components/workflow/nodes/knowledge-base/hooks/use-config.ts @@ -15,6 +15,7 @@ import type { KnowledgeBaseNodeType, RerankingModel, } from '../types' +import { isHighQualitySearchMethod } from '../utils' export const useConfig = (id: string) => { const store = useStoreApi() @@ -36,10 +37,18 @@ export const useConfig = (id: string) => { const handleChunkStructureChange = useCallback((chunkStructure: ChunkStructureEnum) => { const nodeData = getNodeData() - const { indexing_technique } = nodeData?.data + const { + indexing_technique, + retrieval_model, + } = nodeData?.data + const { search_method } = retrieval_model || {} handleNodeDataUpdate({ chunk_structure: chunkStructure, indexing_technique: (chunkStructure === ChunkStructureEnum.parent_child || chunkStructure === ChunkStructureEnum.question_answer) ? IndexMethodEnum.QUALIFIED : indexing_technique, + retrieval_model: { + ...retrieval_model, + search_method: ((chunkStructure === ChunkStructureEnum.parent_child || chunkStructure === ChunkStructureEnum.question_answer) && !isHighQualitySearchMethod(search_method)) ? RetrievalSearchMethodEnum.semantic : search_method, + }, }) }, [handleNodeDataUpdate, getNodeData]) @@ -50,7 +59,7 @@ export const useConfig = (id: string) => { draft.indexing_technique = indexMethod if (indexMethod === IndexMethodEnum.ECONOMICAL) - draft.retrieval_model.search_method = RetrievalSearchMethodEnum.keywordSearch + draft.retrieval_model.search_method = RetrievalSearchMethodEnum.invertedIndex else if (indexMethod === IndexMethodEnum.QUALIFIED) draft.retrieval_model.search_method = RetrievalSearchMethodEnum.semantic })) diff --git a/web/app/components/workflow/nodes/knowledge-base/hooks/use-settings-display.ts b/web/app/components/workflow/nodes/knowledge-base/hooks/use-settings-display.ts index b4f0b50c0c..64679642ab 100644 --- a/web/app/components/workflow/nodes/knowledge-base/hooks/use-settings-display.ts +++ b/web/app/components/workflow/nodes/knowledge-base/hooks/use-settings-display.ts @@ -13,6 +13,6 @@ export const useSettingsDisplay = () => { [RetrievalSearchMethodEnum.semantic]: t('dataset.retrieval.semantic_search.title'), [RetrievalSearchMethodEnum.fullText]: t('dataset.retrieval.full_text_search.title'), [RetrievalSearchMethodEnum.hybrid]: t('dataset.retrieval.hybrid_search.title'), - [RetrievalSearchMethodEnum.keywordSearch]: t('dataset.retrieval.invertedIndex.title'), + [RetrievalSearchMethodEnum.invertedIndex]: t('dataset.retrieval.invertedIndex.title'), } } diff --git a/web/app/components/workflow/nodes/knowledge-base/utils.ts b/web/app/components/workflow/nodes/knowledge-base/utils.ts new file mode 100644 index 0000000000..c05721c098 --- /dev/null +++ b/web/app/components/workflow/nodes/knowledge-base/utils.ts @@ -0,0 +1,9 @@ +import { + RetrievalSearchMethodEnum, +} from './types' + +export const isHighQualitySearchMethod = (searchMethod: RetrievalSearchMethodEnum) => { + return searchMethod === RetrievalSearchMethodEnum.semantic + || searchMethod === RetrievalSearchMethodEnum.hybrid + || searchMethod === RetrievalSearchMethodEnum.fullText +}