Skip to content

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

fix(lightrag): close role model audit gaps

NoxsMedia814081f36dd1
diff --git a/deeptutor/services/rag/pipelines/lightrag/README.md b/deeptutor/services/rag/pipelines/lightrag/README.md
index 4a5ea5606..909723469 100644
--- a/deeptutor/services/rag/pipelines/lightrag/README.md
+++ b/deeptutor/services/rag/pipelines/lightrag/README.md
@@ -25,6 +25,12 @@ model or reasoning level. Concurrency and timeout limits apply per role to
subsequent tasks and do not require rebuilding. Accepted tasks keep their effective
models, reasoning and limits while queued and running.
+DeepTutor forwards LightRAG structured-output requests, including the JSON
+object contracts used by EXTRACT, KEYWORD and VLM, through its provider
+capability filter. Provider reasoning is controlled by the saved role effort.
+DeepTutor intentionally omits provider reasoning traces from the returned answer
+even when LightRAG requests its COT output format.
+
## Creating, appending and rebuilding
Creation and full rebuild dialogs prefill EXTRACT and VLM from engine settings.
diff --git a/deeptutor/services/rag/pipelines/lightrag/config.py b/deeptutor/services/rag/pipelines/lightrag/config.py
index 568e5b16b..d7fd19ccf 100644
--- a/deeptutor/services/rag/pipelines/lightrag/config.py
+++ b/deeptutor/services/rag/pipelines/lightrag/config.py
@@ -255,7 +255,13 @@ def build_llm_model_func(
):
"""Wrap DeepTutor's unified LLM callable for LightRAG.
- Drops LightRAG's internal kwargs while preserving explicit ``messages``.
+ Preserve provider-facing structured-output requests while keeping
+ LightRAG's orchestration-only kwargs out of DeepTutor's provider layer.
+
+ ``enable_cot`` is intentionally an output-formatting switch in LightRAG,
+ not a request to enable provider reasoning. DeepTutor controls reasoning
+ through the frozen role configuration and returns answer content without
+ exposing provider reasoning text.
"""
if llm_config is None:
from deeptutor.services.llm import get_llm_client
@@ -271,10 +277,17 @@ def build_llm_model_func(
system_prompt=None,
history_messages=None,
messages=None,
+ response_format=None,
+ enable_cot=False,
**_ignored,
):
+ del enable_cot
+
async def request():
async def complete():
+ provider_kwargs = {}
+ if response_format is not None:
+ provider_kwargs["response_format"] = response_format
return await base(
prompt or "",
system_prompt=system_prompt,
@@ -282,6 +295,7 @@ def build_llm_model_func(
messages=messages,
max_retries=0,
allow_image_fallback=False,
+ **provider_kwargs,
)
if owner is None:
@@ -318,6 +332,7 @@ def build_vision_model_func(
history_messages=None,
image_inputs=None,
messages=None,
+ response_format=None,
**_ignored,
):
if not isinstance(image_inputs, list) or len(image_inputs) != 1:
@@ -331,6 +346,9 @@ def build_vision_model_func(
async def request():
async def complete():
+ provider_kwargs = {}
+ if response_format is not None:
+ provider_kwargs["response_format"] = response_format
return await base(
prompt or "",
system_prompt=system_prompt,
@@ -339,6 +357,7 @@ def build_vision_model_func(
messages=messages,
max_retries=0,
allow_image_fallback=False,
+ **provider_kwargs,
)
if owner is None:
diff --git a/tests/services/rag/test_lightrag_pipeline.py b/tests/services/rag/test_lightrag_pipeline.py
index 9e192a3f1..aa1a3f210 100644
--- a/tests/services/rag/test_lightrag_pipeline.py
+++ b/tests/services/rag/test_lightrag_pipeline.py
@@ -158,11 +158,14 @@ def test_query_model_resolver_falls_back_only_when_selected_entry_is_missing(
def test_lightrag_llm_adapter_uses_explicit_snapshot_config(monkeypatch) -> None:
+ captured = {}
+
def build_model(config, *, allow_multimodal):
assert config is selected_config
assert allow_multimodal is False
async def model_func(_prompt, **kwargs):
+ captured.update(kwargs)
assert kwargs["max_retries"] == 0
return "ok"
@@ -172,15 +175,35 @@ def test_lightrag_llm_adapter_uses_explicit_snapshot_config(monkeypatch) -> None
monkeypatch.setattr("deeptutor.services.llm.client.build_model_func_for_config", build_model)
adapter = config.build_llm_model_func(llm_config=selected_config)
- assert asyncio.run(adapter("prompt")) == "ok"
+ assert (
+ asyncio.run(
+ adapter(
+ "prompt",
+ response_format={"type": "json_object"},
+ enable_cot=True,
+ stream=False,
+ _priority=3,
+ hashing_kv=object(),
+ )
+ )
+ == "ok"
+ )
+ assert captured["response_format"] == {"type": "json_object"}
+ assert "enable_cot" not in captured
+ assert "stream" not in captured
+ assert "_priority" not in captured
+ assert "hashing_kv" not in captured
def test_lightrag_vision_adapter_uses_explicit_snapshot_config(monkeypatch) -> None:
+ captured = {}
+
def build_model(config, *, allow_multimodal):
assert config is selected_config
assert allow_multimodal is True
async def model_func(_prompt, **kwargs):
+ captured.update(kwargs)
assert kwargs["allow_image_fallback"] is False
assert kwargs["image_data"] == "sentinel"
return "ok"
@@ -191,7 +214,23 @@ def test_lightrag_vision_adapter_uses_explicit_snapshot_config(monkeypatch) -> N
monkeypatch.setattr("deeptutor.services.llm.client.build_model_func_for_config", build_model)
adapter = config.build_vision_model_func(llm_config=selected_config)
- assert asyncio.run(adapter("prompt", image_inputs=[{"base64": "sentinel"}])) == "ok"
+ assert (
+ asyncio.run(
+ adapter(
+ "prompt",
+ image_inputs=[{"base64": "sentinel"}],
+ response_format={"type": "json_object"},
+ stream=False,
+ _priority=3,
+ hashing_kv=object(),
+ )
+ )
+ == "ok"
+ )
+ assert captured["response_format"] == {"type": "json_object"}
+ assert "stream" not in captured
+ assert "_priority" not in captured
+ assert "hashing_kv" not in captured
@pytest.mark.parametrize("role", ["user", "admin"])
diff --git a/web/components/knowledge/CreateKbModal.tsx b/web/components/knowledge/CreateKbModal.tsx
index fe978a3a4..c5855bf24 100644
--- a/web/components/knowledge/CreateKbModal.tsx
+++ b/web/components/knowledge/CreateKbModal.tsx
@@ -419,7 +419,10 @@ export default function CreateKbModal({
!!weKnoraProbe?.ok
);
}
- if (provider === "lightrag" && !isCompleteIndexingSelection(indexingLLM))
+ if (
+ provider === "lightrag" &&
+ !isCompleteIndexingSelection(indexingLLM, llmCatalog.options)
+ )
return false;
return !providerUnavailable;
}
diff --git a/web/components/knowledge/IndexingModelSelector.tsx b/web/components/knowledge/IndexingModelSelector.tsx
index 9be433f3d..d1eb5ff3e 100644
--- a/web/components/knowledge/IndexingModelSelector.tsx
+++ b/web/components/knowledge/IndexingModelSelector.tsx
@@ -99,6 +99,10 @@ export default function IndexingModelSelector({
option.profile_id === selection?.profile_id &&
option.model_id === selection?.model_id,
);
+ const unavailableSelectionKey =
+ selection && !selected
+ ? `${selection.profile_id}:${selection.model_id}`
+ : null;
const usesDefault = Boolean(
defaultSelection &&
selection?.profile_id === defaultSelection.profile_id &&
@@ -159,7 +163,7 @@ export default function IndexingModelSelector({
? "__engine_default__"
: selected
? `${selected.profile_id}:${selected.model_id}`
- : ""
+ : (unavailableSelectionKey ?? "")
}
disabled={disabled || lockModel}
onChange={(event) => {
@@ -178,6 +182,11 @@ export default function IndexingModelSelector({
<option value="" disabled>
{t("Select an indexing model")}
</option>
+ {unavailableSelectionKey && (
+ <option value={unavailableSelectionKey} disabled>
+ {t("Unavailable model")} · {selection?.model_id}
+ </option>
+ )}
{defaultSelection && defaultLabel && (
<option value="__engine_default__">{defaultLabel}</option>
)}
diff --git a/web/components/knowledge/KbIndexVersionsSection.tsx b/web/components/knowledge/KbIndexVersionsSection.tsx
index 0752f538d..9bd7ea41e 100644
--- a/web/components/knowledge/KbIndexVersionsSection.tsx
+++ b/web/components/knowledge/KbIndexVersionsSection.tsx
@@ -187,7 +187,7 @@ export default function KbIndexVersionsSection({
};
const handleModelSubmit = async () => {
- if (!isCompleteIndexingSelection(indexingLLM)) return;
+ if (!isCompleteIndexingSelection(indexingLLM, llmCatalog.options)) return;
setSubmitting(true);
setDialogError(null);
try {
@@ -399,7 +399,10 @@ export default function KbIndexVersionsSection({
<button
type="button"
onClick={() => void handleModelSubmit()}
- disabled={submitting || !isCompleteIndexingSelection(indexingLLM)}
+ disabled={
+ submitting ||
+ !isCompleteIndexingSelection(indexingLLM, llmCatalog.options)
+ }
className="inline-flex items-center gap-1.5 rounded-md bg-[var(--primary)] px-3 py-1.5 text-[12px] font-medium text-[var(--primary-foreground)] disabled:opacity-50"
>
{submitting && <Loader2 className="h-3 w-3 animate-spin" />}
diff --git a/web/components/knowledge/LightRagIndexingSelector.tsx b/web/components/knowledge/LightRagIndexingSelector.tsx
index 6f4493ab9..89768e9e4 100644
--- a/web/components/knowledge/LightRagIndexingSelector.tsx
+++ b/web/components/knowledge/LightRagIndexingSelector.tsx
@@ -74,13 +74,30 @@ export function indexingSelectionFromPolicy(
export function isCompleteIndexingSelection(
value: LightRagIndexingSelection | null,
+ options?: LLMOption[],
): value is LightRagIndexingSelection {
- return Boolean(
+ const structurallyComplete = Boolean(
value?.extract.profile_id &&
value.extract.model_id &&
(value.vlm.mode === "disabled" ||
(value.vlm.selection?.profile_id && value.vlm.selection.model_id)),
);
+ if (!structurallyComplete || !value || options === undefined) {
+ return structurallyComplete;
+ }
+ const available = (selection: { profile_id: string; model_id: string }) =>
+ options.find(
+ (option) =>
+ option.profile_id === selection.profile_id &&
+ option.model_id === selection.model_id,
+ );
+ if (!available(value.extract)) return false;
+ return (
+ value.vlm.mode === "disabled" ||
+ Boolean(
+ value.vlm.selection && available(value.vlm.selection)?.supports_vision,
+ )
+ );
}
export default function LightRagIndexingSelector({
@@ -147,6 +164,11 @@ export default function LightRagIndexingSelector({
defaults?.vlm.mode === "enabled"
? optionLabel(defaults.vlm.selection)
: t("Image analysis disabled");
+ const hasUnavailableSelection = Boolean(
+ selection &&
+ isCompleteIndexingSelection(selection) &&
+ !isCompleteIndexingSelection(selection, options),
+ );
const fields = (
<div className="space-y-4">
@@ -162,6 +184,13 @@ export default function LightRagIndexingSelector({
"Used to extract entities and relationships during indexing. Choose a fast, economical model with reasoning disabled.",
)}
</p>
+ {hasUnavailableSelection && (
+ <p className="text-xs text-red-600">
+ {t(
+ "One or more selected indexing models are unavailable. Choose accessible models before continuing.",
+ )}
+ </p>
+ )}
<IndexingModelSelector
{...state}
label="EXTRACT model"
diff --git a/web/components/knowledge/LightRagRoleModelsEditor.tsx b/web/components/knowledge/LightRagRoleModelsEditor.tsx
index 3f6866880..32d305230 100644
--- a/web/components/knowledge/LightRagRoleModelsEditor.tsx
+++ b/web/components/knowledge/LightRagRoleModelsEditor.tsx
@@ -19,22 +19,71 @@ const ROLE_DESCRIPTIONS = {
vlm: "Used to analyze images during indexing. The model must support image input.",
} as const;
-export const inheritedRole = (): LightRagRoleModel => ({
+export const inheritedRole = (maxAsync = 4): LightRagRoleModel => ({
mode: "inherit",
- max_async: 4,
+ max_async: maxAsync,
timeout: 240,
});
export const newRoleModels = (
base: IndexingLLMSelection,
vision = false,
+ maxAsync = 4,
): LightRagRoleModels => ({
base,
- extract: inheritedRole(),
- keyword: inheritedRole(),
- query: inheritedRole(),
- vlm: { ...inheritedRole(), mode: vision ? "inherit" : "disabled" },
+ extract: inheritedRole(maxAsync),
+ keyword: inheritedRole(maxAsync),
+ query: inheritedRole(maxAsync),
+ vlm: {
+ ...inheritedRole(maxAsync),
+ mode: vision ? "inherit" : "disabled",
+ },
});
+export function roleModelsValidationError(
+ models: LightRagRoleModels | null,
+ options: LLMOption[],
+): string | null {
+ if (!models) return "Choose a LightRAG base model before saving.";
+ const findOption = (selection: IndexingLLMSelection | null | undefined) =>
+ options.find(
+ (option) =>
+ option.profile_id === selection?.profile_id &&
+ option.model_id === selection?.model_id,
+ );
+ if (!findOption(models.base)) {
+ return "The LightRAG base model is unavailable. Choose an accessible model.";
+ }
+ for (const role of ["extract", "keyword", "query", "vlm"] as const) {
+ const value = models[role];
+ if (
+ !Number.isInteger(value.max_async) ||
+ value.max_async < 1 ||
+ value.max_async > 32 ||
+ !Number.isInteger(value.timeout) ||
+ value.timeout < 1 ||
+ value.timeout > 3600
+ ) {
+ return "Concurrency and timeout values must stay within the displayed limits.";
+ }
+ const effective = resolvedRole(models, role);
+ if (!effective) continue;
+ const option = findOption(effective);
+ if (!option) {
+ return "One or more role models are unavailable. Choose accessible models before saving.";
+ }
+ if (role === "vlm" && option.supports_vision !== true) {
+ return "The selected VLM model does not support image inputs.";
+ }
+ if (
+ value.reasoning_effort &&
+ !option.supported_reasoning_efforts?.includes(value.reasoning_effort)
+ ) {
+ return "The selected reasoning effort is no longer supported.";
+ }
+ }
+ return null;
+}
+
export function resolvedRole(
models: LightRagRoleModels,
role: "extract" | "keyword" | "query" | "vlm",
@@ -69,6 +118,11 @@ export default function LightRagRoleModelsEditor({
const { t } = useTranslation();
return (
<div className="space-y-4">
+ <p className="text-[11px] leading-relaxed text-[var(--muted-foreground)]">
+ {t(
+ "LightRAG recommends disabling reasoning for EXTRACT and KEYWORD and enabling it for QUERY when supported.",
+ )}
+ </p>
<div className="space-y-1.5">
<IndexingModelSelector
label="LightRAG base model"
@@ -102,6 +156,11 @@ export default function LightRagRoleModelsEditor({
option.profile_id === effective?.profile_id &&
option.model_id === effective?.model_id,
);
+ const baseOption = options.find(
+ (option) =>
+ option.profile_id === models.base.profile_id &&
+ option.model_id === models.base.model_id,
+ );
const selectionKey =
value.mode === "model" && value.selection
? `${value.selection.profile_id}:${value.selection.model_id}`
@@ -157,7 +216,12 @@ export default function LightRagRoleModelsEditor({
{t("Image analysis disabled")}
</option>
)}
- <option value="inherit">
+ <option
+ value="inherit"
+ disabled={
+ role === "vlm" && baseOption?.supports_vision !== true
+ }
+ >
{t("Inherit LightRAG base model")} ·{" "}
{options.find(
(option) =>
diff --git a/web/features/knowledge/components/engines/EngineDetail.tsx b/web/features/knowledge/components/engines/EngineDetail.tsx
index b073b09c1..676634aad 100644
--- a/web/features/knowledge/components/engines/EngineDetail.tsx
+++ b/web/features/knowledge/components/engines/EngineDetail.tsx
@@ -67,6 +67,7 @@ import { useAuthStatus } from "@/hooks/useAuthStatus";
import { useLLMOptions } from "@/hooks/useLLMOptions";
import LightRagRoleModelsEditor, {
newRoleModels,
+ roleModelsValidationError,
} from "@/components/knowledge/LightRagRoleModelsEditor";
import { selectionFromLightRagDefault } from "@/components/knowledge/IndexingModelSelector";
@@ -927,10 +928,12 @@ function ToggleField({
function SaveButton({
dirty,
saving,
+ invalid = false,
onSave,
}: {
dirty: boolean;
saving: boolean;
+ invalid?: boolean;
onSave: () => void;
}) {
const { t } = useTranslation();
@@ -939,7 +942,7 @@ function SaveButton({
<button
type="button"
onClick={onSave}
- disabled={!dirty || saving}
+ disabled={!dirty || saving || invalid}
className="inline-flex items-center gap-1.5 rounded-lg bg-[var(--primary)] px-3.5 py-1.5 text-[12.5px] font-medium text-[var(--primary-foreground)] transition-opacity hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-40"
>
{saving && <Loader2 className="h-3.5 w-3.5 animate-spin" />}
@@ -1180,8 +1183,13 @@ export function LightRagModelsForm({
? newRoleModels(
legacyBase,
form.version !== 2 && legacyOption?.supports_vision === true,
+ form.llm_model_max_async,
)
: null);
+ const validationError = roleModelsValidationError(
+ roleModels,
+ catalog.options,
+ );
const save = async () => {
if (!roleModels) {
@@ -1231,9 +1239,13 @@ export function LightRagModelsForm({
"KEYWORD and QUERY apply to subsequent queries. EXTRACT and VLM apply to new or fully rebuilt indexes; published indexes keep their pinned models.",
)}
</p>
+ {validationError && (
+ <p className="text-xs text-red-600">{t(validationError)}</p>
+ )}
<SaveButton
dirty={dirty || (!form.role_models && roleModels !== null)}
saving={saving}
+ invalid={validationError !== null}
onSave={() => void save()}
/>
</fieldset>
diff --git a/web/locales/en/app.json b/web/locales/en/app.json
index abf590003..4054ebe0b 100644
--- a/web/locales/en/app.json
+++ b/web/locales/en/app.json
@@ -3996,6 +3996,7 @@
"readiness.detail.redis_available_but_memory_selected": "Redis is reachable — coordination could be switched to it",
"After publication, enabling, disabling or replacing VLM requires a full rebuild. A VLM pinned now can process later image uploads.": "After publication, enabling, disabling or replacing VLM requires a full rebuild. A VLM pinned now can process later image uploads.",
"Choose a LightRAG base model before saving.": "Choose a LightRAG base model before saving.",
+ "Concurrency and timeout values must stay within the displayed limits.": "Concurrency and timeout values must stay within the displayed limits.",
"Choose a vision model": "Choose a vision model",
"EXTRACT model": "EXTRACT model",
"Effective reasoning": "Effective reasoning",
@@ -4005,12 +4006,15 @@
"KEYWORD and QUERY apply to subsequent queries. EXTRACT and VLM apply to new or fully rebuilt indexes; published indexes keep their pinned models.": "KEYWORD and QUERY apply to subsequent queries. EXTRACT and VLM apply to new or fully rebuilt indexes; published indexes keep their pinned models.",
"Legacy model settings are shown below. Saving fixes the LightRAG base selection independently of chat.": "Legacy model settings are shown below. Saving fixes the LightRAG base selection independently of chat.",
"LightRAG base model": "LightRAG base model",
+ "LightRAG recommends disabling reasoning for EXTRACT and KEYWORD and enabling it for QUERY when supported.": "LightRAG recommends disabling reasoning for EXTRACT and KEYWORD and enabling it for QUERY when supported.",
"Model default / unspecified": "Model default / unspecified",
"Model source": "Model source",
"Only administrators can change shared LightRAG engine settings.": "Only administrators can change shared LightRAG engine settings.",
"Prefilled from the engine's EXTRACT and VLM settings. Changes here apply only to this new or rebuilt index.": "Prefilled from the engine's EXTRACT and VLM settings. Changes here apply only to this new or rebuilt index.",
"Role concurrency and timeouts apply to subsequent tasks without rebuilding.": "Role concurrency and timeouts apply to subsequent tasks without rebuilding.",
"The selected VLM model does not support image inputs.": "The selected VLM model does not support image inputs.",
+ "The LightRAG base model is unavailable. Choose an accessible model.": "The LightRAG base model is unavailable. Choose an accessible model.",
+ "The selected reasoning effort is no longer supported.": "The selected reasoning effort is no longer supported.",
"Unsupported reasoning effort": "Unsupported reasoning effort",
"VLM image analysis": "VLM image analysis",
"VLM model": "VLM model",
@@ -4025,6 +4029,8 @@
"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",
+ "One or more role models are unavailable. Choose accessible models before saving.": "One or more role models are unavailable. Choose accessible models before saving.",
+ "One or more selected indexing models are unavailable. Choose accessible models before continuing.": "One or more selected indexing models are unavailable. Choose accessible models before continuing.",
"Use engine default": "Use engine default",
"Not selected": "Not selected",
"Choose indexing models": "Choose indexing models",
diff --git a/web/locales/zh/app.json b/web/locales/zh/app.json
index 46587f864..eba195b12 100644
--- a/web/locales/zh/app.json
+++ b/web/locales/zh/app.json
@@ -3996,6 +3996,7 @@
"readiness.detail.redis_available_but_memory_selected": "Redis 可用,可以把轮次协调切到它",
"After publication, enabling, disabling or replacing VLM requires a full rebuild. A VLM pinned now can process later image uploads.": "发布后,启用、禁用或更换 VLM 均需完整重建。现在固定的 VLM 可以处理以后上传的图片。",
"Choose a LightRAG base model before saving.": "请先选择 LightRAG 基础模型再保存。",
+ "Concurrency and timeout values must stay within the displayed limits.": "并发数和超时值必须保持在界面显示的范围内。",
"Choose a vision model": "选择视觉模型",
"EXTRACT model": "EXTRACT 模型",
"Effective reasoning": "实际推理强度",
@@ -4005,12 +4006,15 @@
"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 应用于新建或完整重建的索引;已发布的索引保留固定的模型。",
"Legacy model settings are shown below. Saving fixes the LightRAG base selection independently of chat.": "下方显示旧版模型设置。保存后,LightRAG 基础模型将独立于聊天模型。",
"LightRAG base model": "LightRAG 基础模型",
+ "LightRAG recommends disabling reasoning for EXTRACT and KEYWORD and enabling it for QUERY when supported.": "LightRAG 建议关闭 EXTRACT 和 KEYWORD 的推理,并在模型支持时为 QUERY 开启推理。",
"Model default / unspecified": "模型默认值 / 未指定",
"Model source": "模型来源",
"Only administrators can change shared LightRAG engine settings.": "只有管理员可以修改共享的 LightRAG 引擎设置。",
"Prefilled from the engine's EXTRACT and VLM settings. Changes here apply only to this new or rebuilt index.": "已从引擎的 EXTRACT 和 VLM 设置预填。此处修改仅应用于本次新建或重建的索引。",
"Role concurrency and timeouts apply to subsequent tasks without rebuilding.": "角色并发数和超时设置应用于后续任务,无需重建。",
"The selected VLM model does not support image inputs.": "所选 VLM 模型不支持图片输入。",
+ "The LightRAG base model is unavailable. Choose an accessible model.": "LightRAG 基础模型不可用,请选择有权访问的模型。",
+ "The selected reasoning effort is no longer supported.": "所选推理强度已不再受支持。",
"Unsupported reasoning effort": "不支持的推理强度",
"VLM image analysis": "VLM 图片分析",
"VLM model": "VLM 模型",
@@ -4025,6 +4029,8 @@
"Used to analyze images during indexing. The model must support image input.": "用于索引时分析图片;必须选择支持视觉输入的模型。",
"Currently effective": "当前生效",
"Unavailable model": "不可用的模型",
+ "One or more role models are unavailable. Choose accessible models before saving.": "一个或多个角色模型不可用,请在保存前选择有权访问的模型。",
+ "One or more selected indexing models are unavailable. Choose accessible models before continuing.": "一个或多个索引模型不可用,请先选择有权访问的模型。",
"Use engine default": "使用引擎默认值",
"Not selected": "未选择",
"Choose indexing models": "选择索引模型",
diff --git a/web/tests/lightrag-form.spec.tsx b/web/tests/lightrag-form.spec.tsx
index 266db6ff5..76e2e8c38 100644
--- a/web/tests/lightrag-form.spec.tsx
+++ b/web/tests/lightrag-form.spec.tsx
@@ -9,7 +9,11 @@ import {
import { beforeEach, expect, it, vi } from "vitest";
import { LightRagModelsForm } from "@/features/knowledge/components/engines/EngineDetail";
-const fixture = vi.hoisted(() => ({ version: 2, save: vi.fn() }));
+const fixture = vi.hoisted(() => ({
+ version: 2,
+ maxAsync: 4,
+ save: vi.fn(),
+}));
vi.mock("react-i18next", () => ({
useTranslation: () => ({ t: (key: string) => key }),
}));
@@ -49,7 +53,7 @@ vi.mock("@/features/knowledge/api/engines", async (original) => ({
top_k: 60,
response_type: "Multiple Paragraphs",
max_concurrent_files: 1,
- llm_model_max_async: 4,
+ llm_model_max_async: fixture.maxAsync,
entity_extract_max_gleaning: 1,
}),
updateLightRagConfig: async (value: unknown) => {
@@ -57,7 +61,10 @@ vi.mock("@/features/knowledge/api/engines", async (original) => ({
return value;
},
}));
-beforeEach(() => fixture.save.mockClear());
+beforeEach(() => {
+ fixture.maxAsync = 4;
+ fixture.save.mockClear();
+});
it.each([
[2, "disabled"],
@@ -79,3 +86,18 @@ it.each([
});
},
);
+
+it("preserves the legacy base concurrency when creating role settings", async () => {
+ fixture.version = 1;
+ fixture.maxAsync = 8;
+ render(<LightRagModelsForm onChanged={vi.fn()} onError={vi.fn()} />);
+ fireEvent.click(
+ await screen.findByRole("button", { name: "Save changes" }),
+ );
+ await waitFor(() => expect(fixture.save).toHaveBeenCalledOnce());
+ const roles = fixture.save.mock.calls[0][0].role_models;
+ expect(roles.extract.max_async).toBe(8);
+ expect(roles.keyword.max_async).toBe(8);
+ expect(roles.query.max_async).toBe(8);
+ expect(roles.vlm.max_async).toBe(8);
+});
diff --git a/web/tests/lightrag-role-models.spec.tsx b/web/tests/lightrag-role-models.spec.tsx
index 609b7cd58..fe21cfc0c 100644
--- a/web/tests/lightrag-role-models.spec.tsx
+++ b/web/tests/lightrag-role-models.spec.tsx
@@ -4,6 +4,7 @@ import { describe, expect, it, vi } from "vitest";
import LightRagRoleModelsEditor, {
newRoleModels,
resolvedRole,
+ roleModelsValidationError,
} from "@/components/knowledge/LightRagRoleModelsEditor";
import LightRagIndexingSelector, {
indexingSelectionFromDefaults,
@@ -72,16 +73,32 @@ describe("LightRAG role editor", () => {
const vlm = within(screen.getByRole("group", { name: "VLM" }));
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();
+ within(mode).getByRole("option", {
+ name: "Inherit LightRAG base model · Small",
+ }),
+ ).toBeDisabled();
fireEvent.change(mode, { target: { value: "vision:large" } });
expect(resolvedRole(state(), "vlm")).toEqual(visionModel);
fireEvent.change(mode, { target: { value: "disabled" } });
expect(resolvedRole(state(), "vlm")).toBeNull();
});
+ it("rejects invalid role state before it reaches the API", () => {
+ const invalidVlm = newRoleModels(textModel);
+ invalidVlm.vlm.mode = "inherit";
+ expect(roleModelsValidationError(invalidVlm, options)).toBe(
+ "The selected VLM model does not support image inputs.",
+ );
+ const staleBase = newRoleModels({ profile_id: "gone", model_id: "gone" });
+ expect(roleModelsValidationError(staleBase, options)).toBe(
+ "The LightRAG base model is unavailable. Choose an accessible model.",
+ );
+ const invalidLimit = newRoleModels(textModel);
+ invalidLimit.query.max_async = 0;
+ expect(roleModelsValidationError(invalidLimit, options)).toBe(
+ "Concurrency and timeout values must stay within the displayed limits.",
+ );
+ });
it("preserves explicit none and limits when the base model changes", () => {
render(<Editor />);
const extract = within(screen.getByRole("group", { name: "EXTRACT" }));
@@ -226,6 +243,32 @@ it("selects a vision model without a duplicate VLM control", () => {
).not.toBeInTheDocument();
});
+it("blocks structurally complete indexing selections whose models disappeared", () => {
+ const stale: LightRagIndexingSelection = {
+ extract: { profile_id: "gone", model_id: "gone" },
+ vlm: { mode: "disabled" },
+ };
+ expect(isCompleteIndexingSelection(stale)).toBe(true);
+ expect(isCompleteIndexingSelection(stale, options)).toBe(false);
+ render(
+ <LightRagIndexingSelector
+ options={options}
+ selection={stale}
+ onChange={vi.fn()}
+ loading={false}
+ error={false}
+ />,
+ );
+ expect(
+ screen.getByText(
+ "One or more selected indexing models are unavailable. Choose accessible models before continuing.",
+ ),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole("option", { name: "Unavailable model · gone" }),
+ ).toBeDisabled();
+});
+
it("shows engine defaults in the collapsed create-index summary", () => {
const defaults: LightRagIndexingSelection = {
extract: textModel,