mirror of
https://github.com/langgenius/dify.git
synced 2025-09-03 14:23:48 +00:00
knowledge base default data
This commit is contained in:
parent
29d2f2339b
commit
b9214ca76b
@ -1,13 +1,15 @@
|
||||
import { memo } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { RiAddLine } from '@remixicon/react'
|
||||
import { Field } from '@/app/components/workflow/nodes/_base/components/layout'
|
||||
import type { ChunkStructureEnum } from '../../types'
|
||||
import OptionCard from '../option-card'
|
||||
import Selector from './selector'
|
||||
import { useChunkStructure } from './hooks'
|
||||
import Button from '@/app/components/base/button'
|
||||
|
||||
type ChunkStructureProps = {
|
||||
chunkStructure: ChunkStructureEnum
|
||||
chunkStructure?: ChunkStructureEnum
|
||||
onChunkStructureChange: (value: ChunkStructureEnum) => void
|
||||
readonly?: boolean
|
||||
}
|
||||
@ -27,7 +29,7 @@ const ChunkStructure = ({
|
||||
fieldTitleProps={{
|
||||
title: t('workflow.nodes.knowledgeBase.chunkStructure'),
|
||||
tooltip: t('workflow.nodes.knowledgeBase.chunkStructure'),
|
||||
operation: (
|
||||
operation: chunkStructure && (
|
||||
<Selector
|
||||
options={options}
|
||||
value={chunkStructure}
|
||||
@ -37,12 +39,34 @@ const ChunkStructure = ({
|
||||
),
|
||||
}}
|
||||
>
|
||||
<OptionCard
|
||||
{...optionMap[chunkStructure]}
|
||||
selectedId={chunkStructure}
|
||||
enableSelect={false}
|
||||
enableHighlightBorder={false}
|
||||
/>
|
||||
{
|
||||
chunkStructure && (
|
||||
<OptionCard
|
||||
{...optionMap[chunkStructure]}
|
||||
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>
|
||||
)
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import type { ReactNode } from 'react'
|
||||
import { useCallback, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import {
|
||||
@ -12,15 +13,17 @@ import type { Option } from './type'
|
||||
|
||||
type SelectorProps = {
|
||||
options: Option[]
|
||||
value: ChunkStructureEnum
|
||||
value?: ChunkStructureEnum
|
||||
onChange: (key: ChunkStructureEnum) => void
|
||||
readonly?: boolean
|
||||
trigger?: ReactNode
|
||||
}
|
||||
const Selector = ({
|
||||
options,
|
||||
value,
|
||||
onChange,
|
||||
readonly,
|
||||
trigger,
|
||||
}: SelectorProps) => {
|
||||
const { t } = useTranslation()
|
||||
const [open, setOpen] = useState(false)
|
||||
@ -40,17 +43,24 @@ const Selector = ({
|
||||
open={open}
|
||||
onOpenChange={setOpen}
|
||||
>
|
||||
<PortalToFollowElemTrigger onClick={() => {
|
||||
if (readonly)
|
||||
return
|
||||
setOpen(!open)
|
||||
}}>
|
||||
<Button
|
||||
size='small'
|
||||
variant='ghost-accent'
|
||||
>
|
||||
{t('workflow.panel.change')}
|
||||
</Button>
|
||||
<PortalToFollowElemTrigger
|
||||
asChild
|
||||
onClick={() => {
|
||||
if (readonly)
|
||||
return
|
||||
setOpen(!open)
|
||||
}}
|
||||
>
|
||||
{
|
||||
trigger || (
|
||||
<Button
|
||||
size='small'
|
||||
variant='ghost-accent'
|
||||
>
|
||||
{t('workflow.panel.change')}
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
</PortalToFollowElemTrigger>
|
||||
<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]'>
|
||||
|
@ -21,7 +21,7 @@ import {
|
||||
|
||||
type IndexMethodProps = {
|
||||
chunkStructure: ChunkStructureEnum
|
||||
indexMethod: IndexMethodEnum
|
||||
indexMethod?: IndexMethodEnum
|
||||
onIndexMethodChange: (value: IndexMethodEnum) => void
|
||||
keywordNumber: number
|
||||
onKeywordNumberChange: (value: number) => void
|
||||
|
@ -15,7 +15,7 @@ import type {
|
||||
Option,
|
||||
} from './type'
|
||||
|
||||
export const useRetrievalSetting = (indexMethod: IndexMethodEnum) => {
|
||||
export const useRetrievalSetting = (indexMethod?: IndexMethodEnum) => {
|
||||
const { t } = useTranslation()
|
||||
const VectorSearchOption: Option = useMemo(() => {
|
||||
return {
|
||||
|
@ -17,11 +17,11 @@ import type { RerankingModelSelectorProps } from './reranking-model-selector'
|
||||
import SearchMethodOption from './search-method-option'
|
||||
|
||||
type RetrievalSettingProps = {
|
||||
indexMethod: IndexMethodEnum
|
||||
indexMethod?: IndexMethodEnum
|
||||
readonly?: boolean
|
||||
searchMethod: RetrievalSearchMethodEnum
|
||||
searchMethod?: RetrievalSearchMethodEnum
|
||||
onRetrievalSearchMethodChange: (value: RetrievalSearchMethodEnum) => void
|
||||
hybridSearchMode: HybridSearchModeEnum
|
||||
hybridSearchMode?: HybridSearchModeEnum
|
||||
onHybridSearchModeChange: (value: HybridSearchModeEnum) => void
|
||||
rerankingModelEnabled?: boolean
|
||||
onRerankingModelEnabledChange?: (value: boolean) => void
|
||||
|
@ -30,9 +30,9 @@ type SearchMethodOptionProps = {
|
||||
readonly?: boolean
|
||||
option: Option
|
||||
hybridSearchModeOptions: HybridSearchModeOption[]
|
||||
searchMethod: RetrievalSearchMethodEnum
|
||||
searchMethod?: RetrievalSearchMethodEnum
|
||||
onRetrievalSearchMethodChange: (value: RetrievalSearchMethodEnum) => void
|
||||
hybridSearchMode: HybridSearchModeEnum
|
||||
hybridSearchMode?: HybridSearchModeEnum
|
||||
onHybridSearchModeChange: (value: HybridSearchModeEnum) => void
|
||||
weightedScore?: WeightedScore
|
||||
onWeightedScoreChange: (value: { value: number[] }) => void
|
||||
|
@ -1,11 +1,5 @@
|
||||
import type { NodeDefault } from '../../types'
|
||||
import type { KnowledgeBaseNodeType } from './types'
|
||||
import {
|
||||
ChunkStructureEnum,
|
||||
HybridSearchModeEnum,
|
||||
IndexMethodEnum,
|
||||
RetrievalSearchMethodEnum,
|
||||
} from './types'
|
||||
import { genNodeMetaData } from '@/app/components/workflow/utils'
|
||||
import { BlockEnum } from '@/app/components/workflow/types'
|
||||
|
||||
@ -17,15 +11,11 @@ const nodeDefault: NodeDefault<KnowledgeBaseNodeType> = {
|
||||
metaData,
|
||||
defaultValue: {
|
||||
index_chunk_variable_selector: [],
|
||||
chunk_structure: ChunkStructureEnum.general,
|
||||
indexing_technique: IndexMethodEnum.QUALIFIED,
|
||||
keyword_number: 10,
|
||||
retrieval_model: {
|
||||
search_method: RetrievalSearchMethodEnum.hybrid,
|
||||
top_k: 2,
|
||||
score_threshold_enabled: false,
|
||||
score_threshold: 0.5,
|
||||
hybridSearchMode: HybridSearchModeEnum.WeightedScore,
|
||||
},
|
||||
},
|
||||
checkValid() {
|
||||
|
@ -75,27 +75,33 @@ const Panel: FC<NodePanelProps<KnowledgeBaseNodeType>> = ({
|
||||
</Group>
|
||||
<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}
|
||||
/>
|
||||
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>
|
||||
</>
|
||||
)
|
||||
}
|
||||
<div className='pt-1'>
|
||||
<Split className='h-[1px]' />
|
||||
</div>
|
||||
<RetrievalSetting
|
||||
indexMethod={data.indexing_technique}
|
||||
searchMethod={data.retrieval_model.search_method}
|
||||
|
@ -32,19 +32,19 @@ export type WeightedScore = {
|
||||
}
|
||||
|
||||
export type RetrievalSetting = {
|
||||
search_method: RETRIEVE_METHOD
|
||||
search_method?: RETRIEVE_METHOD
|
||||
reranking_enable?: boolean
|
||||
reranking_model?: RerankingModel
|
||||
weights?: WeightedScore
|
||||
top_k: number
|
||||
score_threshold_enabled: boolean
|
||||
score_threshold: number
|
||||
hybridSearchMode: RerankingModeEnum
|
||||
hybridSearchMode?: RerankingModeEnum
|
||||
}
|
||||
export type KnowledgeBaseNodeType = CommonNodeType & {
|
||||
index_chunk_variable_selector: string[]
|
||||
chunk_structure: ChunkStructureEnum
|
||||
indexing_technique: IndexingType
|
||||
chunk_structure?: ChunkStructureEnum
|
||||
indexing_technique?: IndexingType
|
||||
embedding_model?: string
|
||||
embedding_model_provider?: string
|
||||
keyword_number: number
|
||||
|
@ -891,6 +891,7 @@ const translation = {
|
||||
},
|
||||
knowledgeBase: {
|
||||
chunkStructure: 'Chunk Structure',
|
||||
chooseChunkStructure: 'Choose a chunk structure',
|
||||
changeChunkStructure: 'Change Chunk Structure',
|
||||
aboutRetrieval: 'about retrieval method.',
|
||||
},
|
||||
|
@ -892,6 +892,7 @@ const translation = {
|
||||
},
|
||||
knowledgeBase: {
|
||||
chunkStructure: '分段结构',
|
||||
chooseChunkStructure: '选择分段结构',
|
||||
changeChunkStructure: '更改分段结构',
|
||||
aboutRetrieval: '关于知识检索。',
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user