From 66f3fcc17b00108868c5618b7390c53e80f3f054 Mon Sep 17 00:00:00 2001 From: choizhang Date: Thu, 10 Apr 2025 23:17:33 +0800 Subject: [PATCH 1/3] feat: Add query mode 'bypass' to bypass knowledge retrieval and directly use LLM --- lightrag/api/routers/query_routes.py | 2 +- lightrag/base.py | 2 +- lightrag/lightrag.py | 8 ++++++++ lightrag_webui/src/api/lightrag.ts | 3 ++- lightrag_webui/src/components/retrieval/QuerySettings.tsx | 1 + lightrag_webui/src/locales/ar.json | 3 ++- lightrag_webui/src/locales/en.json | 3 ++- lightrag_webui/src/locales/fr.json | 3 ++- lightrag_webui/src/locales/zh.json | 3 ++- 9 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lightrag/api/routers/query_routes.py b/lightrag/api/routers/query_routes.py index c9648356..81603487 100644 --- a/lightrag/api/routers/query_routes.py +++ b/lightrag/api/routers/query_routes.py @@ -22,7 +22,7 @@ class QueryRequest(BaseModel): description="The query text", ) - mode: Literal["local", "global", "hybrid", "naive", "mix"] = Field( + mode: Literal["local", "global", "hybrid", "naive", "mix", "bypass"] = Field( default="hybrid", description="Query mode", ) diff --git a/lightrag/base.py b/lightrag/base.py index 5cf5ab61..e2b0fd32 100644 --- a/lightrag/base.py +++ b/lightrag/base.py @@ -36,7 +36,7 @@ T = TypeVar("T") class QueryParam: """Configuration parameters for query execution in LightRAG.""" - mode: Literal["local", "global", "hybrid", "naive", "mix"] = "global" + mode: Literal["local", "global", "hybrid", "naive", "mix", "bypass"] = "global" """Specifies the retrieval mode: - "local": Focuses on context-dependent information. - "global": Utilizes global knowledge. diff --git a/lightrag/lightrag.py b/lightrag/lightrag.py index 0933a4d1..386ea814 100644 --- a/lightrag/lightrag.py +++ b/lightrag/lightrag.py @@ -1381,6 +1381,14 @@ class LightRAG: hashing_kv=self.llm_response_cache, # Directly use llm_response_cache system_prompt=system_prompt, ) + elif param.mode == "bypass": + # Bypass mode: directly use LLM without knowledge retrieval + use_llm_func = param.model_func or global_config["llm_model_func"] + response = await use_llm_func( + query.strip(), + system_prompt=system_prompt, + history_messages=param.conversation_history, + ) else: raise ValueError(f"Unknown mode {param.mode}") await self._query_done() diff --git a/lightrag_webui/src/api/lightrag.ts b/lightrag_webui/src/api/lightrag.ts index bd49f7dc..98ac703f 100644 --- a/lightrag_webui/src/api/lightrag.ts +++ b/lightrag_webui/src/api/lightrag.ts @@ -65,8 +65,9 @@ export type LightragDocumentsScanProgress = { * - "global": Utilizes global knowledge. * - "hybrid": Combines local and global retrieval methods. * - "mix": Integrates knowledge graph and vector retrieval. + * - "bypass": Bypasses knowledge retrieval and directly uses the LLM. */ -export type QueryMode = 'naive' | 'local' | 'global' | 'hybrid' | 'mix' +export type QueryMode = 'naive' | 'local' | 'global' | 'hybrid' | 'mix' | 'bypass' export type Message = { role: 'user' | 'assistant' | 'system' diff --git a/lightrag_webui/src/components/retrieval/QuerySettings.tsx b/lightrag_webui/src/components/retrieval/QuerySettings.tsx index 9fca1782..f5e17cc1 100644 --- a/lightrag_webui/src/components/retrieval/QuerySettings.tsx +++ b/lightrag_webui/src/components/retrieval/QuerySettings.tsx @@ -55,6 +55,7 @@ export default function QuerySettings() { {t('retrievePanel.querySettings.queryModeOptions.global')} {t('retrievePanel.querySettings.queryModeOptions.hybrid')} {t('retrievePanel.querySettings.queryModeOptions.mix')} + {t('retrievePanel.querySettings.queryModeOptions.bypass')} diff --git a/lightrag_webui/src/locales/ar.json b/lightrag_webui/src/locales/ar.json index 36f31e92..42d9d527 100644 --- a/lightrag_webui/src/locales/ar.json +++ b/lightrag_webui/src/locales/ar.json @@ -302,7 +302,8 @@ "local": "محلي", "global": "عالمي", "hybrid": "مختلط", - "mix": "مزيج" + "mix": "مزيج", + "bypass": "تجاوز" }, "responseFormat": "تنسيق الرد", "responseFormatTooltip": "يحدد تنسيق الرد. أمثلة:\n• فقرات متعددة\n• فقرة واحدة\n• نقاط نقطية", diff --git a/lightrag_webui/src/locales/en.json b/lightrag_webui/src/locales/en.json index 13b6e5a5..96e1dd19 100644 --- a/lightrag_webui/src/locales/en.json +++ b/lightrag_webui/src/locales/en.json @@ -301,7 +301,8 @@ "local": "Local", "global": "Global", "hybrid": "Hybrid", - "mix": "Mix" + "mix": "Mix", + "bypass": "Bypass" }, "responseFormat": "Response Format", "responseFormatTooltip": "Defines the response format. Examples:\n• Multiple Paragraphs\n• Single Paragraph\n• Bullet Points", diff --git a/lightrag_webui/src/locales/fr.json b/lightrag_webui/src/locales/fr.json index dbba9480..20012f58 100644 --- a/lightrag_webui/src/locales/fr.json +++ b/lightrag_webui/src/locales/fr.json @@ -302,7 +302,8 @@ "local": "Local", "global": "Global", "hybrid": "Hybride", - "mix": "Mixte" + "mix": "Mixte", + "bypass": "Bypass" }, "responseFormat": "Format de réponse", "responseFormatTooltip": "Définit le format de la réponse. Exemples :\n• Plusieurs paragraphes\n• Paragraphe unique\n• Points à puces", diff --git a/lightrag_webui/src/locales/zh.json b/lightrag_webui/src/locales/zh.json index df4c33c3..c1f58e4b 100644 --- a/lightrag_webui/src/locales/zh.json +++ b/lightrag_webui/src/locales/zh.json @@ -302,7 +302,8 @@ "local": "Local", "global": "Global", "hybrid": "Hybrid", - "mix": "Mix" + "mix": "Mix", + "bypass": "Bypass" }, "responseFormat": "响应格式", "responseFormatTooltip": "定义响应格式。例如:\n• 多段落\n• 单段落\n• 要点", From 5b65ce5cfef97831824d8510ad7897b0a0ee1792 Mon Sep 17 00:00:00 2001 From: choizhang Date: Thu, 10 Apr 2025 23:20:54 +0800 Subject: [PATCH 2/3] docs: Translate annotations --- lightrag/api/routers/ollama_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lightrag/api/routers/ollama_api.py b/lightrag/api/routers/ollama_api.py index 9ece2680..088cd02c 100644 --- a/lightrag/api/routers/ollama_api.py +++ b/lightrag/api/routers/ollama_api.py @@ -308,7 +308,7 @@ class OllamaAPI: "Cache-Control": "no-cache", "Connection": "keep-alive", "Content-Type": "application/x-ndjson", - "X-Accel-Buffering": "no", # 确保在Nginx代理时正确处理流式响应 + "X-Accel-Buffering": "no", # Ensure proper handling of streaming responses in Nginx proxy }, ) else: From f35012572c883603262b040d1f1bafc99418c1df Mon Sep 17 00:00:00 2001 From: choizhang Date: Fri, 11 Apr 2025 11:12:01 +0800 Subject: [PATCH 3/3] docs(locales): Update multilingual files to include descriptions of bypass mode --- lightrag/lightrag.py | 2 ++ lightrag_webui/src/locales/ar.json | 2 +- lightrag_webui/src/locales/en.json | 2 +- lightrag_webui/src/locales/fr.json | 2 +- lightrag_webui/src/locales/zh.json | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lightrag/lightrag.py b/lightrag/lightrag.py index 386ea814..5647799b 100644 --- a/lightrag/lightrag.py +++ b/lightrag/lightrag.py @@ -1384,10 +1384,12 @@ class LightRAG: elif param.mode == "bypass": # Bypass mode: directly use LLM without knowledge retrieval use_llm_func = param.model_func or global_config["llm_model_func"] + param.stream = True if param.stream is None else param.stream response = await use_llm_func( query.strip(), system_prompt=system_prompt, history_messages=param.conversation_history, + stream=param.stream, ) else: raise ValueError(f"Unknown mode {param.mode}") diff --git a/lightrag_webui/src/locales/ar.json b/lightrag_webui/src/locales/ar.json index 42d9d527..641315ee 100644 --- a/lightrag_webui/src/locales/ar.json +++ b/lightrag_webui/src/locales/ar.json @@ -296,7 +296,7 @@ "parametersTitle": "المعلمات", "parametersDescription": "تكوين معلمات الاستعلام الخاص بك", "queryMode": "وضع الاستعلام", - "queryModeTooltip": "حدد استراتيجية الاسترجاع:\n• ساذج: بحث أساسي بدون تقنيات متقدمة\n• محلي: استرجاع معلومات يعتمد على السياق\n• عالمي: يستخدم قاعدة المعرفة العالمية\n• مختلط: يجمع بين الاسترجاع المحلي والعالمي\n• مزيج: يدمج شبكة المعرفة مع الاسترجاع المتجهي", + "queryModeTooltip": "حدد استراتيجية الاسترجاع:\n• ساذج: بحث أساسي بدون تقنيات متقدمة\n• محلي: استرجاع معلومات يعتمد على السياق\n• عالمي: يستخدم قاعدة المعرفة العالمية\n• مختلط: يجمع بين الاسترجاع المحلي والعالمي\n• مزيج: يدمج شبكة المعرفة مع الاسترجاع المتجهي\n• تجاوز: يمرر الاستعلام مباشرة إلى LLM بدون استرجاع", "queryModeOptions": { "naive": "ساذج", "local": "محلي", diff --git a/lightrag_webui/src/locales/en.json b/lightrag_webui/src/locales/en.json index 96e1dd19..ff20528d 100644 --- a/lightrag_webui/src/locales/en.json +++ b/lightrag_webui/src/locales/en.json @@ -295,7 +295,7 @@ "parametersTitle": "Parameters", "parametersDescription": "Configure your query parameters", "queryMode": "Query Mode", - "queryModeTooltip": "Select the retrieval strategy:\n• Naive: Basic search without advanced techniques\n• Local: Context-dependent information retrieval\n• Global: Utilizes global knowledge base\n• Hybrid: Combines local and global retrieval\n• Mix: Integrates knowledge graph with vector retrieval", + "queryModeTooltip": "Select the retrieval strategy:\n• Naive: Basic search without advanced techniques\n• Local: Context-dependent information retrieval\n• Global: Utilizes global knowledge base\n• Hybrid: Combines local and global retrieval\n• Mix: Integrates knowledge graph with vector retrieval\n• Bypass: Passes query directly to LLM without retrieval", "queryModeOptions": { "naive": "Naive", "local": "Local", diff --git a/lightrag_webui/src/locales/fr.json b/lightrag_webui/src/locales/fr.json index 20012f58..e35f744a 100644 --- a/lightrag_webui/src/locales/fr.json +++ b/lightrag_webui/src/locales/fr.json @@ -296,7 +296,7 @@ "parametersTitle": "Paramètres", "parametersDescription": "Configurez vos paramètres de requête", "queryMode": "Mode de requête", - "queryModeTooltip": "Sélectionnez la stratégie de récupération :\n• Naïf : Recherche de base sans techniques avancées\n• Local : Récupération d'informations dépendante du contexte\n• Global : Utilise une base de connaissances globale\n• Hybride : Combine récupération locale et globale\n• Mixte : Intègre le graphe de connaissances avec la récupération vectorielle", + "queryModeTooltip": "Sélectionnez la stratégie de récupération :\n• Naïf : Recherche de base sans techniques avancées\n• Local : Récupération d'informations dépendante du contexte\n• Global : Utilise une base de connaissances globale\n• Hybride : Combine récupération locale et globale\n• Mixte : Intègre le graphe de connaissances avec la récupération vectorielle\n• Bypass : Transmet directement la requête au LLM sans récupération", "queryModeOptions": { "naive": "Naïf", "local": "Local", diff --git a/lightrag_webui/src/locales/zh.json b/lightrag_webui/src/locales/zh.json index c1f58e4b..60e2b7c8 100644 --- a/lightrag_webui/src/locales/zh.json +++ b/lightrag_webui/src/locales/zh.json @@ -296,7 +296,7 @@ "parametersTitle": "参数", "parametersDescription": "配置查询参数", "queryMode": "查询模式", - "queryModeTooltip": "选择检索策略:\n• Naive:基础搜索,无高级技术\n• Local:上下文相关信息检索\n• Global:利用全局知识库\n• Hybrid:结合本地和全局检索\n• Mix:整合知识图谱和向量检索", + "queryModeTooltip": "选择检索策略:\n• Naive:基础搜索,无高级技术\n• Local:上下文相关信息检索\n• Global:利用全局知识库\n• Hybrid:结合本地和全局检索\n• Mix:整合知识图谱和向量检索\n• Bypass:直接传递查询到LLM,不进行检索", "queryModeOptions": { "naive": "Naive", "local": "Local",