File size: 4,147 Bytes
4304c6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
'use client'
import type { FC } from 'react'
import React from 'react'
import { useTranslation } from 'react-i18next'
import RetrievalParamConfig from '../retrieval-param-config'
import type { RetrievalConfig } from '@/types/app'
import { RETRIEVE_METHOD } from '@/types/app'
import RadioCard from '@/app/components/base/radio-card'
import { PatternRecognition, Semantic } from '@/app/components/base/icons/src/vender/solid/development'
import { FileSearch02 } from '@/app/components/base/icons/src/vender/solid/files'
import { useProviderContext } from '@/context/provider-context'
import { useDefaultModel } from '@/app/components/header/account-setting/model-provider-page/hooks'
import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'

type Props = {
  value: RetrievalConfig
  onChange: (value: RetrievalConfig) => void
}

const RetrievalMethodConfig: FC<Props> = ({

  value: passValue,

  onChange,

}) => {
  const { t } = useTranslation()
  const { supportRetrievalMethods } = useProviderContext()
  const { data: rerankDefaultModel } = useDefaultModel(ModelTypeEnum.rerank)
  const value = (() => {
    if (!passValue.reranking_model.reranking_model_name) {
      return {
        ...passValue,
        reranking_model: {
          reranking_provider_name: rerankDefaultModel?.provider.provider || '',
          reranking_model_name: rerankDefaultModel?.model || '',
        },
      }
    }
    return passValue
  })()
  return (
    <div className='space-y-2'>

      {supportRetrievalMethods.includes(RETRIEVE_METHOD.semantic) && (

        <RadioCard

          icon={<Semantic className='w-4 h-4 text-[#7839EE]' />}

          title={t('dataset.retrieval.semantic_search.title')}

          description={t('dataset.retrieval.semantic_search.description')}

          isChosen={value.search_method === RETRIEVE_METHOD.semantic}

          onChosen={() => onChange({

            ...value,

            search_method: RETRIEVE_METHOD.semantic,

          })}

          chosenConfig={

            <RetrievalParamConfig

              type={RETRIEVE_METHOD.semantic}

              value={value}

              onChange={onChange}

            />

          }

        />

      )}

      {supportRetrievalMethods.includes(RETRIEVE_METHOD.semantic) && (

        <RadioCard

          icon={<FileSearch02 className='w-4 h-4 text-[#7839EE]' />}

          title={t('dataset.retrieval.full_text_search.title')}

          description={t('dataset.retrieval.full_text_search.description')}

          isChosen={value.search_method === RETRIEVE_METHOD.fullText}

          onChosen={() => onChange({

            ...value,

            search_method: RETRIEVE_METHOD.fullText,

          })}

          chosenConfig={

            <RetrievalParamConfig

              type={RETRIEVE_METHOD.fullText}

              value={value}

              onChange={onChange}

            />

          }

        />

      )}

      {supportRetrievalMethods.includes(RETRIEVE_METHOD.semantic) && (

        <RadioCard

          icon={<PatternRecognition className='w-4 h-4 text-[#7839EE]' />}

          title={

            <div className='flex items-center space-x-1'>

              <div>{t('dataset.retrieval.hybrid_search.title')}</div>

              <div className='flex h-full items-center px-1.5 rounded-md border border-[#E0EAFF] text-xs font-medium text-[#444CE7]'>{t('dataset.retrieval.hybrid_search.recommend')}</div>

            </div>

          }

          description={t('dataset.retrieval.hybrid_search.description')}

          isChosen={value.search_method === RETRIEVE_METHOD.hybrid}

          onChosen={() => onChange({

            ...value,

            search_method: RETRIEVE_METHOD.hybrid,

            reranking_enable: true,

          })}

          chosenConfig={

            <RetrievalParamConfig

              type={RETRIEVE_METHOD.hybrid}

              value={value}

              onChange={onChange}

            />

          }

        />

      )}

    </div>
  )
}
export default React.memo(RetrievalMethodConfig)