dify/web/app/components/datasets/external-knowledge-base/create/RetrievalSettings.tsx
Wu Tianwei 33edf97f81
feat: RBAC (#37107)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: fatelei <fatelei@gmail.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: 盐粒 Yanli <yanli@dify.ai>
Co-authored-by: Charles Yao <chongbinyao33@gmail.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: yunlu.wen <yunlu.wen@dify.ai>
Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
Co-authored-by: Jingyi <jingyi.qi@dify.ai>
Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
Co-authored-by: Joel <iamjoel007@gmail.com>
Co-authored-by: hjlarry <hjlarry@163.com>
Co-authored-by: Asuka Minato <i@asukaminato.eu.org>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Xiyuan Chen <52963600+GareArc@users.noreply.github.com>
Co-authored-by: gigglewang <gigglewang@dify.ai>
Co-authored-by: chariri <w@chariri.moe>
Co-authored-by: Evan <2869018789@qq.com>
Co-authored-by: zyssyz123 <916125788@qq.com>
2026-06-18 16:35:29 +00:00

75 lines
2.3 KiB
TypeScript

import type { FC } from 'react'
import { cn } from '@langgenius/dify-ui/cn'
import * as React from 'react'
import { useTranslation } from 'react-i18next'
import ScoreThresholdItem from '@/app/components/base/param-item/score-threshold-item'
import TopKItem from '@/app/components/base/param-item/top-k-item'
type RetrievalSettingsProps = {
topK: number
scoreThreshold: number
scoreThresholdEnabled: boolean
isInHitTesting?: boolean
isInRetrievalSetting?: boolean
readonly?: boolean
onChange: (data: { top_k?: number, score_threshold?: number, score_threshold_enabled?: boolean }) => void
}
const RetrievalSettings: FC<RetrievalSettingsProps> = ({
topK,
scoreThreshold,
scoreThresholdEnabled,
onChange,
isInHitTesting = false,
isInRetrievalSetting = false,
readonly = false,
}) => {
const { t } = useTranslation()
const handleScoreThresholdChange = (enabled: boolean) => {
onChange({ score_threshold_enabled: enabled })
}
return (
<div className={cn('flex flex-col gap-2 self-stretch', isInRetrievalSetting && 'w-full max-w-[480px]')}>
{!isInHitTesting && !isInRetrievalSetting && (
<div className="flex h-7 flex-col gap-2 self-stretch pt-1">
<label className="system-sm-semibold text-text-secondary">{t('retrievalSettings', { ns: 'dataset' })}</label>
</div>
)}
<div className={cn(
'flex gap-4 self-stretch',
{
'flex-col': isInHitTesting,
'flex-row': isInRetrievalSetting,
'flex-col sm:flex-row': !isInHitTesting && !isInRetrievalSetting,
},
)}
>
<div className="flex grow flex-col gap-1">
<TopKItem
className="grow"
value={topK}
onChange={(_key, v) => onChange({ top_k: v })}
enable={true}
disabled={readonly}
/>
</div>
<div className="flex grow flex-col gap-1">
<ScoreThresholdItem
className="grow"
value={scoreThreshold}
onChange={(_key, v) => onChange({ score_threshold: v })}
enable={scoreThresholdEnabled}
hasSwitch={true}
onSwitchChange={(_key, v) => handleScoreThresholdChange(v)}
disabled={readonly}
/>
</div>
</div>
</div>
)
}
export default RetrievalSettings