From 446301a443584b548fad82c2131f94228998af7d Mon Sep 17 00:00:00 2001 From: zxhlyh Date: Tue, 29 Jul 2025 11:10:16 +0800 Subject: [PATCH 1/2] 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 +} From 6d00ffa50974566eceae86505780aede9626ee7b Mon Sep 17 00:00:00 2001 From: jyong <718720800@qq.com> Date: Tue, 29 Jul 2025 11:18:06 +0800 Subject: [PATCH 2/2] add old auth transform --- api/core/app/apps/pipeline/pipeline_generator.py | 3 ++- api/core/helper/name_generator.py | 2 +- .../rag_pipeline/pipeline_template/remote/remote_retrieval.py | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/api/core/app/apps/pipeline/pipeline_generator.py b/api/core/app/apps/pipeline/pipeline_generator.py index 17acc51b0d..b00b13437b 100644 --- a/api/core/app/apps/pipeline/pipeline_generator.py +++ b/api/core/app/apps/pipeline/pipeline_generator.py @@ -639,7 +639,8 @@ class PipelineGenerator(BaseAppGenerator): raise GenerateTaskStoppedError() else: logger.exception( - f"Fails to process generate task pipeline, task_id: {application_generate_entity.task_id}" + "Fails to process generate task pipeline, task_id: %r", + application_generate_entity.task_id, ) raise e diff --git a/api/core/helper/name_generator.py b/api/core/helper/name_generator.py index 2465e0ddfb..4e19e3946f 100644 --- a/api/core/helper/name_generator.py +++ b/api/core/helper/name_generator.py @@ -17,7 +17,7 @@ def generate_provider_name( f"{credential_type.get_name()}", ) except Exception as e: - logger.warning(f"Error generating next provider name for {fallback_context}: {str(e)}") + logger.warning("Error generating next provider name for %r: %r", fallback_context, e) return f"{credential_type.get_name()} 1" diff --git a/api/services/rag_pipeline/pipeline_template/remote/remote_retrieval.py b/api/services/rag_pipeline/pipeline_template/remote/remote_retrieval.py index 5553d7c97e..c7bf06e043 100644 --- a/api/services/rag_pipeline/pipeline_template/remote/remote_retrieval.py +++ b/api/services/rag_pipeline/pipeline_template/remote/remote_retrieval.py @@ -20,7 +20,7 @@ class RemotePipelineTemplateRetrieval(PipelineTemplateRetrievalBase): try: result = self.fetch_pipeline_template_detail_from_dify_official(pipeline_id) except Exception as e: - logger.warning(f"fetch recommended app detail from dify official failed: {e}, switch to built-in.") + logger.warning("fetch recommended app detail from dify official failed: %r, switch to built-in.", e) result = BuildInRecommendAppRetrieval.fetch_recommended_app_detail_from_builtin(pipeline_id) return result @@ -28,7 +28,7 @@ class RemotePipelineTemplateRetrieval(PipelineTemplateRetrievalBase): try: result = self.fetch_pipeline_templates_from_dify_official(language) except Exception as e: - logger.warning(f"fetch pipeline templates from dify official failed: {e}, switch to built-in.") + logger.warning("fetch pipeline templates from dify official failed: %r, switch to built-in.", e) result = BuildInRecommendAppRetrieval.fetch_recommended_apps_from_builtin(language) return result