"use client"; import { FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { useWatch, type UseFormReturn } from "react-hook-form"; import { useI18n } from "@/i18n/i18n-context"; import type { CreateKBInput } from "@/schemas/knowledge-base"; interface EmbeddingConfigFormProps { form: UseFormReturn; } const V3_DIMENSIONS = [1024, 768, 512, 256, 128, 64]; const V4_DIMENSIONS = [2048, 1536, 1024, 768, 512, 256, 128, 64]; // qwen3-vl-embedding 是多模态模型,支持的维度集合与 text-embedding-v3/v4 不同。 // 维度列表与 1024 默认值需保持与模型文档一致。 const QWEN3_VL_DIMENSIONS = [2560, 2048, 1536, 1024, 768, 512, 256]; // 模型 → 维度列表的映射。未来新增模型在此处补一行即可,无需修改下方组件逻辑。 const DIMENSION_MAP: Record = { "text-embedding-v3": V3_DIMENSIONS, "text-embedding-v4": V4_DIMENSIONS, "qwen3-vl-embedding": QWEN3_VL_DIMENSIONS, }; export function EmbeddingConfigForm({ form }: EmbeddingConfigFormProps) { const { t } = useI18n(); const provider = useWatch({ control: form.control, name: "embeddingConfiguration.provider", }); const model = useWatch({ control: form.control, name: "embeddingConfiguration.model", }); // 未识别的模型回落到 V4(与历史行为兼容)。 const dimensionOptions = DIMENSION_MAP[model ?? ""] ?? V4_DIMENSIONS; const handleModelChange = (newModel: string) => { form.setValue("embeddingConfiguration.model", newModel); // Auto-set default dimension based on model. 1024 在所有当前模型中都是合法维度。 form.setValue("embeddingConfiguration.dimension", 1024); }; return (
( {t("knowledgeBase.provider.label")} )} /> ( {t("knowledgeBase.provider.modelName")} {provider === "bailian" ? ( ) : ( )} )} /> ( {t("knowledgeBase.embedding.dimension")} {provider === "bailian" ? ( ) : ( field.onChange(Number(event.target.value)) } /> )} )} /> {provider === "custom" && ( <> ( API Key )} /> ( API URL )} /> )}
); }