GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — LightRAG/RUNBOOK_BatchQuery.md at main · Lathezero/LightRAG

Expand file tree

/

RUNBOOK_BatchQuery.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
150 lines (132 loc) · 6.44 KB
/

RUNBOOK_BatchQuery.md

Copy path

File metadata and controls

150 lines (132 loc) · 6.44 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

LightRAG 批量提问专用手册(/query/batch 与 /query/data/batch)

本手册聚焦“批量提问”能力:如何一次提交多条问题给 LightRAG 服务器,并获取答案或结构化检索数据。内容包含前置条件、请求体参数说明、curl 与 PowerShell 一行命令示例、响应结构以及大规模批量(如 500 条问题)的实践建议。

前置条件

  • 已启动 LightRAG 服务器(默认端口 9621):
    • 访问 Swagger:http://localhost:9621/docs
    • 访问 ReDoc:http://localhost:9621/redoc
    • 健康检查:curl.exe http://localhost:9621/health
  • 如开启了认证:
    • API Key:在请求头添加 X-API-Key: <你的KEY>
    • JWT:在请求头添加 Authorization: Bearer <你的JWT>
  • 问题文件(可选):每行一个问题,例:examples/questions_sample.txt

端点与能力概览

  • POST /query/batch:批量问答(RAG + LLM),返回每条问题的生成答案,引用可选。
  • POST /query/data/batch:批量结构化检索数据(不调用 LLM),返回实体、关系、chunks 与引用。

请求体(关键参数)

  • queries(必填):字符串数组,每个元素是一条问题;每条至少 3 个字符。
  • mode(选填):local / global / hybrid / naive / mix / bypass,推荐 mix。
  • top_k(选填):实体/关系检索范围(用于知识图谱检索)。
  • chunk_top_k(选填):初始向量检索返回的文本片段数量。
  • include_references(选填,默认 True):是否在响应中返回文档引用信息。
  • include_chunk_content(选填,默认 False):在引用中包含 chunk 文本内容(响应更长)。
  • max_concurrent(选填,默认 4):批量并发度上限。

其他高级参数(如 only_need_context、only_need_prompt、response_type、hl_keywords、ll_keywords、conversation_history、user_prompt、enable_rerank 等)通常无需设置,按需使用即可。

快速开始示例

1) 使用 curl(直接提交三条问题)

curl -X POST "http://localhost:9621/query/batch" \
  -H "Content-Type: application/json" \
  -d "{
    \"queries\":[
      \"请解释什么是检索增强生成(RAG)以及它的优势?\",
      \"如何在本系统中选择适合的查询模式(local/global/mix)?\",
      \"向量检索中的 top_k 和 chunk_top_k 有什么区别?\"
    ],
    \"mode\":\"mix\",
    \"include_references\":true,
    \"max_concurrent\":4
  }"
  • 含认证(示例):
curl -X POST "http://localhost:9621/query/batch" \
  -H "Content-Type: application/json" \
  -H "X-API-Key: <你的KEY>" \
  -H "Authorization: Bearer <你的JWT>" \
  -d "{ ...同上... }"

2) PowerShell 一行命令(从 txt 文件读取)

$qs = Get-Content .\examples\questions_sample.txt | Where-Object { $_.Trim().Length -ge 3 }
$body = @{ queries = $qs; mode = 'mix'; include_references = $true; max_concurrent = 4 } | ConvertTo-Json
Invoke-RestMethod -Method Post -Uri http://localhost:9621/query/batch -ContentType 'application/json' -Body $body
  • 含认证(示例):
Invoke-RestMethod -Method Post -Uri http://localhost:9621/query/batch \
  -Headers @{ 'X-API-Key' = '<你的KEY>'; 'Authorization' = 'Bearer <你的JWT>' } \
  -ContentType 'application/json' -Body $body

3) 结构化数据批量(不走 LLM)

curl -X POST "http://localhost:9621/query/data/batch" \
  -H "Content-Type: application/json" \
  -d "{
    \"queries\": [\"neural network architectures\", \"machine learning algorithms\"],
    \"mode\": \"mix\",
    \"chunk_top_k\": 5,
    \"max_concurrent\": 4
  }"

4) 法一:Python 脚本读取 txt 并调用批量接口

  • 脚本路径:examples/batch_query_from_file.py

  • 示例命令:

    • 指定模式与并发:
      • python examples/batch_query_from_file.py --file examples/questions_sample.txt --mode mix --max-concurrent 4 --include-references --output out/results.json
    • 保存为 Markdown 汇总(更易读,便于预览):
      • python examples/batch_query_from_file.py --file examples/questions_sample.txt --include-references --save-md out/results.md
  • 参数说明:

    • --file:txt 文件路径(每行一个问题)。
    • --endpoint:默认 http://localhost:9621/query/batch。
    • --mode:local/global/hybrid/naive/mix/bypass,推荐 mix。
    • --top-k、--chunk-top-k:检索范围控制(不设则用后端默认)。
    • --include-references:返回引用信息。
    • --include-chunk-content:引用中包含 chunk 内容(响应较长)。
    • --max-concurrent:批量并发控制,默认 4。
    • --limit:仅取前 N 个问题做测试。
    • --api-key / --token:认证用(API Key 或 JWT)。
    • --output:保存结果到文件,.json 写完整响应;.ndjson/.jsonl 每行一个结果项。
    • --save-md:保存可读的 Markdown 汇总文件,包含每个问题、回答与引用。

响应结构

/query/batch(问答)

{
  "results": [
    {
      "response": "...生成答案...",
      "references": [
        { "reference_id": "1", "file_path": "/documents/ai_overview.pdf", "content": ["...chunk1...", "...chunk2..."] }
      ]
    },
    { "response": "...", "references": [] }
  ]
}
  • references 在 include_references=true 时返回;
  • content 仅在 include_chunk_content=true 时返回,且为“同一个文件可能对应多个文本片段”的数组。

/query/data/batch(结构化数据)

{
  "results": [
    {
      "status": "success",
      "message": "Query executed successfully",
      "data": {
        "entities": [ { "entity_name": "Neural Networks", "entity_type": "CONCEPT", ... } ],
        "relationships": [ { "src_id": "Neural Networks", "tgt_id": "Machine Learning", ... } ],
        "chunks": [ { "content": "...", "file_path": "...", "chunk_id": "...", "reference_id": "1" } ],
        "references": [ { "reference_id": "1", "file_path": "..." } ]
      },
      "metadata": { "query_mode": "mix", "keywords": { ... }, "processing_info": { ... } }
    }
  ]
}

附:txt 文件示例

路径:examples/questions_sample.txt

请解释什么是检索增强生成(RAG)以及它的优势?
如何在本系统中选择适合的查询模式(local/global/mix)?
向量检索中的 top_k 和 chunk_top_k 有什么区别?
如何根据引用的来源定位原始文档内容?
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.