mirror of
https://github.com/langgenius/dify.git
synced 2026-05-13 08:57:28 +08:00
Signed-off-by: majiayu000 <1835304752@qq.com> Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: NeatGuyCoding <15627489+NeatGuyCoding@users.noreply.github.com> Signed-off-by: -LAN- <laipz8200@outlook.com> Signed-off-by: yihong0618 <zouzou0208@gmail.com> Co-authored-by: QuantumGhost <obelisk.reg+git@gmail.com> Co-authored-by: 盐粒 Yanli <yanli@dify.ai> Co-authored-by: wangxiaolei <fatelei@gmail.com> Co-authored-by: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Cursx <33718736+Cursx@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: lif <1835304752@qq.com> Co-authored-by: 非法操作 <hjlarry@163.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org> Co-authored-by: fenglin <790872612@qq.com> Co-authored-by: qiaofenglin <qiaofenglin@baidu.com> Co-authored-by: -LAN- <laipz8200@outlook.com> Co-authored-by: TomoOkuyama <49631611+TomoOkuyama@users.noreply.github.com> Co-authored-by: Tomo Okuyama <tomo.okuyama@intersystems.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: zyssyz123 <916125788@qq.com> Co-authored-by: hj24 <mambahj24@gmail.com> Co-authored-by: Coding On Star <447357187@qq.com> Co-authored-by: CodingOnStar <hanxujiang@dify.ai> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com> Co-authored-by: Xiangxuan Qu <fghpdf@outlook.com> Co-authored-by: fghpdf <fghpdf@users.noreply.github.com> Co-authored-by: coopercoder <whitetiger0127@163.com> Co-authored-by: zhaiguangpeng <zhaiguangpeng@didiglobal.com> Co-authored-by: Junyan Qin (Chin) <rockchinq@gmail.com> Co-authored-by: E.G <146701565+GlobalStar117@users.noreply.github.com> Co-authored-by: GlobalStar117 <GlobalStar117@users.noreply.github.com> Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com> Co-authored-by: CodingOnStar <hanxujiang@dify.com> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: heyszt <270985384@qq.com> Co-authored-by: NeatGuyCoding <15627489+NeatGuyCoding@users.noreply.github.com> Co-authored-by: Yeuoly <45712896+Yeuoly@users.noreply.github.com> Co-authored-by: zxhlyh <jasonapring2015@outlook.com> Co-authored-by: moonpanda <chuanzegao@163.com> Co-authored-by: warlocgao <warlocgao@tencent.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: KVOJJJin <jzongcode@gmail.com> Co-authored-by: eux <euxx@users.noreply.github.com> Co-authored-by: bangjiehan <bangjiehan@gmail.com> Co-authored-by: FFXN <31929997+FFXN@users.noreply.github.com> Co-authored-by: Jyong <76649700+JohnJyong@users.noreply.github.com> Co-authored-by: Nie Ronghua <nieronghua@sf-express.com> Co-authored-by: JQSevenMiao <141806521+JQSevenMiao@users.noreply.github.com> Co-authored-by: jiasiqi <jiasiqi3@tal.com> Co-authored-by: Seokrin Taron Sung <sungsjade@gmail.com> Co-authored-by: CrabSAMA <40541269+CrabSAMA@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: yihong <zouzou0208@gmail.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: Wu Tianwei <30284043+WTW0313@users.noreply.github.com> Co-authored-by: yessenia <yessenia.contact@gmail.com> Co-authored-by: Jax <anobaka@qq.com> Co-authored-by: niveshdandyan <155956228+niveshdandyan@users.noreply.github.com> Co-authored-by: OSS Contributor <oss-contributor@example.com> Co-authored-by: niveshdandyan <niveshdandyan@users.noreply.github.com> Co-authored-by: Sean Kenneth Doherty <Smaster7772@gmail.com>
219 lines
8.5 KiB
TypeScript
219 lines
8.5 KiB
TypeScript
import type { FC } from 'react'
|
|
import type { KnowledgeBaseNodeType } from './types'
|
|
import type { NodePanelProps, Var } from '@/app/components/workflow/types'
|
|
import {
|
|
memo,
|
|
useCallback,
|
|
useMemo,
|
|
} from 'react'
|
|
import { useTranslation } from 'react-i18next'
|
|
import SummaryIndexSetting from '@/app/components/datasets/settings/summary-index-setting'
|
|
import { checkShowMultiModalTip } from '@/app/components/datasets/settings/utils'
|
|
import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
|
import { useModelList } from '@/app/components/header/account-setting/model-provider-page/hooks'
|
|
import { useNodesReadOnly } from '@/app/components/workflow/hooks'
|
|
import {
|
|
BoxGroup,
|
|
BoxGroupField,
|
|
Group,
|
|
} from '@/app/components/workflow/nodes/_base/components/layout'
|
|
import VarReferencePicker from '@/app/components/workflow/nodes/_base/components/variable/var-reference-picker'
|
|
import Split from '../_base/components/split'
|
|
import ChunkStructure from './components/chunk-structure'
|
|
import EmbeddingModel from './components/embedding-model'
|
|
import IndexMethod from './components/index-method'
|
|
import RetrievalSetting from './components/retrieval-setting'
|
|
import { useConfig } from './hooks/use-config'
|
|
import {
|
|
ChunkStructureEnum,
|
|
IndexMethodEnum,
|
|
} from './types'
|
|
|
|
const Panel: FC<NodePanelProps<KnowledgeBaseNodeType>> = ({
|
|
id,
|
|
data,
|
|
}) => {
|
|
const { t } = useTranslation()
|
|
const { nodesReadOnly } = useNodesReadOnly()
|
|
const { data: embeddingModelList } = useModelList(ModelTypeEnum.textEmbedding)
|
|
const { data: rerankModelList } = useModelList(ModelTypeEnum.rerank)
|
|
|
|
const {
|
|
handleChunkStructureChange,
|
|
handleIndexMethodChange,
|
|
handleKeywordNumberChange,
|
|
handleEmbeddingModelChange,
|
|
handleRetrievalSearchMethodChange,
|
|
handleHybridSearchModeChange,
|
|
handleRerankingModelEnabledChange,
|
|
handleWeighedScoreChange,
|
|
handleRerankingModelChange,
|
|
handleTopKChange,
|
|
handleScoreThresholdChange,
|
|
handleScoreThresholdEnabledChange,
|
|
handleInputVariableChange,
|
|
handleSummaryIndexSettingChange,
|
|
} = useConfig(id)
|
|
|
|
const filterVar = useCallback((variable: Var) => {
|
|
if (!data.chunk_structure)
|
|
return false
|
|
switch (data.chunk_structure) {
|
|
case ChunkStructureEnum.general:
|
|
return variable.schemaType === 'general_structure' || variable.schemaType === 'multimodal_general_structure'
|
|
case ChunkStructureEnum.parent_child:
|
|
return variable.schemaType === 'parent_child_structure' || variable.schemaType === 'multimodal_parent_child_structure'
|
|
case ChunkStructureEnum.question_answer:
|
|
return variable.schemaType === 'qa_structure'
|
|
default:
|
|
return false
|
|
}
|
|
}, [data.chunk_structure])
|
|
|
|
const chunkTypePlaceHolder = useMemo(() => {
|
|
if (!data.chunk_structure)
|
|
return ''
|
|
let placeholder = ''
|
|
switch (data.chunk_structure) {
|
|
case ChunkStructureEnum.general:
|
|
placeholder = '(multimodal_)general_structure'
|
|
break
|
|
case ChunkStructureEnum.parent_child:
|
|
placeholder = '(multimodal_)parent_child_structure'
|
|
break
|
|
case ChunkStructureEnum.question_answer:
|
|
placeholder = 'qa_structure'
|
|
break
|
|
default:
|
|
return ''
|
|
}
|
|
return placeholder.charAt(0).toUpperCase() + placeholder.slice(1)
|
|
}, [data.chunk_structure])
|
|
|
|
const showMultiModalTip = useMemo(() => {
|
|
return checkShowMultiModalTip({
|
|
embeddingModel: {
|
|
provider: data.embedding_model_provider ?? '',
|
|
model: data.embedding_model ?? '',
|
|
},
|
|
rerankingEnable: !!data.retrieval_model?.reranking_enable,
|
|
rerankModel: {
|
|
rerankingProviderName: data.retrieval_model?.reranking_model?.reranking_provider_name ?? '',
|
|
rerankingModelName: data.retrieval_model?.reranking_model?.reranking_model_name ?? '',
|
|
},
|
|
indexMethod: data.indexing_technique,
|
|
embeddingModelList,
|
|
rerankModelList,
|
|
})
|
|
}, [data.embedding_model_provider, data.embedding_model, data.retrieval_model?.reranking_enable, data.retrieval_model?.reranking_model, data.indexing_technique, embeddingModelList, rerankModelList])
|
|
|
|
return (
|
|
<div>
|
|
<Group
|
|
className="py-3"
|
|
withBorderBottom={!!data.chunk_structure}
|
|
>
|
|
<ChunkStructure
|
|
chunkStructure={data.chunk_structure}
|
|
onChunkStructureChange={handleChunkStructureChange}
|
|
readonly={nodesReadOnly}
|
|
/>
|
|
</Group>
|
|
{
|
|
!!data.chunk_structure && (
|
|
<>
|
|
<BoxGroupField
|
|
boxGroupProps={{
|
|
boxProps: { withBorderBottom: true },
|
|
}}
|
|
fieldProps={{
|
|
fieldTitleProps: {
|
|
title: t('nodes.knowledgeBase.chunksInput', { ns: 'workflow' }),
|
|
tooltip: t('nodes.knowledgeBase.chunksInputTip', { ns: 'workflow' }),
|
|
},
|
|
}}
|
|
>
|
|
<VarReferencePicker
|
|
nodeId={id}
|
|
isShowNodeName
|
|
value={data.index_chunk_variable_selector}
|
|
onChange={handleInputVariableChange}
|
|
readonly={nodesReadOnly}
|
|
filterVar={filterVar}
|
|
isFilterFileVar
|
|
isSupportFileVar={false}
|
|
preferSchemaType
|
|
typePlaceHolder={chunkTypePlaceHolder}
|
|
/>
|
|
</BoxGroupField>
|
|
<BoxGroup>
|
|
<div className="space-y-3">
|
|
<IndexMethod
|
|
chunkStructure={data.chunk_structure}
|
|
indexMethod={data.indexing_technique}
|
|
onIndexMethodChange={handleIndexMethodChange}
|
|
keywordNumber={data.keyword_number}
|
|
onKeywordNumberChange={handleKeywordNumberChange}
|
|
readonly={nodesReadOnly}
|
|
/>
|
|
{
|
|
data.indexing_technique === IndexMethodEnum.QUALIFIED && (
|
|
<EmbeddingModel
|
|
embeddingModel={data.embedding_model}
|
|
embeddingModelProvider={data.embedding_model_provider}
|
|
onEmbeddingModelChange={handleEmbeddingModelChange}
|
|
readonly={nodesReadOnly}
|
|
/>
|
|
)
|
|
}
|
|
<div className="pt-1">
|
|
<Split className="h-[1px]" />
|
|
</div>
|
|
{
|
|
data.indexing_technique === IndexMethodEnum.QUALIFIED
|
|
&& [ChunkStructureEnum.general, ChunkStructureEnum.parent_child].includes(data.chunk_structure)
|
|
&& (
|
|
<>
|
|
<SummaryIndexSetting
|
|
summaryIndexSetting={data.summary_index_setting}
|
|
onSummaryIndexSettingChange={handleSummaryIndexSettingChange}
|
|
readonly={nodesReadOnly}
|
|
/>
|
|
<div className="pt-1">
|
|
<Split className="h-[1px]" />
|
|
</div>
|
|
</>
|
|
)
|
|
}
|
|
<RetrievalSetting
|
|
indexMethod={data.indexing_technique}
|
|
searchMethod={data.retrieval_model.search_method}
|
|
onRetrievalSearchMethodChange={handleRetrievalSearchMethodChange}
|
|
hybridSearchMode={data.retrieval_model.reranking_mode}
|
|
onHybridSearchModeChange={handleHybridSearchModeChange}
|
|
weightedScore={data.retrieval_model.weights}
|
|
onWeightedScoreChange={handleWeighedScoreChange}
|
|
rerankingModelEnabled={data.retrieval_model.reranking_enable}
|
|
onRerankingModelEnabledChange={handleRerankingModelEnabledChange}
|
|
rerankingModel={data.retrieval_model.reranking_model}
|
|
onRerankingModelChange={handleRerankingModelChange}
|
|
topK={data.retrieval_model.top_k}
|
|
onTopKChange={handleTopKChange}
|
|
scoreThreshold={data.retrieval_model.score_threshold}
|
|
onScoreThresholdChange={handleScoreThresholdChange}
|
|
isScoreThresholdEnabled={data.retrieval_model.score_threshold_enabled}
|
|
onScoreThresholdEnabledChange={handleScoreThresholdEnabledChange}
|
|
showMultiModalTip={showMultiModalTip}
|
|
readonly={nodesReadOnly}
|
|
/>
|
|
</div>
|
|
</BoxGroup>
|
|
</>
|
|
)
|
|
}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default memo(Panel)
|