LightRAG README

The project's README from github.com/HKUDS/LightRAG. As one markdown file: README.md.

LightRAG Logo

🚀 LightRAG: Simple and Fast Retrieval-Augmented Generation

HKUDS%2FLightRAG | Trendshift

LightRAG Diagram

LiteWrite

🎉 News

Algorithm Flowchart

LightRAG Indexing Flowchart Figure 1: LightRAG Indexing Flowchart - Img Caption : Source LightRAG Retrieval and Querying Flowchart Figure 2: LightRAG Retrieval and Querying Flowchart - Img Caption : Source

Installation

💡 Using uv for Package Management: This project uses uv for fast and reliable Python package management. Install uv first: curl -LsSf https://astral.sh/uv/install.sh | sh (Unix/macOS) or powershell -c "irm https://astral.sh/uv/install.ps1 | iex" (Windows)

Note: You can also use pip if you prefer, but uv is recommended for better performance and more reliable dependency management.

📦 Offline Deployment: For offline or air-gapped environments, see the Offline Deployment Guide for instructions on pre-installing all dependencies and cache files.

Install LightRAG Server

### Install LightRAG Server as tool using uv (recommended)
uv tool install "lightrag-hku[api]"

### Or using pip
# python -m venv .venv
# source .venv/bin/activate  # Windows: .venv\Scripts\activate
# pip install "lightrag-hku[api]"

# Setup env file
# Obtain the env.example file by downloading it from the GitHub repository root
# or by copying it from a local source checkout.
cp env.example .env  # Update the .env with your LLM and embedding configurations
# Launch the server. It binds to all interfaces (0.0.0.0) by default.
# SECURITY: before exposing it on a network, configure authentication in .env
# (LIGHTRAG_API_KEY, or AUTH_ACCOUNTS together with TOKEN_SECRET), or bind to
# 127.0.0.1 for local-only access; without auth every endpoint is public.
# Note: the Ollama-compatible /api/* routes stay open by default for client
# compatibility; set WHITELIST_PATHS=/health to require auth on them too.
lightrag-server
git clone https://github.com/HKUDS/LightRAG.git
cd LightRAG

# Bootstrap the development environment (recommended)
make dev
source .venv/bin/activate  # Activate the virtual environment (Linux/macOS)
# Or on Windows: .venv\Scripts\activate

# make dev installs the test toolchain plus the full offline stack
# (API, storage backends, and provider integrations), then builds the frontend.
# Run make env-base or copy env.example to .env before starting the server.

# Equivalent manual steps with uv
# Note: uv sync automatically creates a virtual environment in .venv/
uv sync --extra test --extra offline
source .venv/bin/activate  # Activate the virtual environment (Linux/macOS)
# Or on Windows: .venv\Scripts\activate

### Or using pip with virtual environment
# python -m venv .venv
# source .venv/bin/activate  # Windows: .venv\Scripts\activate
# pip install -e ".[test,offline]"

# Build front-end artifacts
cd lightrag_webui
bun install --frozen-lockfile
bun run build
cd ..

# setup env file
make env-base  # Or: cp env.example .env and update it manually
# Launch API-WebUI server
lightrag-server
git clone https://github.com/HKUDS/LightRAG.git
cd LightRAG
cp env.example .env  # Update the .env with your LLM and embedding configurations
# modify LLM and Embedding settings in .env
docker compose up

Historical versions of LightRAG docker images can be found here: LightRAG Docker Images

Official GHCR images published by GitHub Actions are signed with Sigstore Cosign using GitHub OIDC. See docs/DockerDeployment.md for verification commands.

On Apple Silicon (macOS 26) without Docker Desktop, you can run the same Postgres/Neo4j/Milvus storage stack on Apple's native container runtime — see docs/AppleContainerSetup.md.

Create .env File With Setup Tool

Instead of editing env.example by hand, use the interactive setup wizard to generate a configured .env and, when needed, docker-compose.final.yml:

make env-base           # Required first step: LLM, embedding, reranker
make env-storage        # Optional: storage backends and database services
make env-server         # Optional: server port, auth, and SSL
make env-base-rewrite   # Optional: force-regenerate wizard-managed compose services
make env-storage-rewrite # Optional: force-regenerate wizard-managed compose services
make env-security-check # Optional: audit the current .env for security risks

For full description of every target see docs/InteractiveSetup.md.

Optional: spaCy Models for docx smart_heading

The native docx parser's opt-in smart_heading engine parameter uses spaCy for sentence/NER heuristics. The spaCy runtime is already included in the api extra — only the two pinned language models (zh_core_web_sm / en_core_web_sm 3.8.0, GitHub release wheels not published on PyPI) need one extra step:

lightrag-download-cache --spacy-install

Enable smart_heading per file/rule (e.g. LIGHTRAG_PARSER=docx:native(smart_heading=true)), or globally in .env:

# .docx files routed to the native engine get smart_heading by default;
# opt a file back out with an explicit native(smart_heading=false) rule/hint.
DOCX_SMART_HEADING=true

When the global switch is on (or a LIGHTRAG_PARSER rule carries native(smart_heading=true)), the server verifies the models at startup and fails fast with install guidance if they are missing. Deployments that never enable smart_heading need no models. The main Docker image ships the models pre-installed (the lite image does not); for air-gapped hosts see the Offline Deployment Guide.

Optional: libcairo for SVG Rasterization (native md/textpack)

The native markdown/textpack parser rasterizes embedded SVG images to PNG via cairosvg. cairosvg is a cffi binding: pip install cairosvg (pulled in by the api extra) always succeeds, but rendering only works if the native libcairo shared library is also present on the host — pip/uv cannot install system libraries. Without it, rasterization fails at runtime and the affected SVG is skipped (the rest of the document is unaffected); the server logs a warning at startup so the gap is visible before it shows up as a per-document warning later.

Install the system package for your platform:

# Debian / Ubuntu (the official Docker image already includes this)
sudo apt-get install -y libcairo2

# RHEL / Fedora
sudo dnf install -y cairo

# macOS (Homebrew)
brew install cairo

# Windows: install the GTK3 runtime, which bundles libcairo-2.dll

Deployments that never process markdown/textpack documents with embedded SVGs can ignore the startup warning.

About LightRAG

A Lightweight, Graph-Based RAG Framework

LightRAG is a lightweight knowledge-graph RAG framework and an efficient alternative to Microsoft GraphRAG. It adopts a dual-layer architecture to manage both knowledge graphs (KGs) and vector embeddings, effectively bridging the gap between traditional vector-based RAG and graph-based RAG approaches. Designed for high scalability, LightRAG addresses key challenges in large-scale graph indexing and retrieval, including heavy computational overhead, slow response times, and the high cost of incremental updates. While supporting large datasets, LightRAG can still deliver exceptionally high RAG quality, even when paired with a 30B open-source large language model (LLM).

Features & Advantages

Multimodal Capability Upgrades

Traditional RAG systems lack an effective way to process multimodal content such as images, formulas, and tables in documents. Starting with v1.5, LightRAG seamlessly integrates multimodal processing into its document pipeline and query flow. Through the knowledge graph, LightRAG connects multimodal content with the body text and can use that information when answering queries to produce more accurate and reliable responses. This capability can substantially improve RAG quality for documents rich in multimodal content, such as operation manuals and academic papers.

LightRAG API Server

The LightRAG server offers not only a web-based UI for exploring LightRAG functionalities but also a comprehensive REST API. For more information about the LightRAG server, please refer to LightRAG Server.

iShot_2025-03-23_12.40.08

Key Configuration Guide

Selecting LLM Models

LightRAG requires LLM/VLMs of four different roles during its workflow

LightRAG (HKUDS/LightRAG)

Searching Database…

40.2K ·GitHub
这是什么?LightRAG 是 HKUDS 开发的开源图结构 RAG 框架(发表于 EMNLP 2025)。它把你的文档索引成知识图谱加上向量嵌入,方便你进行查询——是 Microsoft GraphRAG 之外一个更轻量、更快速的选择。
它是一个需要写代码调用的库,还是一个拿来就能运行的应用?两者都是:它是一个可以集成到自己代码里的 Python 框架,同时自带一个服务器,提供网页界面来插入、查询和可视化你的知识库,还有一整套完善的 REST API。
我怎么把它跑起来?用 uv(推荐)或 pip 从 PyPI 安装,或者用 Docker Compose 启动服务器。然后运行交互式设置向导生成一个配置好的 .env 文件,不用手动去改 env.example。
我需要自己准备大语言模型吗?是的——模型由你自己提供:LLM/VLM 分为四个角色(EXTRACT、QUERY、KEYWORDS 和 VLM),每个角色都有独立的设置。图抽取用 Qwen3-30B-A3B 这类开源模型效果也不错。
默认的存储配置能直接用于生产环境吗?不行。默认的内存版 KV、向量和图存储加上本地文件持久化,只适合小规模测试;要在生产环境处理大数据集,推荐使用 PostgreSQL(Neo4j、MongoDB 和 OpenSearch 也可以)。
它最适合处理哪些领域的资料?知识密集型行业:README 特别提到需要全局理解或逻辑推理的法律和金融工作。它的设计目标还包括在大型数据集上保持高效,同时维持较高的 RAG 质量。
能在完全不联网的隔离服务器上运行吗?可以——有一份专门的离线部署指南,介绍如何为隔离主机预先安装所有依赖和缓存文件,而且官方 Docker 镜像用 Sigstore Cosign 签名,方便校验。
它和普通的向量 RAG 有什么区别?它在向量嵌入之外还会索引一个知识图谱,并在两个层面进行检索——具体事实和更宽泛的概念——能捕捉到基于分块的搜索漏掉的实体关系。它省去了社区报告和多跳推理,从而减少 LLM 调用次数、降低延迟和成本。
它能导入哪些文档格式?通过 RAG-Anything 集成:PDF、图片、Office 文档、表格和公式。解析由 MinerU、Docling 或内置的 Native 引擎完成,其中内置引擎还能处理 Word 和 Markdown 文件里的图片、表格和公式。
更新知识库时需要把所有内容重新索引一遍吗?不需要——文档可以增量添加,删除某个文档会自动触发知识图谱重建,并复用索引时的 LLM 缓存,只重建受影响的实体和关系。
我能衡量它回答得好不好吗?可以——它集成了 RAGAS 用于评估、Langfuse 用于追踪,而且 API 可以在返回查询结果的同时附上检索到的上下文,方便你对上下文的精确度打分。
Creator
HKUDS
Size
114.9 MB
Stars
40.2K
Age
2y
Commits · 90 Days