Skip to content

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

feat(rag): expose LightRAG llm_timeout so extraction LLM timeouts are tunable

wumajiehechuan-labcf61846076bb
diff --git a/deeptutor/api/routers/knowledge.py b/deeptutor/api/routers/knowledge.py
index 794385ace..a78ba651e 100644
--- a/deeptutor/api/routers/knowledge.py
+++ b/deeptutor/api/routers/knowledge.py
@@ -1489,6 +1489,7 @@ class LightRagConfigUpdate(BaseModel):
max_concurrent_files: int | None = None
llm_model_max_async: int | None = None
entity_extract_max_gleaning: int | None = None
+ llm_timeout: int | None = None
llm_profile_id: str | None = None
llm_model_id: str | None = None
diff --git a/deeptutor/services/config/runtime_settings.py b/deeptutor/services/config/runtime_settings.py
index 09900a4bc..7fb36c35f 100644
--- a/deeptutor/services/config/runtime_settings.py
+++ b/deeptutor/services/config/runtime_settings.py
@@ -356,6 +356,9 @@ DEFAULT_LIGHTRAG_SETTINGS: dict[str, Any] = {
"max_concurrent_files": 1,
"llm_model_max_async": 4,
"entity_extract_max_gleaning": 1,
+ # Maps to LightRAG's ``default_llm_timeout`` (seconds). LightRAG derives its
+ # worker execution cap as 2x this value, so 240 -> a 480s per-call ceiling.
+ "llm_timeout": 240,
"llm_profile_id": "",
"llm_model_id": "",
}
@@ -978,6 +981,9 @@ class RuntimeSettingsService:
"entity_extract_max_gleaning": _coerce_clamped_int(
settings.get("entity_extract_max_gleaning"), 1, 0, 5
),
+ "llm_timeout": _coerce_clamped_int(
+ settings.get("llm_timeout"), 240, 60, 3600
+ ),
"llm_profile_id": _string(settings.get("llm_profile_id"))[:128],
"llm_model_id": _string(settings.get("llm_model_id"))[:128],
}
diff --git a/deeptutor/services/rag/pipelines/lightrag/config.py b/deeptutor/services/rag/pipelines/lightrag/config.py
index 6f45e3365..292ba16a0 100644
--- a/deeptutor/services/rag/pipelines/lightrag/config.py
+++ b/deeptutor/services/rag/pipelines/lightrag/config.py
@@ -186,6 +186,7 @@ def constructor_kwargs_from_settings() -> dict:
return {
"llm_model_max_async": int(settings.get("llm_model_max_async", 4)),
"entity_extract_max_gleaning": int(settings.get("entity_extract_max_gleaning", 1)),
+ "default_llm_timeout": int(settings.get("llm_timeout", 240)),
}
except Exception:
return {}
diff --git a/tests/services/config/test_graphrag_lightrag_settings.py b/tests/services/config/test_graphrag_lightrag_settings.py
index 4cf3b4720..212d507ee 100644
--- a/tests/services/config/test_graphrag_lightrag_settings.py
+++ b/tests/services/config/test_graphrag_lightrag_settings.py
@@ -52,6 +52,7 @@ def test_lightrag_indexing_knobs_round_trip_and_clamp(tmp_path: Path) -> None:
assert defaults["max_concurrent_files"] == 1
assert defaults["llm_model_max_async"] == 4
assert defaults["entity_extract_max_gleaning"] == 1
+ assert defaults["llm_timeout"] == 240
assert defaults["llm_profile_id"] == ""
assert defaults["llm_model_id"] == ""
@@ -60,22 +61,26 @@ def test_lightrag_indexing_knobs_round_trip_and_clamp(tmp_path: Path) -> None:
"max_concurrent_files": 4,
"llm_model_max_async": 8,
"entity_extract_max_gleaning": 0,
+ "llm_timeout": 480,
}
)
assert saved["max_concurrent_files"] == 4
assert saved["llm_model_max_async"] == 8
assert saved["entity_extract_max_gleaning"] == 0
+ assert saved["llm_timeout"] == 480
clamped = svc.save_lightrag(
{
"max_concurrent_files": 999,
"llm_model_max_async": 0,
"entity_extract_max_gleaning": 99,
+ "llm_timeout": 99999,
}
)
assert clamped["max_concurrent_files"] == 16
assert clamped["llm_model_max_async"] == 1
assert clamped["entity_extract_max_gleaning"] == 5
+ assert clamped["llm_timeout"] == 3600 # clamped to max
# Editing one knob must not reset the query knobs beside it.
assert clamped["top_k"] == 60
assert clamped["response_type"] == "Multiple Paragraphs"
@@ -94,6 +99,7 @@ def test_lightrag_settings_written_before_the_indexing_knobs_still_load(
assert loaded["max_concurrent_files"] == 1
assert loaded["llm_model_max_async"] == 4
assert loaded["entity_extract_max_gleaning"] == 1
+ assert loaded["llm_timeout"] == 240
assert loaded["llm_profile_id"] == ""
assert loaded["llm_model_id"] == ""
diff --git a/tests/services/rag/test_lightrag_settings_wiring.py b/tests/services/rag/test_lightrag_settings_wiring.py
index 4b9f7ad0d..176fc6008 100644
--- a/tests/services/rag/test_lightrag_settings_wiring.py
+++ b/tests/services/rag/test_lightrag_settings_wiring.py
@@ -43,7 +43,11 @@ def test_native_constructor_receives_every_supported_knob(monkeypatch, tmp_path:
monkeypatch.setattr(
engine,
"constructor_kwargs_from_settings",
- lambda: {"llm_model_max_async": 8, "entity_extract_max_gleaning": 2},
+ lambda: {
+ "llm_model_max_async": 8,
+ "entity_extract_max_gleaning": 2,
+ "default_llm_timeout": 480,
+ },
)
rag = engine.build_rag(tmp_path)
@@ -56,6 +60,7 @@ def test_native_constructor_receives_every_supported_knob(monkeypatch, tmp_path:
assert rag.kwargs["max_parallel_parse_native"] == 4
assert rag.kwargs["llm_model_max_async"] == 8
assert rag.kwargs["entity_extract_max_gleaning"] == 2
+ assert rag.kwargs["default_llm_timeout"] == 480
assert rag.kwargs["vlm_process_enable"] is False
assert rag.kwargs["llm_model_name"] == "query-fingerprint"
assert set(rag.kwargs["role_llm_configs"]) == {"keyword", "query"}
diff --git a/web/contracts/generated/api.ts b/web/contracts/generated/api.ts
index 4e0342db5..366c778b4 100644
--- a/web/contracts/generated/api.ts
+++ b/web/contracts/generated/api.ts
@@ -10966,6 +10966,8 @@ export interface components {
readonly llm_model_max_async?: number | null;
/** Llm Profile Id */
readonly llm_profile_id?: string | null;
+ /** Llm Timeout */
+ readonly llm_timeout?: number | null;
/** Max Concurrent Files */
readonly max_concurrent_files?: number | null;
/** Response Type */
diff --git a/web/contracts/schema/openapi.json b/web/contracts/schema/openapi.json
index 9c2862f3e..ee51617f7 100644
--- a/web/contracts/schema/openapi.json
+++ b/web/contracts/schema/openapi.json
@@ -4387,6 +4387,17 @@
],
"title": "Llm Profile Id"
},
+ "llm_timeout": {
+ "anyOf": [
+ {
+ "type": "integer"
+ },
+ {
+ "type": "null"
+ }
+ ],
+ "title": "Llm Timeout"
+ },
"max_concurrent_files": {
"anyOf": [
{