choizhang
commited on
Commit
·
e0cb5fa
1
Parent(s):
3757a93
feat: Add query mode 'bypass' to bypass knowledge retrieval and directly use LLM
Browse files- lightrag/api/routers/query_routes.py +1 -1
- lightrag/base.py +1 -1
- lightrag/lightrag.py +8 -0
- lightrag_webui/src/api/lightrag.ts +2 -1
- lightrag_webui/src/components/retrieval/QuerySettings.tsx +1 -0
- lightrag_webui/src/locales/ar.json +2 -1
- lightrag_webui/src/locales/en.json +2 -1
- lightrag_webui/src/locales/fr.json +2 -1
- lightrag_webui/src/locales/zh.json +2 -1
lightrag/api/routers/query_routes.py
CHANGED
@@ -22,7 +22,7 @@ class QueryRequest(BaseModel):
|
|
22 |
description="The query text",
|
23 |
)
|
24 |
|
25 |
-
mode: Literal["local", "global", "hybrid", "naive", "mix"] = Field(
|
26 |
default="hybrid",
|
27 |
description="Query mode",
|
28 |
)
|
|
|
22 |
description="The query text",
|
23 |
)
|
24 |
|
25 |
+
mode: Literal["local", "global", "hybrid", "naive", "mix", "bypass"] = Field(
|
26 |
default="hybrid",
|
27 |
description="Query mode",
|
28 |
)
|
lightrag/base.py
CHANGED
@@ -36,7 +36,7 @@ T = TypeVar("T")
|
|
36 |
class QueryParam:
|
37 |
"""Configuration parameters for query execution in LightRAG."""
|
38 |
|
39 |
-
mode: Literal["local", "global", "hybrid", "naive", "mix"] = "global"
|
40 |
"""Specifies the retrieval mode:
|
41 |
- "local": Focuses on context-dependent information.
|
42 |
- "global": Utilizes global knowledge.
|
|
|
36 |
class QueryParam:
|
37 |
"""Configuration parameters for query execution in LightRAG."""
|
38 |
|
39 |
+
mode: Literal["local", "global", "hybrid", "naive", "mix", "bypass"] = "global"
|
40 |
"""Specifies the retrieval mode:
|
41 |
- "local": Focuses on context-dependent information.
|
42 |
- "global": Utilizes global knowledge.
|
lightrag/lightrag.py
CHANGED
@@ -1381,6 +1381,14 @@ class LightRAG:
|
|
1381 |
hashing_kv=self.llm_response_cache, # Directly use llm_response_cache
|
1382 |
system_prompt=system_prompt,
|
1383 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1384 |
else:
|
1385 |
raise ValueError(f"Unknown mode {param.mode}")
|
1386 |
await self._query_done()
|
|
|
1381 |
hashing_kv=self.llm_response_cache, # Directly use llm_response_cache
|
1382 |
system_prompt=system_prompt,
|
1383 |
)
|
1384 |
+
elif param.mode == "bypass":
|
1385 |
+
# Bypass mode: directly use LLM without knowledge retrieval
|
1386 |
+
use_llm_func = param.model_func or global_config["llm_model_func"]
|
1387 |
+
response = await use_llm_func(
|
1388 |
+
query.strip(),
|
1389 |
+
system_prompt=system_prompt,
|
1390 |
+
history_messages=param.conversation_history,
|
1391 |
+
)
|
1392 |
else:
|
1393 |
raise ValueError(f"Unknown mode {param.mode}")
|
1394 |
await self._query_done()
|
lightrag_webui/src/api/lightrag.ts
CHANGED
@@ -65,8 +65,9 @@ export type LightragDocumentsScanProgress = {
|
|
65 |
* - "global": Utilizes global knowledge.
|
66 |
* - "hybrid": Combines local and global retrieval methods.
|
67 |
* - "mix": Integrates knowledge graph and vector retrieval.
|
|
|
68 |
*/
|
69 |
-
export type QueryMode = 'naive' | 'local' | 'global' | 'hybrid' | 'mix'
|
70 |
|
71 |
export type Message = {
|
72 |
role: 'user' | 'assistant' | 'system'
|
|
|
65 |
* - "global": Utilizes global knowledge.
|
66 |
* - "hybrid": Combines local and global retrieval methods.
|
67 |
* - "mix": Integrates knowledge graph and vector retrieval.
|
68 |
+
* - "bypass": Bypasses knowledge retrieval and directly uses the LLM.
|
69 |
*/
|
70 |
+
export type QueryMode = 'naive' | 'local' | 'global' | 'hybrid' | 'mix' | 'bypass'
|
71 |
|
72 |
export type Message = {
|
73 |
role: 'user' | 'assistant' | 'system'
|
lightrag_webui/src/components/retrieval/QuerySettings.tsx
CHANGED
@@ -55,6 +55,7 @@ export default function QuerySettings() {
|
|
55 |
<SelectItem value="global">{t('retrievePanel.querySettings.queryModeOptions.global')}</SelectItem>
|
56 |
<SelectItem value="hybrid">{t('retrievePanel.querySettings.queryModeOptions.hybrid')}</SelectItem>
|
57 |
<SelectItem value="mix">{t('retrievePanel.querySettings.queryModeOptions.mix')}</SelectItem>
|
|
|
58 |
</SelectGroup>
|
59 |
</SelectContent>
|
60 |
</Select>
|
|
|
55 |
<SelectItem value="global">{t('retrievePanel.querySettings.queryModeOptions.global')}</SelectItem>
|
56 |
<SelectItem value="hybrid">{t('retrievePanel.querySettings.queryModeOptions.hybrid')}</SelectItem>
|
57 |
<SelectItem value="mix">{t('retrievePanel.querySettings.queryModeOptions.mix')}</SelectItem>
|
58 |
+
<SelectItem value="bypass">{t('retrievePanel.querySettings.queryModeOptions.bypass')}</SelectItem>
|
59 |
</SelectGroup>
|
60 |
</SelectContent>
|
61 |
</Select>
|
lightrag_webui/src/locales/ar.json
CHANGED
@@ -302,7 +302,8 @@
|
|
302 |
"local": "محلي",
|
303 |
"global": "عالمي",
|
304 |
"hybrid": "مختلط",
|
305 |
-
"mix": "مزيج"
|
|
|
306 |
},
|
307 |
"responseFormat": "تنسيق الرد",
|
308 |
"responseFormatTooltip": "يحدد تنسيق الرد. أمثلة:\n• فقرات متعددة\n• فقرة واحدة\n• نقاط نقطية",
|
|
|
302 |
"local": "محلي",
|
303 |
"global": "عالمي",
|
304 |
"hybrid": "مختلط",
|
305 |
+
"mix": "مزيج",
|
306 |
+
"bypass": "تجاوز"
|
307 |
},
|
308 |
"responseFormat": "تنسيق الرد",
|
309 |
"responseFormatTooltip": "يحدد تنسيق الرد. أمثلة:\n• فقرات متعددة\n• فقرة واحدة\n• نقاط نقطية",
|
lightrag_webui/src/locales/en.json
CHANGED
@@ -301,7 +301,8 @@
|
|
301 |
"local": "Local",
|
302 |
"global": "Global",
|
303 |
"hybrid": "Hybrid",
|
304 |
-
"mix": "Mix"
|
|
|
305 |
},
|
306 |
"responseFormat": "Response Format",
|
307 |
"responseFormatTooltip": "Defines the response format. Examples:\n• Multiple Paragraphs\n• Single Paragraph\n• Bullet Points",
|
|
|
301 |
"local": "Local",
|
302 |
"global": "Global",
|
303 |
"hybrid": "Hybrid",
|
304 |
+
"mix": "Mix",
|
305 |
+
"bypass": "Bypass"
|
306 |
},
|
307 |
"responseFormat": "Response Format",
|
308 |
"responseFormatTooltip": "Defines the response format. Examples:\n• Multiple Paragraphs\n• Single Paragraph\n• Bullet Points",
|
lightrag_webui/src/locales/fr.json
CHANGED
@@ -302,7 +302,8 @@
|
|
302 |
"local": "Local",
|
303 |
"global": "Global",
|
304 |
"hybrid": "Hybride",
|
305 |
-
"mix": "Mixte"
|
|
|
306 |
},
|
307 |
"responseFormat": "Format de réponse",
|
308 |
"responseFormatTooltip": "Définit le format de la réponse. Exemples :\n• Plusieurs paragraphes\n• Paragraphe unique\n• Points à puces",
|
|
|
302 |
"local": "Local",
|
303 |
"global": "Global",
|
304 |
"hybrid": "Hybride",
|
305 |
+
"mix": "Mixte",
|
306 |
+
"bypass": "Bypass"
|
307 |
},
|
308 |
"responseFormat": "Format de réponse",
|
309 |
"responseFormatTooltip": "Définit le format de la réponse. Exemples :\n• Plusieurs paragraphes\n• Paragraphe unique\n• Points à puces",
|
lightrag_webui/src/locales/zh.json
CHANGED
@@ -302,7 +302,8 @@
|
|
302 |
"local": "Local",
|
303 |
"global": "Global",
|
304 |
"hybrid": "Hybrid",
|
305 |
-
"mix": "Mix"
|
|
|
306 |
},
|
307 |
"responseFormat": "响应格式",
|
308 |
"responseFormatTooltip": "定义响应格式。例如:\n• 多段落\n• 单段落\n• 要点",
|
|
|
302 |
"local": "Local",
|
303 |
"global": "Global",
|
304 |
"hybrid": "Hybrid",
|
305 |
+
"mix": "Mix",
|
306 |
+
"bypass": "Bypass"
|
307 |
},
|
308 |
"responseFormat": "响应格式",
|
309 |
"responseFormatTooltip": "定义响应格式。例如:\n• 多段落\n• 单段落\n• 要点",
|