130 lines
4.4 KiB
TypeScript
Raw Normal View History

2025-04-25 17:24:47 +08:00
import type { FC } from 'react'
2025-05-06 17:24:30 +08:00
import {
memo,
} from 'react'
2025-05-23 16:27:19 +08:00
import { useTranslation } from 'react-i18next'
2025-04-25 17:24:47 +08:00
import type { KnowledgeBaseNodeType } from './types'
2025-05-06 17:24:30 +08:00
import {
IndexMethodEnum,
} from './types'
2025-04-28 18:36:55 +08:00
import ChunkStructure from './components/chunk-structure'
2025-04-28 12:12:33 +08:00
import IndexMethod from './components/index-method'
2025-04-28 18:36:55 +08:00
import RetrievalSetting from './components/retrieval-setting'
import EmbeddingModel from './components/embedding-model'
2025-05-06 17:24:30 +08:00
import { useConfig } from './hooks/use-config'
2025-04-25 17:24:47 +08:00
import type { NodePanelProps } from '@/app/components/workflow/types'
2025-04-28 18:36:55 +08:00
import {
2025-05-23 16:27:19 +08:00
BoxGroup,
BoxGroupField,
2025-04-28 18:36:55 +08:00
Group,
} from '@/app/components/workflow/nodes/_base/components/layout'
import Split from '../_base/components/split'
2025-05-14 11:14:16 +08:00
import { useNodesReadOnly } from '@/app/components/workflow/hooks'
2025-05-23 16:27:19 +08:00
import VarReferencePicker from '@/app/components/workflow/nodes/_base/components/variable/var-reference-picker'
2025-04-25 17:24:47 +08:00
2025-05-06 17:24:30 +08:00
const Panel: FC<NodePanelProps<KnowledgeBaseNodeType>> = ({
id,
data,
}) => {
2025-05-23 16:27:19 +08:00
const { t } = useTranslation()
2025-05-14 11:14:16 +08:00
const { nodesReadOnly } = useNodesReadOnly()
2025-05-06 17:24:30 +08:00
const {
handleChunkStructureChange,
handleIndexMethodChange,
handleKeywordNumberChange,
2025-05-07 15:08:13 +08:00
handleEmbeddingModelChange,
2025-05-06 17:24:30 +08:00
handleRetrievalSearchMethodChange,
handleHybridSearchModeChange,
handleWeighedScoreChange,
handleRerankingModelChange,
2025-05-07 15:08:13 +08:00
handleTopKChange,
handleScoreThresholdChange,
handleScoreThresholdEnabledChange,
2025-05-08 15:31:37 +08:00
handleInputVariableChange,
2025-05-06 17:24:30 +08:00
} = useConfig(id)
2025-04-25 17:24:47 +08:00
return (
2025-04-28 12:12:33 +08:00
<div>
2025-05-23 16:27:19 +08:00
<BoxGroupField
boxGroupProps={{
boxProps: { withBorderBottom: true },
}}
fieldProps={{
fieldTitleProps: {
title: t('workflow.nodes.common.inputVars'),
},
}}
>
<VarReferencePicker
2025-05-08 15:31:37 +08:00
nodeId={id}
2025-05-23 16:27:19 +08:00
isShowNodeName
value={data.index_chunk_variable_selector}
onChange={handleInputVariableChange}
2025-05-14 11:14:16 +08:00
readonly={nodesReadOnly}
2025-05-08 15:31:37 +08:00
/>
2025-05-23 16:27:19 +08:00
</BoxGroupField>
2025-04-28 18:36:55 +08:00
<Group
className='py-3'
withBorderBottom
>
2025-05-06 17:24:30 +08:00
<ChunkStructure
chunkStructure={data.chunk_structure}
onChunkStructureChange={handleChunkStructureChange}
2025-05-14 11:14:16 +08:00
readonly={nodesReadOnly}
2025-05-06 17:24:30 +08:00
/>
2025-04-28 18:36:55 +08:00
</Group>
2025-05-23 16:27:19 +08:00
<BoxGroup>
2025-04-28 18:36:55 +08:00
<div className='space-y-3'>
2025-05-06 17:24:30 +08:00
{
2025-05-28 13:56:03 +08:00
data.chunk_structure && (
<>
<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>
</>
2025-05-06 17:24:30 +08:00
)
}
<RetrievalSetting
2025-05-19 15:59:04 +08:00
indexMethod={data.indexing_technique}
2025-05-06 17:24:30 +08:00
searchMethod={data.retrieval_model.search_method}
onRetrievalSearchMethodChange={handleRetrievalSearchMethodChange}
hybridSearchMode={data.retrieval_model.hybridSearchMode}
onHybridSearchModeChange={handleHybridSearchModeChange}
weightedScore={data.retrieval_model.weights}
onWeightedScoreChange={handleWeighedScoreChange}
rerankingModel={data.retrieval_model.reranking_model}
onRerankingModelChange={handleRerankingModelChange}
2025-05-07 15:08:13 +08:00
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}
2025-05-14 11:14:16 +08:00
readonly={nodesReadOnly}
2025-05-06 17:24:30 +08:00
/>
2025-04-28 12:12:33 +08:00
</div>
2025-05-23 16:27:19 +08:00
</BoxGroup>
2025-04-25 17:24:47 +08:00
</div>
)
}
export default memo(Panel)