Merge branch 'feat/parent-child-retrieval' of https://github.com/langgenius/dify into feat/parent-child-retrieval

pull/12097/head
twwu 1 year ago
commit 12c791149c

@ -75,6 +75,10 @@
cursor: pointer; cursor: pointer;
} }
.disabled {
cursor: not-allowed;
}
.indexItem.disabled:hover { .indexItem.disabled:hover {
background-color: #fcfcfd; background-color: #fcfcfd;
border-color: #f2f4f7; border-color: #f2f4f7;

@ -177,6 +177,8 @@ const StepTwo = ({
setDocForm(value) setDocForm(value)
// eslint-disable-next-line @typescript-eslint/no-use-before-define // eslint-disable-next-line @typescript-eslint/no-use-before-define
currentEstimateMutation.reset() currentEstimateMutation.reset()
if (value === ChuckingMode.parentChild)
setIndexType(IndexingType.QUALIFIED)
} }
const [docLanguage, setDocLanguage] = useState<string>( const [docLanguage, setDocLanguage] = useState<string>(
@ -503,6 +505,9 @@ const StepTwo = ({
} }
const changeToEconomicalType = () => { const changeToEconomicalType = () => {
if (docForm === ChuckingMode.parentChild)
return
if (!hasSetIndexType) { if (!hasSetIndexType) {
setIndexType(IndexingType.ECONOMICAL) setIndexType(IndexingType.ECONOMICAL)
if (docForm === ChuckingMode.qa) if (docForm === ChuckingMode.qa)
@ -555,8 +560,12 @@ const StepTwo = ({
icon={<Image src={SettingCog} alt={t('datasetCreation.stepTwo.general')} />} icon={<Image src={SettingCog} alt={t('datasetCreation.stepTwo.general')} />}
activeHeaderClassName='bg-gradient-to-r from-[#EFF0F9] to-[#F9FAFB]' activeHeaderClassName='bg-gradient-to-r from-[#EFF0F9] to-[#F9FAFB]'
description={t('datasetCreation.stepTwo.generalTip')} description={t('datasetCreation.stepTwo.generalTip')}
isActive={docForm === ChuckingMode.qa || docForm === ChuckingMode.text} isActive={
onSelect={() => handleChangeDocform(ChuckingMode.text)} [ChuckingMode.text, ChuckingMode.qa].includes(docForm)
}
onSwitched={() =>
handleChangeDocform(ChuckingMode.text)
}
actions={ actions={
<> <>
<Button variant={'secondary-accent'} onClick={() => updatePreview()}> <Button variant={'secondary-accent'} onClick={() => updatePreview()}>
@ -651,7 +660,7 @@ const StepTwo = ({
activeHeaderClassName='bg-gradient-to-r from-[#F9F1EE] to-[#F9FAFB]' activeHeaderClassName='bg-gradient-to-r from-[#F9F1EE] to-[#F9FAFB]'
description={t('datasetCreation.stepTwo.parentChildTip')} description={t('datasetCreation.stepTwo.parentChildTip')}
isActive={docForm === ChuckingMode.parentChild} isActive={docForm === ChuckingMode.parentChild}
onSelected={() => handleChangeDocform(ChuckingMode.parentChild)} onSwitched={() => handleChangeDocform(ChuckingMode.parentChild)}
actions={ actions={
<> <>
<Button variant={'secondary-accent'} onClick={() => updatePreview()}> <Button variant={'secondary-accent'} onClick={() => updatePreview()}>
@ -815,6 +824,7 @@ const StepTwo = ({
!hasSetIndexType && indexType === IndexingType.ECONOMICAL && s.active, !hasSetIndexType && indexType === IndexingType.ECONOMICAL && s.active,
hasSetIndexType && s.disabled, hasSetIndexType && s.disabled,
hasSetIndexType && '!w-full !min-h-[96px]', hasSetIndexType && '!w-full !min-h-[96px]',
docForm === ChuckingMode.parentChild && s.disabled,
)} )}
onClick={changeToEconomicalType} onClick={changeToEconomicalType}
> >
@ -919,7 +929,10 @@ const StepTwo = ({
> >
<div className='flex items-center gap-2'> <div className='flex items-center gap-2'>
<DocumentPicker datasetId={datasetId || ''} value={{}} onChange={console.log} /> <DocumentPicker datasetId={datasetId || ''} value={{}} onChange={console.log} />
<Badge text='276 Estimated chunks' /> <Badge text={t(
'datasetCreation.stepTwo.previewChunkCount', {
count: estimate?.preview.length || estimate?.qa_preview?.length || 0,
}) as string} />
</div> </div>
</PreviewHeader>} </PreviewHeader>}
className={cn(s.previewWrap, isMobile && s.isMobile, 'relative h-full overflow-y-scroll')} className={cn(s.previewWrap, isMobile && s.isMobile, 'relative h-full overflow-y-scroll')}
@ -971,7 +984,9 @@ const StepTwo = ({
<div className='h-full w-full flex items-center justify-center'> <div className='h-full w-full flex items-center justify-center'>
<div className='flex flex-col items-center justify-center gap-3'> <div className='flex flex-col items-center justify-center gap-3'>
<RiSearchEyeLine className='size-10 text-text-empty-state-icon' /> <RiSearchEyeLine className='size-10 text-text-empty-state-icon' />
<p className='text-sm text-text-tertiary'>{'Click the \'Preview Chunk\' button on the left to load the preview'}</p> <p className='text-sm text-text-tertiary'>
{t('datasetCreation.stepTwo.previewChunkTip')}
</p>
</div> </div>
</div> </div>
)} )}

@ -22,7 +22,7 @@ type OptionCardHeaderProps = {
export const OptionCardHeader: FC<OptionCardHeaderProps> = (props) => { export const OptionCardHeader: FC<OptionCardHeaderProps> = (props) => {
const { icon, title, description, isActive, activeClassName, effectImg } = props const { icon, title, description, isActive, activeClassName, effectImg } = props
return <div className={classNames( return <div className={classNames(
'flex h-full overflow-hidden rounded-xl relative', 'flex h-full overflow-hidden rounded-t-xl relative',
isActive && activeClassName, isActive && activeClassName,
)}> )}>
<div className='size-14 flex items-center justify-center relative overflow-hidden'> <div className='size-14 flex items-center justify-center relative overflow-hidden'>
@ -50,11 +50,11 @@ type OptionCardProps = {
isActive?: boolean isActive?: boolean
actions?: ReactNode actions?: ReactNode
effectImg?: string effectImg?: string
onSelected?: () => void onSwitched?: () => void
} & Omit<ComponentProps<'div'>, 'title'> } & Omit<ComponentProps<'div'>, 'title'>
export const OptionCard: FC<OptionCardProps> = (props) => { export const OptionCard: FC<OptionCardProps> = (props) => {
const { icon, className, title, description, isActive, children, actions, activeHeaderClassName, style, effectImg, onSelected, onClick, ...rest } = props const { icon, className, title, description, isActive, children, actions, activeHeaderClassName, style, effectImg, onSwitched, onClick, ...rest } = props
return <div return <div
className={classNames( className={classNames(
'rounded-xl', 'rounded-xl',
@ -67,7 +67,7 @@ export const OptionCard: FC<OptionCardProps> = (props) => {
}} }}
onClick={(e) => { onClick={(e) => {
if (!isActive) if (!isActive)
onSelected?.() onSwitched?.()
onClick?.(e) onClick?.(e)
}} }}
{...rest}> {...rest}>

@ -164,6 +164,8 @@ const translation = {
indexSettingTip: 'To change the index method & embedding model, please go to the ', indexSettingTip: 'To change the index method & embedding model, please go to the ',
retrievalSettingTip: 'To change the retrieval setting, please go to the ', retrievalSettingTip: 'To change the retrieval setting, please go to the ',
datasetSettingLink: 'Knowledge settings.', datasetSettingLink: 'Knowledge settings.',
previewChunkTip: 'Click the \'Preview Chunk\' button on the left to load the preview',
previewChunkCount: '{{count}} Estimated chunks',
}, },
stepThree: { stepThree: {
creationTitle: '🎉 Knowledge created', creationTitle: '🎉 Knowledge created',

@ -164,6 +164,8 @@ const translation = {
indexSettingTip: '要更改索引方法和 embedding 模型,请转到', indexSettingTip: '要更改索引方法和 embedding 模型,请转到',
retrievalSettingTip: '要更改检索方法,请转到', retrievalSettingTip: '要更改检索方法,请转到',
datasetSettingLink: '知识库设置。', datasetSettingLink: '知识库设置。',
previewChunkTip: '点击左侧的“预览块”按钮来加载预览',
previewChunkCount: '{{count}} 预估块',
}, },
stepThree: { stepThree: {
creationTitle: '🎉 知识库已创建', creationTitle: '🎉 知识库已创建',

@ -35,7 +35,7 @@ const toBatchDocumentsIdParams = (documentIds: string[] | string) => {
export const useDocumentBatchAction = (action: DocumentActionType) => { export const useDocumentBatchAction = (action: DocumentActionType) => {
return useMutation({ return useMutation({
mutationFn: ({ datasetId, documentIds, documentId }: UpdateDocumentBatchParams) => { mutationFn: ({ datasetId, documentIds, documentId }: UpdateDocumentBatchParams) => {
return patch<CommonResponse>(`/datasets/${datasetId}/documents/status/${action}?${toBatchDocumentsIdParams(documentId || documentIds!)}`) return patch<CommonResponse>(`/datasets/${datasetId}/documents/status/${action}/batch?${toBatchDocumentsIdParams(documentId || documentIds!)}`)
}, },
}) })
} }
@ -59,7 +59,7 @@ export const useDocumentUnArchive = () => {
export const useDocumentDelete = () => { export const useDocumentDelete = () => {
return useMutation({ return useMutation({
mutationFn: ({ datasetId, documentIds, documentId }: UpdateDocumentBatchParams) => { mutationFn: ({ datasetId, documentIds, documentId }: UpdateDocumentBatchParams) => {
return del<CommonResponse>(`/datasets/${datasetId}/documents?${toBatchDocumentsIdParams(documentId || documentIds!)}`) return del<CommonResponse>(`/datasets/${datasetId}/documents/batch?${toBatchDocumentsIdParams(documentId || documentIds!)}`)
}, },
}) })
} }

Loading…
Cancel
Save