Skip to content

Commit c82485d

Browse files
authored
Merge pull request HKUDS#2253 from Mobious/main
Allow users to provide keywords with QueryRequest
2 parents 97a2ee4 + f24a261 commit c82485d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

‎lightrag/api/routers/query_routes.py‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ class QueryRequest(BaseModel):
7373
ge=1,
7474
)
7575

76+
hl_keywords: list[str] = Field(
77+
default_factory=list,
78+
description="List of high-level keywords to prioritize in retrieval. Leave empty to use the LLM to generate the keywords.",
79+
)
80+
81+
ll_keywords: list[str] = Field(
82+
default_factory=list,
83+
description="List of low-level keywords to refine retrieval focus. Leave empty to use the LLM to generate the keywords.",
84+
)
85+
7686
conversation_history: Optional[List[Dict[str, Any]]] = Field(
7787
default=None,
7888
description="Stores past conversation history to maintain context. Format: [{'role': 'user/assistant', 'content': 'message'}].",
@@ -294,6 +304,16 @@ async def query_text(request: QueryRequest):
294304
}
295305
```
296306
307+
Bypass initial LLM call by providing high-level and low-level keywords:
308+
```json
309+
{
310+
"query": "What is Retrieval-Augmented-Generation?",
311+
"hl_keywords": ["machine learning", "information retrieval", "natural language processing"],
312+
"ll_keywords": ["retrieval augmented generation", "RAG", "knowledge base"],
313+
"mode": "mix"
314+
}
315+
```
316+
297317
Advanced query with references:
298318
```json
299319
{
@@ -482,6 +502,16 @@ async def query_text_stream(request: QueryRequest):
482502
}
483503
```
484504
505+
Bypass initial LLM call by providing high-level and low-level keywords:
506+
```json
507+
{
508+
"query": "What is Retrieval-Augmented-Generation?",
509+
"hl_keywords": ["machine learning", "information retrieval", "natural language processing"],
510+
"ll_keywords": ["retrieval augmented generation", "RAG", "knowledge base"],
511+
"mode": "mix"
512+
}
513+
```
514+
485515
Complete response query:
486516
```json
487517
{
@@ -968,6 +998,16 @@ async def query_data(request: QueryRequest):
968998
}
969999
```
9701000
1001+
Bypass initial LLM call by providing high-level and low-level keywords:
1002+
```json
1003+
{
1004+
"query": "What is Retrieval-Augmented-Generation?",
1005+
"hl_keywords": ["machine learning", "information retrieval", "natural language processing"],
1006+
"ll_keywords": ["retrieval augmented generation", "RAG", "knowledge base"],
1007+
"mode": "mix"
1008+
}
1009+
```
1010+
9711011
**Response Analysis:**
9721012
- **Empty arrays**: Normal for certain modes (e.g., naive mode has no entities/relationships)
9731013
- **Processing info**: Shows retrieval statistics and token usage

0 commit comments

Comments
 (0)