knowledge base default data

This commit is contained in:
zxhlyh 2025-05-28 13:56:03 +08:00
parent 29d2f2339b
commit b9214ca76b
11 changed files with 91 additions and 59 deletions

View File

@ -1,13 +1,15 @@
import { memo } from 'react' import { memo } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { RiAddLine } from '@remixicon/react'
import { Field } from '@/app/components/workflow/nodes/_base/components/layout' import { Field } from '@/app/components/workflow/nodes/_base/components/layout'
import type { ChunkStructureEnum } from '../../types' import type { ChunkStructureEnum } from '../../types'
import OptionCard from '../option-card' import OptionCard from '../option-card'
import Selector from './selector' import Selector from './selector'
import { useChunkStructure } from './hooks' import { useChunkStructure } from './hooks'
import Button from '@/app/components/base/button'
type ChunkStructureProps = { type ChunkStructureProps = {
chunkStructure: ChunkStructureEnum chunkStructure?: ChunkStructureEnum
onChunkStructureChange: (value: ChunkStructureEnum) => void onChunkStructureChange: (value: ChunkStructureEnum) => void
readonly?: boolean readonly?: boolean
} }
@ -27,7 +29,7 @@ const ChunkStructure = ({
fieldTitleProps={{ fieldTitleProps={{
title: t('workflow.nodes.knowledgeBase.chunkStructure'), title: t('workflow.nodes.knowledgeBase.chunkStructure'),
tooltip: t('workflow.nodes.knowledgeBase.chunkStructure'), tooltip: t('workflow.nodes.knowledgeBase.chunkStructure'),
operation: ( operation: chunkStructure && (
<Selector <Selector
options={options} options={options}
value={chunkStructure} value={chunkStructure}
@ -37,12 +39,34 @@ const ChunkStructure = ({
), ),
}} }}
> >
<OptionCard {
{...optionMap[chunkStructure]} chunkStructure && (
selectedId={chunkStructure} <OptionCard
enableSelect={false} {...optionMap[chunkStructure]}
enableHighlightBorder={false} selectedId={chunkStructure}
/> enableSelect={false}
enableHighlightBorder={false}
/>
)
}
{
!chunkStructure && (
<Selector
options={options}
onChange={onChunkStructureChange}
readonly={readonly}
trigger={(
<Button
className='w-full'
variant='secondary-accent'
>
<RiAddLine className='mr-1 h-4 w-4' />
{t('workflow.nodes.knowledgeBase.chooseChunkStructure')}
</Button>
)}
/>
)
}
</Field> </Field>
) )
} }

View File

@ -1,3 +1,4 @@
import type { ReactNode } from 'react'
import { useCallback, useState } from 'react' import { useCallback, useState } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { import {
@ -12,15 +13,17 @@ import type { Option } from './type'
type SelectorProps = { type SelectorProps = {
options: Option[] options: Option[]
value: ChunkStructureEnum value?: ChunkStructureEnum
onChange: (key: ChunkStructureEnum) => void onChange: (key: ChunkStructureEnum) => void
readonly?: boolean readonly?: boolean
trigger?: ReactNode
} }
const Selector = ({ const Selector = ({
options, options,
value, value,
onChange, onChange,
readonly, readonly,
trigger,
}: SelectorProps) => { }: SelectorProps) => {
const { t } = useTranslation() const { t } = useTranslation()
const [open, setOpen] = useState(false) const [open, setOpen] = useState(false)
@ -40,17 +43,24 @@ const Selector = ({
open={open} open={open}
onOpenChange={setOpen} onOpenChange={setOpen}
> >
<PortalToFollowElemTrigger onClick={() => { <PortalToFollowElemTrigger
if (readonly) asChild
return onClick={() => {
setOpen(!open) if (readonly)
}}> return
<Button setOpen(!open)
size='small' }}
variant='ghost-accent' >
> {
{t('workflow.panel.change')} trigger || (
</Button> <Button
size='small'
variant='ghost-accent'
>
{t('workflow.panel.change')}
</Button>
)
}
</PortalToFollowElemTrigger> </PortalToFollowElemTrigger>
<PortalToFollowElemContent className='z-10'> <PortalToFollowElemContent className='z-10'>
<div className='w-[404px] rounded-2xl border-[0.5px] border-components-panel-border bg-components-panel-bg-blur shadow-xl backdrop-blur-[5px]'> <div className='w-[404px] rounded-2xl border-[0.5px] border-components-panel-border bg-components-panel-bg-blur shadow-xl backdrop-blur-[5px]'>

View File

@ -21,7 +21,7 @@ import {
type IndexMethodProps = { type IndexMethodProps = {
chunkStructure: ChunkStructureEnum chunkStructure: ChunkStructureEnum
indexMethod: IndexMethodEnum indexMethod?: IndexMethodEnum
onIndexMethodChange: (value: IndexMethodEnum) => void onIndexMethodChange: (value: IndexMethodEnum) => void
keywordNumber: number keywordNumber: number
onKeywordNumberChange: (value: number) => void onKeywordNumberChange: (value: number) => void

View File

@ -15,7 +15,7 @@ import type {
Option, Option,
} from './type' } from './type'
export const useRetrievalSetting = (indexMethod: IndexMethodEnum) => { export const useRetrievalSetting = (indexMethod?: IndexMethodEnum) => {
const { t } = useTranslation() const { t } = useTranslation()
const VectorSearchOption: Option = useMemo(() => { const VectorSearchOption: Option = useMemo(() => {
return { return {

View File

@ -17,11 +17,11 @@ import type { RerankingModelSelectorProps } from './reranking-model-selector'
import SearchMethodOption from './search-method-option' import SearchMethodOption from './search-method-option'
type RetrievalSettingProps = { type RetrievalSettingProps = {
indexMethod: IndexMethodEnum indexMethod?: IndexMethodEnum
readonly?: boolean readonly?: boolean
searchMethod: RetrievalSearchMethodEnum searchMethod?: RetrievalSearchMethodEnum
onRetrievalSearchMethodChange: (value: RetrievalSearchMethodEnum) => void onRetrievalSearchMethodChange: (value: RetrievalSearchMethodEnum) => void
hybridSearchMode: HybridSearchModeEnum hybridSearchMode?: HybridSearchModeEnum
onHybridSearchModeChange: (value: HybridSearchModeEnum) => void onHybridSearchModeChange: (value: HybridSearchModeEnum) => void
rerankingModelEnabled?: boolean rerankingModelEnabled?: boolean
onRerankingModelEnabledChange?: (value: boolean) => void onRerankingModelEnabledChange?: (value: boolean) => void

View File

@ -30,9 +30,9 @@ type SearchMethodOptionProps = {
readonly?: boolean readonly?: boolean
option: Option option: Option
hybridSearchModeOptions: HybridSearchModeOption[] hybridSearchModeOptions: HybridSearchModeOption[]
searchMethod: RetrievalSearchMethodEnum searchMethod?: RetrievalSearchMethodEnum
onRetrievalSearchMethodChange: (value: RetrievalSearchMethodEnum) => void onRetrievalSearchMethodChange: (value: RetrievalSearchMethodEnum) => void
hybridSearchMode: HybridSearchModeEnum hybridSearchMode?: HybridSearchModeEnum
onHybridSearchModeChange: (value: HybridSearchModeEnum) => void onHybridSearchModeChange: (value: HybridSearchModeEnum) => void
weightedScore?: WeightedScore weightedScore?: WeightedScore
onWeightedScoreChange: (value: { value: number[] }) => void onWeightedScoreChange: (value: { value: number[] }) => void

View File

@ -1,11 +1,5 @@
import type { NodeDefault } from '../../types' import type { NodeDefault } from '../../types'
import type { KnowledgeBaseNodeType } from './types' import type { KnowledgeBaseNodeType } from './types'
import {
ChunkStructureEnum,
HybridSearchModeEnum,
IndexMethodEnum,
RetrievalSearchMethodEnum,
} from './types'
import { genNodeMetaData } from '@/app/components/workflow/utils' import { genNodeMetaData } from '@/app/components/workflow/utils'
import { BlockEnum } from '@/app/components/workflow/types' import { BlockEnum } from '@/app/components/workflow/types'
@ -17,15 +11,11 @@ const nodeDefault: NodeDefault<KnowledgeBaseNodeType> = {
metaData, metaData,
defaultValue: { defaultValue: {
index_chunk_variable_selector: [], index_chunk_variable_selector: [],
chunk_structure: ChunkStructureEnum.general,
indexing_technique: IndexMethodEnum.QUALIFIED,
keyword_number: 10, keyword_number: 10,
retrieval_model: { retrieval_model: {
search_method: RetrievalSearchMethodEnum.hybrid,
top_k: 2, top_k: 2,
score_threshold_enabled: false, score_threshold_enabled: false,
score_threshold: 0.5, score_threshold: 0.5,
hybridSearchMode: HybridSearchModeEnum.WeightedScore,
}, },
}, },
checkValid() { checkValid() {

View File

@ -75,27 +75,33 @@ const Panel: FC<NodePanelProps<KnowledgeBaseNodeType>> = ({
</Group> </Group>
<BoxGroup> <BoxGroup>
<div className='space-y-3'> <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 && ( data.chunk_structure && (
<EmbeddingModel <>
embeddingModel={data.embedding_model} <IndexMethod
embeddingModelProvider={data.embedding_model_provider} chunkStructure={data.chunk_structure}
onEmbeddingModelChange={handleEmbeddingModelChange} indexMethod={data.indexing_technique}
readonly={nodesReadOnly} 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>
</>
) )
} }
<div className='pt-1'>
<Split className='h-[1px]' />
</div>
<RetrievalSetting <RetrievalSetting
indexMethod={data.indexing_technique} indexMethod={data.indexing_technique}
searchMethod={data.retrieval_model.search_method} searchMethod={data.retrieval_model.search_method}

View File

@ -32,19 +32,19 @@ export type WeightedScore = {
} }
export type RetrievalSetting = { export type RetrievalSetting = {
search_method: RETRIEVE_METHOD search_method?: RETRIEVE_METHOD
reranking_enable?: boolean reranking_enable?: boolean
reranking_model?: RerankingModel reranking_model?: RerankingModel
weights?: WeightedScore weights?: WeightedScore
top_k: number top_k: number
score_threshold_enabled: boolean score_threshold_enabled: boolean
score_threshold: number score_threshold: number
hybridSearchMode: RerankingModeEnum hybridSearchMode?: RerankingModeEnum
} }
export type KnowledgeBaseNodeType = CommonNodeType & { export type KnowledgeBaseNodeType = CommonNodeType & {
index_chunk_variable_selector: string[] index_chunk_variable_selector: string[]
chunk_structure: ChunkStructureEnum chunk_structure?: ChunkStructureEnum
indexing_technique: IndexingType indexing_technique?: IndexingType
embedding_model?: string embedding_model?: string
embedding_model_provider?: string embedding_model_provider?: string
keyword_number: number keyword_number: number

View File

@ -891,6 +891,7 @@ const translation = {
}, },
knowledgeBase: { knowledgeBase: {
chunkStructure: 'Chunk Structure', chunkStructure: 'Chunk Structure',
chooseChunkStructure: 'Choose a chunk structure',
changeChunkStructure: 'Change Chunk Structure', changeChunkStructure: 'Change Chunk Structure',
aboutRetrieval: 'about retrieval method.', aboutRetrieval: 'about retrieval method.',
}, },

View File

@ -892,6 +892,7 @@ const translation = {
}, },
knowledgeBase: { knowledgeBase: {
chunkStructure: '分段结构', chunkStructure: '分段结构',
chooseChunkStructure: '选择分段结构',
changeChunkStructure: '更改分段结构', changeChunkStructure: '更改分段结构',
aboutRetrieval: '关于知识检索。', aboutRetrieval: '关于知识检索。',
}, },