From c5d1139f7b42be829e8240e690a910d11221ad49 Mon Sep 17 00:00:00 2001 From: chanx <1243304602@qq.com> Date: Tue, 28 Oct 2025 19:17:05 +0800 Subject: [PATCH] Fix: Refactor the similarity slider component and modify the style of the dataset-test page #10703 (#10846) ### What problem does this PR solve? Fix: Refactor the similarity slider component and modify the style of the dataset-test page ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- .../components/similarity-slider/index.tsx | 101 +++++++++++++++--- .../components/slider-input-form-field.tsx | 5 +- web/src/components/top-n-item.tsx | 2 + web/src/components/ui/dual-range-slider.tsx | 4 +- web/src/locales/en.ts | 2 +- web/src/locales/zh.ts | 2 +- .../pages/dataset/testing/testing-form.tsx | 8 +- web/src/pages/next-search/search-setting.tsx | 86 ++------------- 8 files changed, 105 insertions(+), 105 deletions(-) diff --git a/web/src/components/similarity-slider/index.tsx b/web/src/components/similarity-slider/index.tsx index 796d2415e..05a7f29ce 100644 --- a/web/src/components/similarity-slider/index.tsx +++ b/web/src/components/similarity-slider/index.tsx @@ -1,7 +1,19 @@ +import { FormLayout } from '@/constants/form'; import { useTranslate } from '@/hooks/common-hooks'; +import { cn } from '@/lib/utils'; import { Form, Slider } from 'antd'; +import { useFormContext } from 'react-hook-form'; import { z } from 'zod'; import { SliderInputFormField } from '../slider-input-form-field'; +import { SingleFormSlider } from '../ui/dual-range-slider'; +import { + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from '../ui/form'; +import { NumberInput } from '../ui/input'; type FieldType = { similarity_threshold?: number; @@ -44,6 +56,7 @@ const SimilaritySlider = ({ export default SimilaritySlider; interface SimilaritySliderFormFieldProps { + similarityName?: string; vectorSimilarityWeightName?: string; isTooltipShown?: boolean; } @@ -70,37 +83,93 @@ export const initialVectorSimilarityWeightValue = { }; export function SimilaritySliderFormField({ + similarityName = 'similarity_threshold', vectorSimilarityWeightName = 'vector_similarity_weight', isTooltipShown, }: SimilaritySliderFormFieldProps) { const { t } = useTranslate('knowledgeDetails'); - const isVector = vectorSimilarityWeightName === 'vector_similarity_weight'; + const form = useFormContext(); + const isVector = + vectorSimilarityWeightName.indexOf('vector_similarity_weight') > -1; return ( <> - ( + + + {t( + isVector ? 'vectorSimilarityWeight' : 'keywordSimilarityWeight', + )} + + + + + + + + vector + + + {field.value.toFixed(2)} + + + + + full-text + + + {(1 - field.value).toFixed(2)} + + + + + + + + + + + + )} - max={1} - step={0.01} - tooltip={ - isTooltipShown && - t( - isVector - ? 'vectorSimilarityWeightTip' - : 'keywordSimilarityWeightTip', - ) - } - > + /> > ); } diff --git a/web/src/components/slider-input-form-field.tsx b/web/src/components/slider-input-form-field.tsx index 8972222a8..40b2c6804 100644 --- a/web/src/components/slider-input-form-field.tsx +++ b/web/src/components/slider-input-form-field.tsx @@ -79,7 +79,10 @@ export function SliderInputFormField({ ); } diff --git a/web/src/components/ui/dual-range-slider.tsx b/web/src/components/ui/dual-range-slider.tsx index e2fbb303c..88210920a 100644 --- a/web/src/components/ui/dual-range-slider.tsx +++ b/web/src/components/ui/dual-range-slider.tsx @@ -28,12 +28,12 @@ const DualRangeSlider = React.forwardRef< )} {...props} > - + {initialValue.map((value, index) => ( - + {label && ( ( - {t('knowledgeDetails.testText')} + {/* {t('knowledgeDetails.testText')} */} @@ -112,8 +111,9 @@ export default function TestingForm({ disabled={!!!trim(question)} loading={loading} > - {!loading && } + {/* {!loading && } */} {t('knowledgeDetails.testingLabel')} + diff --git a/web/src/pages/next-search/search-setting.tsx b/web/src/pages/next-search/search-setting.tsx index 8a9e136cb..665d7e49b 100644 --- a/web/src/pages/next-search/search-setting.tsx +++ b/web/src/pages/next-search/search-setting.tsx @@ -5,6 +5,7 @@ import { MetadataFilter, MetadataFilterSchema, } from '@/components/metadata-filter'; +import { SimilaritySliderFormField } from '@/components/similarity-slider'; import { Button } from '@/components/ui/button'; import { SingleFormSlider } from '@/components/ui/dual-range-slider'; import { @@ -392,86 +393,11 @@ const SearchSetting: React.FC = ({ )} /> - ( - - - {t('knowledgeDetails.similarityThreshold')} - - - - - - - - - - - - )} - /> - {/* Keyword Similarity Weight */} - ( - - - * - {t('knowledgeDetails.vectorSimilarityWeight')} - - - - - - - - - - - - )} - /> + {/* Rerank Model */}