Fix: restrict keywords_similarity_weight [0,1] (#18044)

This commit is contained in:
Wang Qi
2026-08-10 20:01:45 +08:00
committed by GitHub
parent dbd062f65e
commit df32ffbe57
2 changed files with 7 additions and 4 deletions

View File

@@ -32,7 +32,7 @@ export const initialKeywordsSimilarityWeightValue = {
export const similarityThresholdSchema = { similarity_threshold: z.number() };
export const keywordsSimilarityWeightSchema = {
keywords_similarity_weight: z.number(),
keywords_similarity_weight: z.number().min(0).max(1),
};
export const vectorSimilarityWeightSchema = {
@@ -53,7 +53,8 @@ export function SimilaritySliderFormField({
const { t } = useTranslate('knowledgeDetails');
const form = useFormContext();
const isVector = similarityWeightType === 'vector';
const normalizeWeight = (weight: number) => Number(weight.toFixed(2));
const normalizeWeight = (weight: number) =>
Number(Math.min(1, Math.max(0, weight)).toFixed(2));
const getVectorWeight = (weight: number) =>
normalizeWeight(isVector ? weight : 1 - weight);
const getFullTextWeight = (weight: number) =>
@@ -137,7 +138,9 @@ export function SimilaritySliderFormField({
step={0.01}
{...field}
value={getVectorWeight(field.value)}
onChange={(value) => field.onChange(getStoredWeight(value))}
onChange={(value) =>
field.onChange(getStoredWeight(Number(value)))
}
></NumberInput>
</FormControl>
</div>

View File

@@ -44,7 +44,7 @@ import { useValues } from './use-values';
export const RetrievalPartialSchema = {
similarity_threshold: z.coerce.number(),
keywords_similarity_weight: z.coerce.number(),
keywords_similarity_weight: z.coerce.number().min(0).max(1),
top_n: z.coerce.number(),
top_k: z.coerce.number(),
dataset_ids: z.array(z.string()),