DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
feat(knowledge): expose LightRAG's indexing knobs in the engine settings
Bingxi Zhao (Frank)4a68ccea1eab
diff --git a/deeptutor/api/routers/knowledge.py b/deeptutor/api/routers/knowledge.pyindex 0628fbd39..8db846287 100644--- a/deeptutor/api/routers/knowledge.py+++ b/deeptutor/api/routers/knowledge.py@@ -1374,7 +1374,7 @@ class LightRagConfigUpdate(BaseModel):@router.get("/rag-pipelines/lightrag/config")async def get_lightrag_pipeline_config():- """Read LightRAG's query knobs (top_k, response style)."""+ """Read LightRAG's query knobs plus its indexing concurrency/extraction knobs."""try:from deeptutor.services.config import get_runtime_settings_service@@ -1386,7 +1386,12 @@ async def get_lightrag_pipeline_config():@router.put("/rag-pipelines/lightrag/config")async def update_lightrag_pipeline_config(payload: LightRagConfigUpdate):- """Persist LightRAG's query knobs. Takes effect on the next query."""+ """Persist LightRAG's knobs.++ Query knobs (``top_k``, ``response_type``) take effect on the next query;+ the indexing knobs shape how a KB is built, so they apply to the next+ build or rebuild.+ """try:from deeptutor.services.config import get_runtime_settings_servicediff --git a/tests/api/test_knowledge_router.py b/tests/api/test_knowledge_router.pyindex bd2633c98..bf4789528 100644--- a/tests/api/test_knowledge_router.py+++ b/tests/api/test_knowledge_router.py@@ -1872,3 +1872,49 @@ def test_upload_progress_counts_completed_files_and_reports_reliable_stages(("Saving metadata...", 1, 1),("Successfully processed 1 files!", 1, 1),]+++def test_lightrag_config_endpoint_round_trips_the_indexing_knobs(+ monkeypatch, tmp_path: Path+) -> None:+ """The contract the settings UI edits: GET exposes the knobs, PUT keeps them.++ EngineDetail's LightRAG form reads every field off this payload and sends+ all five back on save, so a field the router drops is a field the UI+ silently cannot change.+ """+ from deeptutor.services.config.runtime_settings import RuntimeSettingsService++ service = RuntimeSettingsService(tmp_path, process_env={})+ monkeypatch.setattr(+ "deeptutor.services.config.get_runtime_settings_service",+ lambda: service,+ )++ client = TestClient(_build_app())++ initial = client.get("/api/v1/knowledge/rag-pipelines/lightrag/config")+ assert initial.status_code == 200+ for key in ("top_k", "response_type", "max_concurrent_files", "llm_model_max_async"):+ assert key in initial.json(), f"{key} missing from the payload the UI reads"++ saved = client.put(+ "/api/v1/knowledge/rag-pipelines/lightrag/config",+ json={+ "top_k": 42,+ "response_type": "Single Paragraph",+ "max_concurrent_files": 4,+ "llm_model_max_async": 8,+ "entity_extract_max_gleaning": 2,+ },+ )+ assert saved.status_code == 200+ assert saved.json()["max_concurrent_files"] == 4+ assert saved.json()["llm_model_max_async"] == 8+ assert saved.json()["entity_extract_max_gleaning"] == 2++ # And they survive a reload rather than living only in the response.+ again = client.get("/api/v1/knowledge/rag-pipelines/lightrag/config").json()+ assert again["max_concurrent_files"] == 4+ assert again["entity_extract_max_gleaning"] == 2+ assert again["top_k"] == 42diff --git a/tests/services/config/test_graphrag_lightrag_settings.py b/tests/services/config/test_graphrag_lightrag_settings.pyindex d9dfdf85e..d736e0317 100644--- a/tests/services/config/test_graphrag_lightrag_settings.py+++ b/tests/services/config/test_graphrag_lightrag_settings.py@@ -41,6 +41,60 @@ def test_lightrag_defaults_and_clamp(tmp_path: Path) -> None:assert floored["top_k"] == 1 # clamped to min+def test_lightrag_indexing_knobs_round_trip_and_clamp(tmp_path: Path) -> None:+ """The indexing knobs the settings UI edits, with the ranges it offers.++ The NumberField min/max in EngineDetail's LightRAG form mirror these+ clamps, so a value the UI accepts is a value the service keeps.+ """+ svc = RuntimeSettingsService(tmp_path, process_env={})+ defaults = svc.load_lightrag()+ assert defaults["max_concurrent_files"] == 1+ assert defaults["llm_model_max_async"] == 4+ assert defaults["entity_extract_max_gleaning"] == 1++ saved = svc.save_lightrag(+ {+ "max_concurrent_files": 4,+ "llm_model_max_async": 8,+ "entity_extract_max_gleaning": 0,+ }+ )+ assert saved["max_concurrent_files"] == 4+ assert saved["llm_model_max_async"] == 8+ assert saved["entity_extract_max_gleaning"] == 0++ clamped = svc.save_lightrag(+ {+ "max_concurrent_files": 999,+ "llm_model_max_async": 0,+ "entity_extract_max_gleaning": 99,+ }+ )+ assert clamped["max_concurrent_files"] == 16+ assert clamped["llm_model_max_async"] == 1+ assert clamped["entity_extract_max_gleaning"] == 5++ # Editing one knob must not reset the query knobs beside it.+ assert clamped["top_k"] == 60+ assert clamped["response_type"] == "Multiple Paragraphs"+++def test_lightrag_settings_written_before_the_indexing_knobs_still_load(+ tmp_path: Path,+) -> None:+ """A lightrag.json from before these knobs existed gets the defaults."""+ (tmp_path / "lightrag.json").write_text(+ '{"version": 1, "top_k": 25, "response_type": "Single Paragraph"}',+ encoding="utf-8",+ )+ loaded = RuntimeSettingsService(tmp_path, process_env={}).load_lightrag()+ assert loaded["top_k"] == 25+ assert loaded["max_concurrent_files"] == 1+ assert loaded["llm_model_max_async"] == 4+ assert loaded["entity_extract_max_gleaning"] == 1++def test_response_type_capped(tmp_path: Path) -> None:svc = RuntimeSettingsService(tmp_path, process_env={})saved = svc.save_graphrag({"response_type": "x" * 500})diff --git a/web/components/knowledge/EngineDetail.tsx b/web/components/knowledge/EngineDetail.tsxindex 42656690f..ce276f215 100644--- a/web/components/knowledge/EngineDetail.tsx+++ b/web/components/knowledge/EngineDetail.tsx@@ -877,6 +877,9 @@ function LightRagForm({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,});setLoaded(next);setForm(next);@@ -903,6 +906,47 @@ function LightRagForm({onChange={(v) => patch({ response_type: v })}/></div>++ {/* 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. */}+ <div className="space-y-4 border-t border-[var(--border)] pt-4">+ <div className="space-y-0.5">+ <div className="text-[12px] font-medium text-[var(--foreground)]">+ {t("Indexing")}+ </div>+ <div className="text-[11px] text-[var(--muted-foreground)]">+ {t("Applies the next time a knowledge base is built or rebuilt.")}+ </div>+ </div>+ <div className="grid grid-cols-1 gap-4 sm:grid-cols-2">+ <NumberField+ label={t("Files in parallel")}+ hint={t("Higher finishes sooner but uses more memory")}+ value={form.max_concurrent_files}+ min={1}+ max={16}+ onChange={(v) => patch({ max_concurrent_files: v })}+ />+ <NumberField+ label={t("Concurrent LLM calls")}+ hint={t("Lower this if your provider rate-limits you")}+ value={form.llm_model_max_async}+ min={1}+ max={32}+ onChange={(v) => patch({ llm_model_max_async: v })}+ />+ <NumberField+ label={t("Extra extraction passes")}+ hint={t("Recovers missed entities; each pass costs another call")}+ value={form.entity_extract_max_gleaning}+ min={0}+ max={5}+ onChange={(v) => patch({ entity_extract_max_gleaning: v })}+ />+ </div>+ </div>+<SaveButton dirty={dirty} saving={saving} onSave={() => void save()} /></div>);diff --git a/web/lib/knowledge-api.ts b/web/lib/knowledge-api.tsindex b90db7440..6468eb83e 100644--- a/web/lib/knowledge-api.ts+++ b/web/lib/knowledge-api.ts@@ -74,6 +74,12 @@ export interface LightRagConfig {version: number;top_k: number;response_type: string;+ /** Files RAG-Anything processes in parallel while indexing. */+ max_concurrent_files: number;+ /** Concurrent LLM calls LightRAG's internal queue issues. */+ llm_model_max_async: number;+ /** Extra extraction passes per chunk, to recover missed entities. */+ entity_extract_max_gleaning: number;}export interface PreflightCheck {diff --git a/web/locales/en/app.json b/web/locales/en/app.jsonindex 118dfe1b1..3931e3718 100644--- a/web/locales/en/app.json+++ b/web/locales/en/app.json@@ -3200,5 +3200,13 @@"Nothing in this view": "Nothing in this view","Switch to another filter to see your other questions.": "Switch to another filter to see your other questions.","Showing {{shown}} of {{total}} — narrow the view to see the rest.": "Showing {{shown}} of {{total}} — narrow the view to see the rest.",- "Delete this category? The questions themselves stay in your bank.": "Delete this category? The questions themselves stay in your bank."+ "Delete this category? The questions themselves stay in your bank.": "Delete this category? The questions themselves stay in your bank.",+ "Indexing": "Indexing",+ "Applies the next time a knowledge base is built or rebuilt.": "Applies the next time a knowledge base is built or rebuilt.",+ "Files in parallel": "Files in parallel",+ "Higher finishes sooner but uses more memory": "Higher finishes sooner but uses more memory",+ "Concurrent LLM calls": "Concurrent LLM calls",+ "Lower this if your provider rate-limits you": "Lower this if your provider rate-limits you",+ "Extra extraction passes": "Extra extraction passes",+ "Recovers missed entities; each pass costs another call": "Recovers missed entities; each pass costs another call"}diff --git a/web/locales/zh/app.json b/web/locales/zh/app.jsonindex 375db84ab..c02408c03 100644--- a/web/locales/zh/app.json+++ b/web/locales/zh/app.json@@ -3200,5 +3200,13 @@"Nothing in this view": "此视图下没有内容","Switch to another filter to see your other questions.": "切换筛选条件查看其他题目。","Showing {{shown}} of {{total}} — narrow the view to see the rest.": "已显示 {{shown}} / {{total}} 条 —— 缩小范围可查看其余。",- "Delete this category? The questions themselves stay in your bank.": "删除这个分类?题目本身会保留在题库里。"+ "Delete this category? The questions themselves stay in your bank.": "删除这个分类?题目本身会保留在题库里。",+ "Indexing": "索引",+ "Applies the next time a knowledge base is built or rebuilt.": "下次构建或重建知识库时生效。",+ "Files in parallel": "并行处理文件数",+ "Higher finishes sooner but uses more memory": "调高更快完成,但占用更多内存",+ "Concurrent LLM calls": "并发 LLM 调用数",+ "Lower this if your provider rate-limits you": "如果提供商限流,请调低",+ "Extra extraction passes": "额外抽取轮数",+ "Recovers missed entities; each pass costs another call": "补捞漏掉的实体;每轮多消耗一次调用"}