Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

refactor(lightrag): clarify role model controls

NoxsMedia4dd9254c0f1d
diff --git a/web/components/knowledge/CreateKbModal.tsx b/web/components/knowledge/CreateKbModal.tsx
index c94cc41b7..fe978a3a4 100644
--- a/web/components/knowledge/CreateKbModal.tsx
+++ b/web/components/knowledge/CreateKbModal.tsx
@@ -184,6 +184,34 @@ export default function CreateKbModal({
active: linkIsIma,
});
const llmCatalog = useLLMOptions(getLightRagModelOptions);
+ const lightRagIndexingDefaults = lightRagConfig
+ ? indexingSelectionFromDefaults(
+ llmCatalog.options,
+ lightRagConfig,
+ llmCatalog.activeDefault,
+ )
+ : null;
+ const lightRagModelName = (value?: {
+ profile_id: string;
+ model_id: string;
+ }) =>
+ llmCatalog.options.find(
+ (option) =>
+ option.profile_id === value?.profile_id &&
+ option.model_id === value?.model_id,
+ )?.model_name ?? value?.model_id;
+ const visibleEngineDefaultSummary =
+ provider === "lightrag" && lightRagIndexingDefaults
+ ? [
+ ...engineDefaultSummary,
+ `EXTRACT: ${lightRagModelName(lightRagIndexingDefaults.extract)}`,
+ `VLM: ${
+ lightRagIndexingDefaults.vlm.mode === "enabled"
+ ? lightRagModelName(lightRagIndexingDefaults.vlm.selection)
+ : t("Image analysis disabled")
+ }`,
+ ]
+ : engineDefaultSummary;
const firstLinkable = providers.find((p) => p.linkable)?.id;
@@ -299,7 +327,7 @@ export default function CreateKbModal({
summary = [
`${t("Results per query")}: ${config.top_k}`,
`${t("Files in parallel")}: ${config.max_concurrent_files}`,
- `${t("Concurrent LLM calls")}: ${config.llm_model_max_async}`,
+ `${t("Extra extraction passes")}: ${config.entity_extract_max_gleaning}`,
];
} else if (provider === "pageindex") {
const config = await getPageIndexConfig();
@@ -605,7 +633,7 @@ export default function CreateKbModal({
providerNeedsKey={providerNeedsKey}
onConfigureProvider={onConfigureProvider}
activeProvider={activeProvider}
- engineDefaultSummary={engineDefaultSummary}
+ engineDefaultSummary={visibleEngineDefaultSummary}
modeOptions={modeOptions}
retrievalMode={retrievalMode}
setRetrievalMode={setRetrievalMode}
@@ -621,6 +649,8 @@ export default function CreateKbModal({
<LightRagIndexingSelector
options={llmCatalog.options}
selection={indexingLLM}
+ defaults={lightRagIndexingDefaults}
+ collapsible
loading={llmCatalog.loading}
error={llmCatalog.error}
defaultUnavailable={
@@ -956,9 +986,7 @@ function NewModeFields({
)}
{indexingModelField && (
- <div className="rounded-xl border border-[var(--border)] bg-[var(--muted)]/20 p-3">
- {indexingModelField}
- </div>
+ <div>{indexingModelField}</div>
)}
{modeOptions.length > 0 && (
diff --git a/web/components/knowledge/IndexingModelSelector.tsx b/web/components/knowledge/IndexingModelSelector.tsx
index c73ec0ec6..9be433f3d 100644
--- a/web/components/knowledge/IndexingModelSelector.tsx
+++ b/web/components/knowledge/IndexingModelSelector.tsx
@@ -60,7 +60,11 @@ export function selectionFromLightRagDefault(
interface IndexingModelSelectorProps {
label?: string;
+ labelClassName?: string;
+ defaultSelection?: IndexingLLMSelection | null;
+ defaultLabel?: string;
lockModel?: boolean;
+ reasoningOnly?: boolean;
inheritBaseReasoning?: string | null;
options: LLMOption[];
selection: IndexingLLMSelection | null;
@@ -74,7 +78,11 @@ interface IndexingModelSelectorProps {
export default function IndexingModelSelector({
label = "Indexing model",
+ labelClassName = "text-[11px] font-medium uppercase tracking-wide text-[var(--muted-foreground)]",
+ defaultSelection,
+ defaultLabel,
lockModel = false,
+ reasoningOnly = false,
inheritBaseReasoning,
options,
selection,
@@ -91,6 +99,13 @@ export default function IndexingModelSelector({
option.profile_id === selection?.profile_id &&
option.model_id === selection?.model_id,
);
+ const usesDefault = Boolean(
+ defaultSelection &&
+ selection?.profile_id === defaultSelection.profile_id &&
+ selection?.model_id === defaultSelection.model_id &&
+ (selection.reasoning_effort ?? "") ===
+ (defaultSelection.reasoning_effort ?? ""),
+ );
const reasoningOptions = (
selected
? selected.supported_reasoning_efforts !== undefined
@@ -134,14 +149,24 @@ export default function IndexingModelSelector({
return (
<div className="space-y-3">
- <label className="block">
- <span className="mb-1.5 block text-[11px] font-medium uppercase tracking-wide text-[var(--muted-foreground)]">
+ {!reasoningOnly && <label className="block">
+ <span className={`mb-1.5 block ${labelClassName}`}>
{t(label)}
</span>
<select
- value={selected ? `${selected.profile_id}:${selected.model_id}` : ""}
+ value={
+ usesDefault
+ ? "__engine_default__"
+ : selected
+ ? `${selected.profile_id}:${selected.model_id}`
+ : ""
+ }
disabled={disabled || lockModel}
onChange={(event) => {
+ if (event.target.value === "__engine_default__") {
+ onChange(defaultSelection ?? null);
+ return;
+ }
const option = options.find(
(item) =>
`${item.profile_id}:${item.model_id}` === event.target.value,
@@ -153,6 +178,9 @@ export default function IndexingModelSelector({
<option value="" disabled>
{t("Select an indexing model")}
</option>
+ {defaultSelection && defaultLabel && (
+ <option value="__engine_default__">{defaultLabel}</option>
+ )}
{options.map((option) => (
<option
key={`${option.profile_id}:${option.model_id}`}
@@ -164,16 +192,16 @@ export default function IndexingModelSelector({
</option>
))}
</select>
- </label>
+ </label>}
- {defaultUnavailable && !selection && (
+ {!reasoningOnly && defaultUnavailable && !selection && (
<div className="rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-[12px] text-amber-700 dark:border-amber-900 dark:bg-amber-950/30 dark:text-amber-300">
{t(
"The current LightRAG query model is unavailable here. Choose an accessible indexing model.",
)}
</div>
)}
- {defaultLoadError && !selection && (
+ {!reasoningOnly && defaultLoadError && !selection && (
<div className="rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-[12px] text-red-700 dark:border-red-900 dark:bg-red-950/30 dark:text-red-300">
{t(
"The LightRAG query-model setting could not be loaded. Choose an indexing model or try again.",
diff --git a/web/components/knowledge/LightRagIndexingSelector.tsx b/web/components/knowledge/LightRagIndexingSelector.tsx
index c2d9d26a6..6f4493ab9 100644
--- a/web/components/knowledge/LightRagIndexingSelector.tsx
+++ b/web/components/knowledge/LightRagIndexingSelector.tsx
@@ -86,11 +86,15 @@ export function isCompleteIndexingSelection(
export default function LightRagIndexingSelector({
options,
selection,
+ defaults,
+ collapsible = false,
onChange,
...state
}: {
options: LLMOption[];
selection: LightRagIndexingSelection | null;
+ defaults?: LightRagIndexingSelection | null;
+ collapsible?: boolean;
onChange: (value: LightRagIndexingSelection | null) => void;
loading: boolean;
error: boolean;
@@ -99,16 +103,74 @@ export default function LightRagIndexingSelector({
disabled?: boolean;
}) {
const { t } = useTranslation();
- return (
+ const optionFor = (value?: { profile_id: string; model_id: string }) =>
+ options.find(
+ (option) =>
+ option.profile_id === value?.profile_id &&
+ option.model_id === value?.model_id,
+ );
+ const optionName = (value?: { profile_id: string; model_id: string }) => {
+ const option = optionFor(value);
+ return option?.model_name ?? value?.model_id ?? t("Not selected");
+ };
+ const optionLabel = (value?: { profile_id: string; model_id: string }) => {
+ const option = optionFor(value);
+ return option
+ ? `${option.provider_label || option.profile_name} · ${option.model_name}`
+ : (value?.model_id ?? t("Not selected"));
+ };
+ const sameSelection = (
+ left?: { profile_id: string; model_id: string; reasoning_effort?: string },
+ right?: { profile_id: string; model_id: string; reasoning_effort?: string },
+ ) =>
+ Boolean(
+ left &&
+ right &&
+ left.profile_id === right.profile_id &&
+ left.model_id === right.model_id &&
+ (left.reasoning_effort ?? "") === (right.reasoning_effort ?? ""),
+ );
+ const usesDefaultVlm = Boolean(
+ selection &&
+ defaults &&
+ selection.vlm.mode === defaults.vlm.mode &&
+ (selection.vlm.mode === "disabled" ||
+ (defaults.vlm.mode === "enabled" &&
+ sameSelection(selection.vlm.selection, defaults.vlm.selection))),
+ );
+ const vlmValue = usesDefaultVlm
+ ? "__engine_default__"
+ : selection?.vlm.mode === "enabled" && selection.vlm.selection
+ ? `${selection.vlm.selection.profile_id}:${selection.vlm.selection.model_id}`
+ : "disabled";
+ const defaultVlmLabel =
+ defaults?.vlm.mode === "enabled"
+ ? optionLabel(defaults.vlm.selection)
+ : t("Image analysis disabled");
+
+ const fields = (
<div className="space-y-4">
<p className="text-xs text-[var(--muted-foreground)]">
{t(
- "Prefilled from the engine's EXTRACT and VLM settings. Changes here apply only to this new or rebuilt index.",
+ defaults
+ ? "Engine model settings are used by default. The resolved models are pinned when this index is created."
+ : "Prefilled from the engine's EXTRACT and VLM settings. Changes here apply only to this new or rebuilt index.",
+ )}
+ </p>
+ <p className="text-[11px] leading-relaxed text-[var(--muted-foreground)]">
+ {t(
+ "Used to extract entities and relationships during indexing. Choose a fast, economical model with reasoning disabled.",
)}
</p>
<IndexingModelSelector
{...state}
label="EXTRACT model"
+ defaultSelection={defaults?.extract}
+ defaultLabel={
+ defaults
+ ? `${t("Use engine default")} · ${optionLabel(defaults.extract)}`
+ : undefined
+ }
options={options}
selection={selection?.extract ?? null}
onChange={(extract) =>
@@ -121,33 +183,71 @@ export default function LightRagIndexingSelector({
/>
{selection && (
<>
- <label className="block text-xs">
+ <div className="space-y-1">
+ <p className="text-[11px] leading-relaxed text-[var(--muted-foreground)]">
+ {t(
+ "Used to analyze images during indexing. The model must support image input.",
+ )}
+ </p>
+ </div>
+ <label className="block text-xs font-medium">
{t("VLM image analysis")}
<select
aria-label={t("VLM image analysis")}
- value={selection.vlm.mode}
+ value={vlmValue}
disabled={state.disabled}
onChange={(event) => {
+ if (event.target.value === "__engine_default__" && defaults) {
+ onChange({ ...selection, vlm: defaults.vlm });
+ return;
+ }
+ if (event.target.value === "disabled") {
+ onChange({ ...selection, vlm: { mode: "disabled" } });
+ return;
+ }
+ const option = options.find(
+ (item) =>
+ `${item.profile_id}:${item.model_id}` === event.target.value,
+ );
+ if (!option) return;
onChange({
...selection,
- vlm:
- event.target.value === "enabled"
- ? { mode: "enabled" }
- : { mode: "disabled" },
+ vlm: {
+ mode: "enabled",
+ selection: {
+ profile_id: option.profile_id,
+ model_id: option.model_id,
+ },
+ },
});
}}
className="mt-1 w-full rounded-lg border border-[var(--border)] bg-[var(--background)] p-2"
>
+ {defaults && (
+ <option value="__engine_default__">
+ {t("Use engine default")} · {defaultVlmLabel}
+ </option>
+ )}
<option value="disabled">{t("Image analysis disabled")}</option>
- <option value="enabled">{t("Choose a vision model")}</option>
+ {options
+ .filter((option) => option.supports_vision)
+ .map((option) => (
+ <option
+ key={`${option.profile_id}:${option.model_id}`}
+ value={`${option.profile_id}:${option.model_id}`}
+ >
+ {option.provider_label || option.profile_name} ·{" "}
+ {option.model_name}
+ </option>
+ ))}
</select>
</label>
- {selection.vlm.mode === "enabled" && (
+ {selection.vlm.mode === "enabled" && selection.vlm.selection && (
<IndexingModelSelector
{...state}
- label="VLM model"
+ reasoningOnly
options={options.filter((option) => option.supports_vision)}
- selection={selection.vlm.selection ?? null}
+ selection={selection.vlm.selection}
onChange={(vlm) =>
onChange({
...selection,
@@ -158,11 +258,40 @@ export default function LightRagIndexingSelector({
)}
<p className="text-xs text-[var(--muted-foreground)]">
{t(
- "After publication, enabling, disabling or replacing VLM requires a full rebuild. A VLM pinned now can process later image uploads.",
+ defaults
+ ? "After creation, changing EXTRACT or enabling, disabling, or replacing VLM requires a full rebuild."
+ : "After publication, enabling, disabling or replacing VLM requires a full rebuild. A VLM pinned now can process later image uploads.",
)}
</p>
</>
)}
</div>
);
+
+ if (!collapsible) return fields;
+ const summary = selection
+ ? `EXTRACT: ${optionName(selection.extract)} · VLM: ${
+ selection.vlm.mode === "enabled"
+ ? optionName(selection.vlm.selection)
+ : t("Image analysis disabled")
+ }`
+ : t("Choose indexing models");
+ return (
+ <details
+ className="rounded-xl border border-[var(--border)] bg-[var(--muted)]/20 p-3"
+ open={
+ state.error || state.defaultLoadError || !selection ? true : undefined
+ }
+ >
+ <summary className="cursor-pointer list-none">
+ <span className="block text-[12px] font-medium text-[var(--foreground)]">
+ {t("Indexing models (optional override)")}
+ </span>
+ <span className="mt-1 block text-[11px] text-[var(--muted-foreground)]">
+ {summary}
+ </span>
+ </summary>
+ <div className="mt-4 border-t border-[var(--border)] pt-4">{fields}</div>
+ </details>
+ );
}
diff --git a/web/components/knowledge/LightRagRoleModelsEditor.tsx b/web/components/knowledge/LightRagRoleModelsEditor.tsx
index ad154535d..3f6866880 100644
--- a/web/components/knowledge/LightRagRoleModelsEditor.tsx
+++ b/web/components/knowledge/LightRagRoleModelsEditor.tsx
@@ -9,6 +9,16 @@ import type {
import type { LLMOption } from "@/lib/llm-options";
import IndexingModelSelector from "./IndexingModelSelector";
+const ROLE_DESCRIPTIONS = {
+ extract:
+ "Used to extract entities and relationships during indexing. Choose a fast, economical model with reasoning disabled.",
+ keyword:
+ "Used to generate retrieval keywords before a query. Choose a fast model with reasoning disabled.",
+ query:
+ "Used to produce the final answer from long, complex retrieval context. Choose a capable model; reasoning can be enabled.",
+ vlm: "Used to analyze images during indexing. The model must support image input.",
+} as const;
+
export const inheritedRole = (): LightRagRoleModel => ({
mode: "inherit",
max_async: 4,
@@ -59,22 +69,43 @@ export default function LightRagRoleModelsEditor({
const { t } = useTranslation();
return (
<div className="space-y-4">
- <IndexingModelSelector
- label="LightRAG base model"
- options={options}
- selection={models?.base ?? null}
- loading={loading}
- error={error}
- disabled={disabled}
- onChange={(base) => {
- if (base)
- onChange(models ? { ...models, base } : newRoleModels(base));
- }}
- />
+ <div className="space-y-1.5">
+ <IndexingModelSelector
+ label="LightRAG base model"
+ labelClassName="text-[12px] font-medium text-[var(--foreground)]"
+ options={options}
+ selection={models?.base ?? null}
+ loading={loading}
+ error={error}
+ disabled={disabled}
+ onChange={(base) => {
+ if (base)
+ onChange(models ? { ...models, base } : newRoleModels(base));
+ }}
+ />
+ <p className="text-[11px] leading-relaxed text-[var(--muted-foreground)]">
+ {t(
+ "The default model when no role model is specified. Role models can inherit its model and reasoning setting.",
+ )}
+ </p>
+ </div>
{models &&
(["extract", "keyword", "query", "vlm"] as const).map((role) => {
const value = models[role];
const effective = resolvedRole(models, role);
+ const roleOptions =
+ role === "vlm"
+ ? options.filter((option) => option.supports_vision)
+ : options;
+ const effectiveOption = options.find(
+ (option) =>
+ option.profile_id === effective?.profile_id &&
+ option.model_id === effective?.model_id,
+ );
+ const selectionKey =
+ value.mode === "model" && value.selection
+ ? `${value.selection.profile_id}:${value.selection.model_id}`
+ : value.mode;
const update = (patch: Partial<LightRagRoleModel>) =>
onChange({ ...models, [role]: { ...value, ...patch } });
return (
@@ -83,29 +114,42 @@ export default function LightRagRoleModelsEditor({
className="space-y-3 rounded-lg border border-[var(--border)] p-3"
disabled={disabled}
>
- <legend className="px-1 text-sm font-medium">
+ <legend className="px-1 text-[12px] font-medium text-[var(--foreground)]">
{role.toUpperCase()}
</legend>
- <label className="block text-xs">
- {t("Model source")}
+ <p className="text-[11px] leading-relaxed text-[var(--muted-foreground)]">
+ {t(ROLE_DESCRIPTIONS[role])}
+ </p>
+ <label className="block text-xs font-medium">
+ {t("Model")}
<select
- aria-label={`${role.toUpperCase()} ${t("Model source")}`}
- value={value.mode}
+ aria-label={`${role.toUpperCase()} ${t("Model")}`}
+ value={selectionKey}
className="mt-1 w-full rounded-lg border border-[var(--border)] bg-[var(--background)] p-2"
onChange={(event) => {
- const mode = event.target
- .value as LightRagRoleModel["mode"];
- update({
- mode,
- selection:
- mode === "model"
- ? {
- profile_id: models.base.profile_id,
- model_id: models.base.model_id,
- }
- : null,
- reasoning_effort: null,
- });
+ const next = event.target.value;
+ if (next === "disabled" || next === "inherit") {
+ update({
+ mode: next,
+ selection: null,
+ reasoning_effort: null,
+ });
+ return;
+ }
+ const option = roleOptions.find(
+ (item) =>
+ `${item.profile_id}:${item.model_id}` === next,
+ );
+ if (option) {
+ update({
+ mode: "model",
+ selection: {
+ profile_id: option.profile_id,
+ model_id: option.model_id,
+ },
+ reasoning_effort: null,
+ });
+ }
}}
>
{role === "vlm" && (
@@ -114,19 +158,39 @@ export default function LightRagRoleModelsEditor({
</option>
)}
<option value="inherit">
- {t("Inherit LightRAG base model")}
+ {t("Inherit LightRAG base model")} ·{" "}
+ {options.find(
+ (option) =>
+ option.profile_id === models.base.profile_id &&
+ option.model_id === models.base.model_id,
+ )?.model_name ?? models.base.model_id}
</option>
- <option value="model">{t("Choose a model")}</option>
+ {value.mode === "model" &&
+ value.selection &&
+ !roleOptions.some(
+ (option) =>
+ option.profile_id === value.selection?.profile_id &&
+ option.model_id === value.selection?.model_id,
+ ) && (
+ <option value={selectionKey} disabled>
+ {t("Unavailable model")} · {value.selection.model_id}
+ </option>
+ )}
+ {roleOptions.map((option) => (
+ <option
+ key={`${option.profile_id}:${option.model_id}`}
+ value={`${option.profile_id}:${option.model_id}`}
+ >
+ {option.provider_label || option.profile_name} ·{" "}
+ {option.model_name}
+ </option>
+ ))}
</select>
</label>
{value.mode !== "disabled" && (
<IndexingModelSelector
- label={`${role.toUpperCase()} ${t("effective model")}`}
- options={
- role === "vlm" && value.mode === "model"
- ? options.filter((option) => option.supports_vision)
- : options
- }
+ reasoningOnly
+ options={roleOptions}
selection={
effective
? {
@@ -142,7 +206,6 @@ export default function LightRagRoleModelsEditor({
}
loading={loading}
error={error}
- lockModel={value.mode === "inherit"}
onChange={(selection) => {
if (selection)
update({
@@ -158,6 +221,12 @@ export default function LightRagRoleModelsEditor({
}}
/>
)}
+ {effectiveOption && value.mode !== "disabled" && (
+ <p className="text-[11px] text-[var(--muted-foreground)]">
+ {t("Currently effective")}: {effectiveOption.provider_label || effectiveOption.profile_name} ·{" "}
+ {effectiveOption.model_name}
+ </p>
+ )}
{role === "vlm" &&
value.mode !== "disabled" &&
!options.some(
@@ -171,7 +240,11 @@ export default function LightRagRoleModelsEditor({
</p>
)}
{value.mode !== "disabled" && (
- <div className="grid grid-cols-2 gap-3">
+ <details className="rounded-lg border border-[var(--border)] px-3 py-2">
+ <summary className="cursor-pointer text-xs font-medium">
+ {t("Advanced")}
+ </summary>
+ <div className="mt-3 grid grid-cols-2 gap-3">
<label className="text-xs">
{t("Concurrent LLM calls")}
<input
@@ -200,7 +273,8 @@ export default function LightRagRoleModelsEditor({
className="mt-1 w-full rounded border border-[var(--border)] bg-[var(--background)] p-2"
/>
</label>
- </div>
+ </div>
+ </details>
)}
</fieldset>
);
diff --git a/web/features/knowledge/components/engines/EngineDetail.tsx b/web/features/knowledge/components/engines/EngineDetail.tsx
index eef119ce1..b073b09c1 100644
--- a/web/features/knowledge/components/engines/EngineDetail.tsx
+++ b/web/features/knowledge/components/engines/EngineDetail.tsx
@@ -114,15 +114,14 @@ const MODE_DESCRIPTIONS: Record<string, string> = {
};
// Model kinds each engine needs (for the in-place pickers). "vision" isn't a
-// catalog service — it rides on the active chat model — so LightRAG only lists
-// llm + embedding and shows a vision note under the chat picker. LightRAG Server
-// owns its own models on the remote instance, so it needs none here.
+// catalog service — it rides on the active chat model. LightRAG owns its role
+// models separately and only uses the shared embedding selection here.
const ENGINE_MODEL_KINDS: Record<string, ("llm" | "embedding")[]> = {
llamaindex: ["embedding"],
pageindex: [],
"pageindex-oss": ["llm"],
graphrag: ["llm", "embedding"],
- lightrag: ["llm", "embedding"],
+ lightrag: ["embedding"],
"lightrag-server": [],
weknora: [],
};
@@ -1058,7 +1057,6 @@ export function LightRagForm({
onError: (message: string) => void;
}) {
const { t } = useTranslation();
- const catalog = useLLMOptions(getLightRagModelOptions);
const auth = useAuthStatus();
const canEdit = auth.statusAvailable && (!auth.enabled || auth.isAdmin);
const { form, setLoaded, setForm, saving, setSaving, dirty, patch } =
@@ -1068,39 +1066,14 @@ export function LightRagForm({
);
if (!form) return <FormSkeleton />;
- const legacyBase = selectionFromLightRagDefault(
- catalog.options,
- form,
- catalog.activeDefault,
- );
- const legacyOption = catalog.options.find(
- (option) =>
- option.profile_id === legacyBase?.profile_id &&
- option.model_id === legacyBase?.model_id,
- );
- const roleModels =
- form.role_models ??
- (legacyBase
- ? newRoleModels(
- legacyBase,
- form.version !== 2 && legacyOption?.supports_vision === true,
- )
- : null);
-
const save = async () => {
- if (!roleModels) {
- onError(t("Choose a LightRAG base model before saving."));
- return;
- }
setSaving(true);
try {
const next = await updateLightRagConfig({
top_k: form.top_k,
response_type: form.response_type,
max_concurrent_files: form.max_concurrent_files,
- llm_model_max_async: form.llm_model_max_async,
entity_extract_max_gleaning: form.entity_extract_max_gleaning,
- role_models: roleModels ?? undefined,
});
setLoaded(next);
setForm(next);
@@ -1136,32 +1109,6 @@ export function LightRagForm({
/>
</div>
- {!form.role_models && form.version !== 2 && (
- <p className="text-xs text-[var(--muted-foreground)]">
- {t(
- "Legacy model settings are shown below. Saving fixes the LightRAG base selection independently of chat.",
- )}
- </p>
- )}
- <LightRagRoleModelsEditor
- models={roleModels}
- options={catalog.options}
- loading={catalog.loading}
- error={catalog.error}
- disabled={saving}
- onChange={(role_models) => patch({ role_models })}
- />
- <p className="text-xs text-[var(--muted-foreground)]">
- {t(
- "KEYWORD and QUERY apply to subsequent queries. EXTRACT and VLM apply to new or fully rebuilt indexes; published indexes keep their pinned models.",
- )}
- </p>
- <p className="text-xs text-[var(--muted-foreground)]">
- {t(
- "Role concurrency and timeouts apply to subsequent tasks without rebuilding.",
- )}
- </p>
-
{/* Indexing knobs are a separate axis from the two above: they shape how
a knowledge base is built, so changing them only affects the next
build — the divider and note keep that from surprising anyone. */}
@@ -1194,6 +1141,96 @@ export function LightRagForm({
</div>
</div>
+ <SaveButton dirty={dirty} saving={saving} onSave={() => void save()} />
+ </fieldset>
+ );
+}
+
+export function LightRagModelsForm({
+ onChanged,
+ onError,
+}: {
+ onChanged: () => void;
+ onError: (message: string) => void;
+}) {
+ const { t } = useTranslation();
+ const catalog = useLLMOptions(getLightRagModelOptions);
+ const auth = useAuthStatus();
+ const canEdit = auth.statusAvailable && (!auth.enabled || auth.isAdmin);
+ const { form, setLoaded, setForm, saving, setSaving, dirty, patch } =
+ useEngineForm<LightRagConfig>(
+ () => getLightRagConfig({ force: true }),
+ onError,
+ );
+
+ if (!form) return <FormSkeleton />;
+ const legacyBase = selectionFromLightRagDefault(
+ catalog.options,
+ form,
+ catalog.activeDefault,
+ );
+ const legacyOption = catalog.options.find(
+ (option) =>
+ option.profile_id === legacyBase?.profile_id &&
+ option.model_id === legacyBase?.model_id,
+ );
+ const roleModels =
+ form.role_models ??
+ (legacyBase
+ ? newRoleModels(
+ legacyBase,
+ form.version !== 2 && legacyOption?.supports_vision === true,
+ )
+ : null);
+
+ const save = async () => {
+ if (!roleModels) {
+ onError(t("Choose a LightRAG base model before saving."));
+ return;
+ }
+ setSaving(true);
+ try {
+ const next = await updateLightRagConfig({ role_models: roleModels });
+ setLoaded(next);
+ setForm(next);
+ onChanged();
+ } catch (err) {
+ onError(err instanceof Error ? err.message : String(err));
+ } finally {
+ setSaving(false);
+ }
+ };
+
+ return (
+ <fieldset
+ disabled={!canEdit || saving}
+ className="space-y-4 rounded-2xl border border-[var(--border)] p-4"
+ >
+ {!auth.loading && !canEdit && (
+ <p className="text-xs text-[var(--muted-foreground)]">
+ {t("Only administrators can change shared LightRAG engine settings.")}
+ </p>
+ )}
+ {!form.role_models && form.version !== 2 && (
+ <p className="text-xs text-[var(--muted-foreground)]">
+ {t(
+ "Legacy model settings are shown below. Saving fixes the LightRAG base selection independently of chat.",
+ )}
+ </p>
+ )}
+ <LightRagRoleModelsEditor
+ models={roleModels}
+ options={catalog.options}
+ loading={catalog.loading}
+ error={catalog.error}
+ disabled={saving}
+ onChange={(role_models) => patch({ role_models })}
+ />
+ <p className="text-xs text-[var(--muted-foreground)]">
+ {t(
+ "KEYWORD and QUERY apply to subsequent queries. EXTRACT and VLM apply to new or fully rebuilt indexes; published indexes keep their pinned models.",
+ )}
+ </p>
<SaveButton
dirty={dirty || (!form.role_models && roleModels !== null)}
saving={saving}
@@ -1386,9 +1423,11 @@ function FormSkeleton() {
function ModelsSection({
providerId,
+ onChanged,
onError,
}: {
providerId: string;
+ onChanged: () => void;
onError: (message: string) => void;
}) {
const { t } = useTranslation();
@@ -1632,6 +1671,11 @@ function ModelsSection({
})}
</div>
)}
+ {providerId === "lightrag" && (
+ <div className="mt-4">
+ <LightRagModelsForm onChanged={onChanged} onError={onError} />
+ </div>
+ )}
</Section>
);
}
@@ -1891,7 +1935,11 @@ export default function EngineDetail({
)}
{/* Models — in-place pickers for the kinds this engine needs */}
- <ModelsSection providerId={provider.id} onError={onError} />
+ <ModelsSection
+ providerId={provider.id}
+ onChanged={onChanged}
+ onError={onError}
+ />
{/* Knowledge bases on this engine */}
<Section
diff --git a/web/locales/en/app.json b/web/locales/en/app.json
index e0c90ac72..abf590003 100644
--- a/web/locales/en/app.json
+++ b/web/locales/en/app.json
@@ -4017,5 +4017,18 @@
"effective model": "effective model",
"Finalizing index publication": "Finalizing index publication",
"Inherit base reasoning": "Inherit base reasoning",
- "With no role override, reasoning follows the LightRAG base.": "With no role override, reasoning follows the LightRAG base."
+ "With no role override, reasoning follows the LightRAG base.": "With no role override, reasoning follows the LightRAG base.",
+ "The default model when no role model is specified. Role models can inherit its model and reasoning setting.": "The default model when no role model is specified. Role models can inherit its model and reasoning setting.",
+ "Used to extract entities and relationships during indexing. Choose a fast, economical model with reasoning disabled.": "Used to extract entities and relationships during indexing. Choose a fast, economical model with reasoning disabled.",
+ "Used to generate retrieval keywords before a query. Choose a fast model with reasoning disabled.": "Used to generate retrieval keywords before a query. Choose a fast model with reasoning disabled.",
+ "Used to produce the final answer from long, complex retrieval context. Choose a capable model; reasoning can be enabled.": "Used to produce the final answer from long, complex retrieval context. Choose a capable model; reasoning can be enabled.",
+ "Used to analyze images during indexing. The model must support image input.": "Used to analyze images during indexing. The model must support image input.",
+ "Currently effective": "Currently effective",
+ "Unavailable model": "Unavailable model",
+ "Use engine default": "Use engine default",
+ "Not selected": "Not selected",
+ "Choose indexing models": "Choose indexing models",
+ "Indexing models (optional override)": "Indexing models (optional override)",
+ "Engine model settings are used by default. The resolved models are pinned when this index is created.": "Engine model settings are used by default. The resolved models are pinned when this index is created.",
+ "After creation, changing EXTRACT or enabling, disabling, or replacing VLM requires a full rebuild.": "After creation, changing EXTRACT or enabling, disabling, or replacing VLM requires a full rebuild."
}
diff --git a/web/locales/zh/app.json b/web/locales/zh/app.json
index e8c6a479d..46587f864 100644
--- a/web/locales/zh/app.json
+++ b/web/locales/zh/app.json
@@ -3999,7 +3999,7 @@
"Choose a vision model": "选择视觉模型",
"EXTRACT model": "EXTRACT 模型",
"Effective reasoning": "实际推理强度",
- "Image analysis disabled": "图片分析已禁用",
+ "Image analysis disabled": "禁用图片分析",
"Image analysis is disabled. Enable a VLM through a full rebuild.": "图片分析已禁用。请通过完整重建启用 VLM。",
"Inherit LightRAG base model": "继承 LightRAG 基础模型",
"KEYWORD and QUERY apply to subsequent queries. EXTRACT and VLM apply to new or fully rebuilt indexes; published indexes keep their pinned models.": "KEYWORD 和 QUERY 应用于后续查询。EXTRACT 和 VLM 应用于新建或完整重建的索引;已发布的索引保留固定的模型。",
@@ -4017,5 +4017,18 @@
"effective model": "实际模型",
"Finalizing index publication": "正在完成索引发布",
"Inherit base reasoning": "继承基础模型推理设置",
- "With no role override, reasoning follows the LightRAG base.": "未设置角色覆盖值时,推理强度继承 LightRAG 基础模型。"
+ "With no role override, reasoning follows the LightRAG base.": "未设置角色覆盖值时,推理强度继承 LightRAG 基础模型。",
+ "The default model when no role model is specified. Role models can inherit its model and reasoning setting.": "未单独指定角色模型时使用的默认模型;角色模型可以继承它的模型和推理设置。",
+ "Used to extract entities and relationships during indexing. Choose a fast, economical model with reasoning disabled.": "用于索引时抽取实体和关系;调用频繁,建议选择快速、经济并关闭推理的模型。",
+ "Used to generate retrieval keywords before a query. Choose a fast model with reasoning disabled.": "用于查询前生成检索关键词;延迟敏感,应选择快速并关闭推理的模型。",
+ "Used to produce the final answer from long, complex retrieval context. Choose a capable model; reasoning can be enabled.": "用于根据较长且复杂的检索上下文生成最终回答;宜选择能力较强的模型,可开启推理。",
+ "Used to analyze images during indexing. The model must support image input.": "用于索引时分析图片;必须选择支持视觉输入的模型。",
+ "Currently effective": "当前生效",
+ "Unavailable model": "不可用的模型",
+ "Use engine default": "使用引擎默认值",
+ "Not selected": "未选择",
+ "Choose indexing models": "选择索引模型",
+ "Indexing models (optional override)": "索引模型(可选覆盖)",
+ "Engine model settings are used by default. The resolved models are pinned when this index is created.": "默认使用 LightRAG 引擎的索引模型设置;创建时会将实际模型固定到这个索引版本。",
+ "After creation, changing EXTRACT or enabling, disabling, or replacing VLM requires a full rebuild.": "创建后,更换 EXTRACT 模型或启用、禁用、更换 VLM 均需完整重建索引。"
}
diff --git a/web/tests/lightrag-form.spec.tsx b/web/tests/lightrag-form.spec.tsx
index 382337973..266db6ff5 100644
--- a/web/tests/lightrag-form.spec.tsx
+++ b/web/tests/lightrag-form.spec.tsx
@@ -7,7 +7,7 @@ import {
within,
} from "@testing-library/react";
import { beforeEach, expect, it, vi } from "vitest";
-import { LightRagForm } from "@/features/knowledge/components/engines/EngineDetail";
+import { LightRagModelsForm } from "@/features/knowledge/components/engines/EngineDetail";
const fixture = vi.hoisted(() => ({ version: 2, save: vi.fn() }));
vi.mock("react-i18next", () => ({
@@ -66,9 +66,9 @@ it.each([
"saves version %s prefilled vision as %s",
async (version, mode) => {
fixture.version = version;
- render(<LightRagForm onChanged={vi.fn()} onError={vi.fn()} />);
+ render(<LightRagModelsForm onChanged={vi.fn()} onError={vi.fn()} />);
const vlm = within(await screen.findByRole("group", { name: "VLM" }));
- expect(vlm.getByRole("combobox", { name: "VLM Model source" })).toHaveValue(
+ expect(vlm.getByRole("combobox", { name: "VLM Model" })).toHaveValue(
mode,
);
fireEvent.click(screen.getByRole("button", { name: "Save changes" }));
diff --git a/web/tests/lightrag-role-models.spec.tsx b/web/tests/lightrag-role-models.spec.tsx
index 87c3afb0c..609b7cd58 100644
--- a/web/tests/lightrag-role-models.spec.tsx
+++ b/web/tests/lightrag-role-models.spec.tsx
@@ -70,20 +70,14 @@ describe("LightRAG role editor", () => {
it("keeps disabled, inherited, and explicit VLM choices distinct", () => {
render(<Editor />);
const vlm = within(screen.getByRole("group", { name: "VLM" }));
- const mode = vlm.getByRole("combobox", { name: "VLM Model source" });
+ const mode = vlm.getByRole("combobox", { name: "VLM Model" });
expect(state().vlm.mode).toBe("disabled");
fireEvent.change(mode, { target: { value: "inherit" } });
expect(
vlm.getByText("The selected VLM model does not support image inputs."),
).toBeInTheDocument();
expect(state().vlm.selection).toBeNull();
- fireEvent.change(mode, { target: { value: "model" } });
- fireEvent.change(
- vlm.getByRole("combobox", { name: "VLM effective model" }),
- {
- target: { value: "vision:large" },
- },
- );
+ fireEvent.change(mode, { target: { value: "vision:large" } });
expect(resolvedRole(state(), "vlm")).toEqual(visionModel);
fireEvent.change(mode, { target: { value: "disabled" } });
expect(resolvedRole(state(), "vlm")).toBeNull();
@@ -91,6 +85,7 @@ describe("LightRAG role editor", () => {
it("preserves explicit none and limits when the base model changes", () => {
render(<Editor />);
const extract = within(screen.getByRole("group", { name: "EXTRACT" }));
+ fireEvent.click(extract.getByText("Advanced"));
fireEvent.change(
extract.getByRole("combobox", { name: "Reasoning effort" }),
{
@@ -116,6 +111,28 @@ describe("LightRAG role editor", () => {
expect(state().extract.timeout).toBe(321);
expect(state().vlm.mode).toBe("disabled");
});
+ it("shows concise role guidance and one model selector per role", () => {
+ render(<Editor />);
+ const extract = within(screen.getByRole("group", { name: "EXTRACT" }));
+ expect(
+ extract.getByText(
+ "Used to extract entities and relationships during indexing. Choose a fast, economical model with reasoning disabled.",
+ ),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByText(
+ "The default model when no role model is specified. Role models can inherit its model and reasoning setting.",
+ ),
+ ).toBeInTheDocument();
+ expect(
+ extract.getAllByRole("combobox", { name: "EXTRACT Model" }),
+ ).toHaveLength(1);
+ expect(
+ within(screen.getByRole("group", { name: "VLM" })).getByText(
+ "Used to analyze images during indexing. The model must support image input.",
+ ),
+ ).toBeInTheDocument();
+ });
it("shows an invalid saved effort without offering unsupported replacements", () => {
const initial = newRoleModels(textModel);
initial.extract.reasoning_effort = "high";
@@ -167,7 +184,7 @@ it("prefills independent indexing roles and preserves a saved disabled policy",
}),
).toEqual({ extract: textModel, vlm: { mode: "disabled" } });
});
-it("requires an explicit vision selection when enabling it in a rebuild draft", () => {
+it("selects a vision model without a duplicate VLM control", () => {
function Draft() {
const [selection, setSelection] =
useState<LightRagIndexingSelection | null>({
@@ -194,18 +211,9 @@ it("requires an explicit vision selection when enabling it in a rebuild draft",
fireEvent.change(
screen.getByRole("combobox", { name: "VLM image analysis" }),
{
- target: { value: "enabled" },
+ target: { value: "vision:large" },
},
);
- expect(
- JSON.parse(screen.getByTestId("draft").textContent ?? "{}").vlm,
- ).toEqual({
- mode: "enabled",
- });
- expect(screen.getByRole("button", { name: "Submit" })).toBeDisabled();
- fireEvent.change(screen.getByRole("combobox", { name: "VLM model" }), {
- target: { value: "vision:large" },
- });
expect(
JSON.parse(screen.getByTestId("draft").textContent ?? "{}").vlm,
).toEqual({
@@ -213,6 +221,37 @@ it("requires an explicit vision selection when enabling it in a rebuild draft",
selection: visionModel,
});
expect(screen.getByRole("button", { name: "Submit" })).toBeEnabled();
+ expect(
+ screen.queryByRole("combobox", { name: "VLM model" }),
+ ).not.toBeInTheDocument();
+});
+
+it("shows engine defaults in the collapsed create-index summary", () => {
+ const defaults: LightRagIndexingSelection = {
+ extract: textModel,
+ vlm: { mode: "disabled" },
+ };
+ render(
+ <LightRagIndexingSelector
+ options={options}
+ selection={defaults}
+ defaults={defaults}
+ collapsible
+ onChange={vi.fn()}
+ loading={false}
+ error={false}
+ />,
+ );
+ expect(
+ screen.getByText("EXTRACT: Small · VLM: Image analysis disabled"),
+ ).toBeInTheDocument();
+ fireEvent.click(screen.getByText("Indexing models (optional override)"));
+ expect(
+ screen.getByRole("combobox", { name: "EXTRACT model" }),
+ ).toHaveValue("__engine_default__");
+ expect(
+ screen.getByRole("combobox", { name: "VLM image analysis" }),
+ ).toHaveValue("__engine_default__");
});
it("distinguishes inherited reasoning from an explicit override with the same value", () => {