lightrag
БесплатноБез исполняемых скриптовНе проверенGraph-based RAG library and server that extracts entities and relationships from documents into a knowledge graph and answers questions with local, global…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
LightRAG — graph-based retrieval over your documents
Overview
LightRAG indexes documents twice: it splits them into chunks stored as vectors, and it asks an LLM to extract entities and relationships from each chunk to build a knowledge graph. At query time it can follow the graph (good for "how are these things connected" and summary-style questions), search the chunk vectors (good for exact facts), or combine both.
It comes in two forms. The Python package lightrag-hku is the library: you create a LightRAG object, insert text and query it. The same package, installed with the api extra, provides lightrag-server, a FastAPI service with a web UI, document upload and query endpoints, configured through a .env file. An agent can install either, write the configuration, run the server and call its endpoints. The LLM and embedding model must exist; the extraction step makes many LLM calls, so use a capable model.
Instructions
Install
The PyPI package is lightrag-hku (installed version checked: 1.5.7).
python3 -m venv .venv
.venv/bin/pip install lightrag-hku # library only
.venv/bin/pip install "lightrag-hku[api]" # library + lightrag-server
With uv, the server can be installed as a tool: uv tool install "lightrag-hku[api]".
Library: create, insert, query
initialize_storages() is an async method that must be awaited before the first insert or query. Forgetting it is the most common failure. The following mirrors the repository's OpenAI demo and reads the key from OPENAI_API_KEY:
import asyncio
from lightrag import LightRAG, QueryParam
from lightrag.llm.openai import gpt_4o_mini_complete, openai_embed
async def main():
rag = LightRAG(
working_dir="./rag_storage",
embedding_func=openai_embed,
llm_model_func=gpt_4o_mini_complete,
)
await rag.initialize_storages()
await rag.ainsert(open("handbook.txt", encoding="utf-8").read())
answer = await rag.aquery(
"Which teams own the on-call rotation?",
param=QueryParam(mode="mix"),
)
print(answer)
await rag.finalize_storages()
asyncio.run(main())
insert and query are synchronous wrappers. ainsert takes a string or a list of strings, with optional ids and file_paths so answers can cite their source. working_dir holds the graph, vectors and cache; reuse the same directory to keep the index.
Query modes
QueryParam(mode=...) accepts local, global, hybrid, naive, mix and bypass. The default is mix.
| Mode | Retrieval |
|---|---|
local |
entities and their neighbourhood (specific, context-dependent questions) |
global |
relationships and themes (broad questions) |
hybrid |
local plus global |
naive |
plain vector search over chunks, no graph |
mix |
knowledge graph plus vector search |
bypass |
skips retrieval and sends the question to the LLM |
QueryParam(only_need_context=True) returns the retrieved context instead of an answer, which is useful for debugging retrieval. rag.aquery_data(...) returns the retrieved data in structured form.
Run the server
Create the configuration file from the repository's env.example (download it from the repository root, or run make env-base in a clone for an interactive wizard):
cp env.example .env
Edit .env. The variables the server reads for models include LLM_BINDING, LLM_MODEL, LLM_BINDING_HOST, LLM_BINDING_API_KEY, EMBEDDING_BINDING, EMBEDDING_MODEL and EMBEDDING_DIM. Server settings include HOST, PORT, WORKING_DIR and INPUT_DIR. A local Ollama setup looks like:
HOST=127.0.0.1
PORT=9621
LLM_BINDING=ollama
LLM_MODEL=qwen3:8b
LLM_BINDING_HOST=http://127.0.0.1:11434
EMBEDDING_BINDING=ollama
EMBEDDING_MODEL=bge-m3
EMBEDDING_DIM=1024
EMBEDDING_BINDING_HOST=http://127.0.0.1:11434
Start it and check health:
.venv/bin/lightrag-server
curl -s http://127.0.0.1:9621/health
The default is HOST=0.0.0.0, PORT=9621, and with no authentication every endpoint is public. The health response reports the version, the configured bindings and the working directory. Interactive API docs are served by the app (FastAPI /docs), and the web UI is on the same port.
For Docker, clone the repository, create .env the same way and run docker compose up.
Server API
Endpoints (verified from the installed server's OpenAPI document):
POST /documents/upload— multipart form with afilefield.POST /documents/text— JSON body withtextand optionalfile_source;POST /documents/textsinserts several.POST /documents/scan— index files placed inINPUT_DIR.GET /documents/track_status/{track_id},GET /documents/pipeline_status,GET /documents/status_counts,POST /documents/paginated— follow indexing.DELETE /documents/delete_document— JSON body{"doc_ids": [...]}.POST /query,POST /query/stream,POST /query/data— body h
Установить lightrag в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл lightrag?
Graph-based RAG library and server that extracts entities and relationships from documents into a knowledge graph and answers questions with local, global, hybrid or mix retrieval. Use when someone asks to "build a graph RAG over my documents", "run lightrag-server", "insert text and query with LightRAG", "pick a QueryParam mode", or "expose a RAG API with a web UI".
Как установить скилл lightrag?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл lightrag запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic