A lightweight Knowledge Graph Retrieval-Augmented Generation system with multiple LLM backend support.
# Linux/MacOS
git clone https://github.com/HKUDS/LightRAG.git
cd LightRAG# Windows PowerShell
git clone https://github.com/HKUDS/LightRAG.git
cd LightRAG# Linux/MacOS
cp env.example .env
# Edit .env with your preferred configuration# Windows PowerShell
Copy-Item env.example .env
# Edit .env with your preferred configurationLightRAG can be configured using environment variables in the .env file:
Server Configuration
HOST: Server host (default: 0.0.0.0)PORT: Server port (default: 9621)
LLM Configuration
LLM_BINDING: LLM backend to use (lollms/ollama/openai)LLM_BINDING_HOST: LLM server host URLLLM_MODEL: Model name to use
Embedding Configuration
EMBEDDING_BINDING: Embedding backend (lollms/ollama/openai)EMBEDDING_BINDING_HOST: Embedding server host URLEMBEDDING_MODEL: Embedding model nameEMBEDDING_ASYMMETRIC: Explicitly enable query/document asymmetric embeddingsEMBEDDING_DOCUMENT_PREFIX: Document prefix for prefix-based asymmetric embeddings (orNO_PREFIX)EMBEDDING_QUERY_PREFIX: Query prefix for prefix-based asymmetric embeddings (orNO_PREFIX)
See Asymmetric Embedding Configuration for prefix validation rules and provider-specific behavior.
RAG Configuration
MAX_ASYNC_LLM: Base maximum LLM concurrency (deprecated alias:MAX_ASYNC). It also sets the per-document chunk-extraction task limit, while each entity/relation merge phase uses twice that task limit; see File Processing Pipeline Specification for the full pipeline and role-override rules.MAX_TOTAL_TOKENS: Maximum total token budget for query context (entities, relations, and text chunks).EMBEDDING_DIM: Embedding dimensions
Docker instructions work the same on all platforms with Docker Desktop installed.
The Dockerfile uses BuildKit cache mounts to significantly improve build performance:
- Automatic cache management: BuildKit is automatically enabled via
# syntax=docker/dockerfile:1directive - Faster rebuilds: Only downloads changed dependencies when
uv.lockorbun.lockfiles are modified - Efficient package caching: UV and Bun package downloads are cached across builds
- No manual configuration needed: Works out of the box in Docker Compose and GitHub Actions
docker compose up -dIf you used the interactive setup, start the generated stack with:
docker compose -f docker-compose.final.yml up -dThe interactive setup keeps .env host-usable. Container-only hostnames such as postgres or host.docker.internal, along with staged SSL paths under /app/data/certs/, are injected into the generated docker-compose.final.yml for the lightrag service instead of being persisted back into .env.
On reruns, unchanged wizard-managed service blocks in docker-compose.final.yml are preserved by
default. To repair or fully regenerate those managed blocks from the bundled templates, rerun the
matching setup target with make env-base-rewrite or make env-storage-rewrite.
If the generated stack includes local Milvus, compose resolves MINIO_ACCESS_KEY_ID and
MINIO_SECRET_ACCESS_KEY at startup from the repo .env or exported shell environment. The
generated compose file does not snapshot those values, and docker compose exits immediately if
either variable is missing.
Before exposing the generated stack beyond localhost, run:
make env-security-checkThat command audits the current .env for missing authentication, unsafe whitelist settings, weak
JWT secrets, and other setup-level security risks without rewriting any files.
LightRAG Server uses the following paths for data storage:
data/
├── rag_storage/ # RAG data persistence
└── inputs/ # Input documents
The official images run the server as a non-root user (lightrag, uid/gid 1000) to satisfy CIS Docker Benchmark 4.1. The behavior is designed so existing deployments keep working on upgrade:
- The container starts as root, takes ownership of the writable data directories, then drops to uid 1000 via
gosu. This means existing root-owned bind-mount / PVC data is adopted automatically — no manualchownis needed when upgrading from an older image. - Ownership is fixed for
/app/dataand any custom locations you set viaWORKING_DIR,INPUT_DIR,PROMPT_DIR, orTIKTOKEN_CACHE_DIR, so pointing data outside/app/datastill works. - If you instead start the container with an explicit non-root user (Compose
user: "1000:1000"or KubernetesrunAsUser: 1000), the startupchownis skipped — make sure the mounted directories are already owned by that uid. .envis not chowned, so the host keeps ownership and you can edit it freely. It only needs to be readable by uid 1000, which the default0644permission satisfies. A.envmounted read-only as0600/0400owned by a different uid will fail to load (clearPermissionErrorat startup); make it readable by uid 1000, or supply configuration via environment variables instead (env_file:/environment:, or k8senv/envFrom).
Passing server flags still works as before, e.g. docker run ghcr.io/hkuds/lightrag:latest --port 9622.
Note: the image starts as root and drops privileges at runtime (the pattern used by the official PostgreSQL/Redis images), so the running process is non-root while the image's configured
USERis still root. Scanners that judge CIS 4.1 purely from theUSERdirective may still flag the image even though no server process runs as root.
To run embedding and/or reranking locally with vLLM, run make env-base and answer yes when prompted to run the embedding model and rerank service locally via Docker.
That configures the embedding service to use BAAI/bge-m3 on port 8001 with a local vLLM server, and can also add a vllm-rerank service on port 8000.
Alternatively, rerun make env-base later and enable only the rerank Docker prompt to add the vllm-rerank service automatically.
vLLM provides a v1/rerank endpoint that works with the cohere binding.
Example docker-compose.override.yml for GPU hosts (embedding + reranker):
services:
vllm-embed:
image: vllm/vllm-openai:latest
runtime: nvidia
command: >
--model BAAI/bge-m3
--port 8001
--dtype float16
ports:
- "8001:8001"
volumes:
- ./data/hf-cache:/root/.cache/huggingface
ipc: host
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
vllm-rerank:
image: vllm/vllm-openai:latest
runtime: nvidia
command: >
--model BAAI/bge-reranker-v2-m3
--port 8000
--dtype float16
ports:
- "8000:8000"
volumes:
- ./data/hf-cache:/root/.cache/huggingface
ipc: host
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]For CPU-only hosts, use the official CPU image instead:
services:
vllm-embed:
image: vllm/vllm-openai-cpu:latest
command: >
--model BAAI/bge-m3
--port 8001
--dtype float32
ports:
- "8001:8001"
volumes:
- ./data/hf-cache:/root/.cache/huggingface
vllm-rerank:
image: vllm/vllm-openai-cpu:latest
command: >
--model BAAI/bge-reranker-v2-m3
--port 8000
--dtype float32
ports:
- "8000:8000"
volumes:
- ./data/hf-cache:/root/.cache/huggingfaceAdd the embedding and rerank config to .env:
EMBEDDING_BINDING=openai
EMBEDDING_MODEL=BAAI/bge-m3
EMBEDDING_DIM=1024
EMBEDDING_BINDING_HOST=http://localhost:8001/v1
EMBEDDING_BINDING_API_KEY=local-key
VLLM_EMBED_DEVICE=cpu
RERANK_BINDING=cohere
RERANK_MODEL=BAAI/bge-reranker-v2-m3
RERANK_BINDING_HOST=http://localhost:8000/rerank
RERANK_BINDING_API_KEY=local-key
VLLM_RERANK_DEVICE=cpuIf LightRAG runs in Docker while vLLM runs on the host, the generated compose file rewrites those endpoints to:
EMBEDDING_BINDING_HOST=http://host.docker.internal:8001/v1
RERANK_BINDING_HOST=http://host.docker.internal:8000/rerankFor GPU, set:
VLLM_EMBED_DEVICE=cuda
VLLM_RERANK_DEVICE=cudaEnsure the NVIDIA Container Toolkit is installed and the host has CUDA drivers available.
The setup wizard uses the CPU image by default for cpu device and the GPU image for cuda device.
When rerunning make env-base, an existing VLLM_EMBED_DEVICE / VLLM_RERANK_DEVICE value is
preserved instead of being overwritten by a fresh GPU auto-detection result.
Those templates already pin the matching vLLM --dtype (float32 on CPU, float16 on CUDA), so no separate VLLM_*_DTYPE environment variables are needed.
The setup wizard stages TLS certificate files under ./data/certs/ before generating the compose file.
This keeps generated host mounts under the same ./data root used by the default Docker deployment.
docker-compose.yml and docker-compose-full.yml mount ./data/ui_templates
read-only at /app/data/ui_templates and set UI_TEMPLATES_DIR to it. That
entry overrides the same key in .env, like WORKING_DIR and INPUT_DIR, so
one .env full of host paths keeps serving a source run as well. Both stay
inert until the directory actually holds a bundle: with no manifest.json
in it the server logs a warning naming the directory and serves its built-in
branding, so the default deployment starts normally. Drop a bundle in and
restart, and the server replaces the welcome page, the login-page text and user
agreement, the query empty state, the copyright line and the brand logo with the
bundle's content — per language, without rebuilding the frontend. From that point on the bundle
is validated in full: an invalid one makes the server refuse to start.
Create the directory before the first up so it is not created root-owned by
Docker:
mkdir -p ./data/ui_templates
cp -r docs/ui_templates_example/* ./data/ui_templates/Podman: docker-compose.podman.yml keeps the mount and UI_TEMPLATES_DIR
commented out, because Podman is stricter than Docker about a bind mount whose
host source is missing. There, create the directory first and then uncomment
both — uncommenting the environment entry alone leaves the server pointed
at a path that is not mounted, and it refuses to start.
See UserDefinedUI.md (中文) for the bundle format and the full deployment guide.
The interactive setup defaults PostgreSQL to the official pgvector image, pgvector/pgvector:pg18-trixie. pgvector is the only extension the PostgreSQL storages need: PGVectorStorage uses it, and PGTableGraphStorage, the PostgreSQL graph storage, keeps the entity-relation graph in ordinary indexed tables. The tag is a multi-architecture manifest covering linux/amd64 and linux/arm64.
On first start the image creates the user, password, and database from the POSTGRES_USER / POSTGRES_PASSWORD / POSTGRES_DB environment variables. The setup wizard prompts for these values (defaulting to rag / rag / lightrag) and injects them into the generated docker-compose.final.yml, so you can choose any user, password, and database name.
Deployments on PGGraphStorage. PGGraphStorage is deprecated and will be removed in a future release. It needs Apache AGE, which the pgvector image does not have. The wizard offers PGGraphStorage only to a deployment whose .env already selects it. Such a deployment can keep it: the wizard then generates the PostgreSQL service with gzdaniel/postgres-for-rag:pg18-age-pgvector, the image earlier versions used for everyone, and a rerun keeps the image of a PostgreSQL service it already manages. To leave AGE behind, follow Migrate from PGGraphStorage to PGTableGraphStorage below.
Please note that data file formats are incompatible across different PostgreSQL major versions; once this Docker image is deployed, it cannot be rolled back to a previous version.
The graph is copied without re-indexing the documents, and every step that reads or removes the AGE graph needs the AGE image, so the image is switched last. Run the steps in order from the directory that holds docker-compose.final.yml. The commands use the wizard's default user rag and database lightrag; substitute the POSTGRES_USER and POSTGRES_DB of your postgres service.
-
Back up the database.
pg_dumpneeds AGE to read the graph tables, so take the backup now, on the AGE image:docker compose -f docker-compose.final.yml exec -T postgres \ pg_dump -U rag -d lightrag -Fc > lightrag-before-graph-migration.dump
-
Copy the graph. The tool ships with LightRAG 1.5.7 and later, so update the LightRAG image first (
pull, orbuildfor an image you build locally). Stop the server, then run the tool in a one-off container of thelightragservice. That container reads the mounted.envand the service'senvironment:block, so it reaches thepostgresservice and the workspace the server uses. Run it without--applyfirst: the dry run reports what the real run will do.docker compose -f docker-compose.final.yml pull lightrag docker compose -f docker-compose.final.yml stop lightrag docker compose -f docker-compose.final.yml run --rm --no-deps lightrag \ python -m lightrag.tools.migrate_graph_storage docker compose -f docker-compose.final.yml run --rm --no-deps lightrag \ python -m lightrag.tools.migrate_graph_storage --apply
Go on only when the apply run exits 0 and reports
'verified': True. If other servers keep their graphs in the same database under other workspaces, migrate each of them the same way (--workspace <name>) before step 4. README_MIGRATE_GRAPH_STORAGE.md has the preconditions, the refusals and the report fields. -
Switch the server. Choose
PGTableGraphStoragewithmake env-storage, start the stack withdocker compose -f docker-compose.final.yml up -d, and check the graph, for example in the WebUI graph view. The wizard keeps the image of the PostgreSQL service it already manages, so the database still runs the AGE image and the old graph is untouched. To roll back, do it before the server ingests new documents, because anything written after the switch exists only in the new tables. The wizard no longer offersPGGraphStorageonce.envselects another graph storage, so setLIGHTRAG_GRAPH_STORAGE=PGGraphStoragein.envby hand and restart the server withdocker compose -f docker-compose.final.yml up -d --force-recreate lightrag. -
Remove the AGE graph once you no longer need to roll back, still on the AGE image. This drops the AGE graph of every workspace in the database, so every workspace must have been migrated:
docker compose -f docker-compose.final.yml exec -T postgres \ psql -U rag -d lightrag -v ON_ERROR_STOP=1 \ -c "SELECT ag_catalog.drop_graph(name::text, true) FROM ag_catalog.ag_graph" \ -c "DROP EXTENSION age"
Do not skip this step. PostgreSQL and LightRAG both start on the pgvector image with the AGE graph still in the database, but the graph tables use AGE's column type, so every later
pg_dumpfails withcould not access file "age". If the image was already switched, remove the graph without AGE instead: each AGE graph is a schema of the same name, listed bySELECT name FROM ag_catalog.ag_graph; runDROP SCHEMA <name> CASCADEfor each one, thenDROP EXTENSION age. -
Switch the image. The wizard never replaces the image of a PostgreSQL service it already manages, so edit the
image:line of thepostgresservice indocker-compose.final.ymltopgvector/pgvector:pg18-trixieby hand, then recreate the container withdocker compose -f docker-compose.final.yml up -d postgres. (make env-storage-rewritealso writes the template image, but it regenerates every wizard-managed service and drops your other edits to them.) That tag has the same Debian base as the AGE image, so the existing data volume opens as it is. The plainpgvector/pgvector:pg18tag is built on an older Debian, and PostgreSQL then warns about a collation version mismatch on every connection to a database the AGE image created.
Only PGGraphStorage needs Apache AGE. An AGE-enabled image can be built from the repository root with Dockerfile.postgres. The Dockerfile starts from pgvector/pgvector:pg18-trixie, builds Apache AGE for PostgreSQL 18, and installs an init script that creates both the vector and age extensions for new databases.
For local development or single-host deployment:
docker build -f Dockerfile.postgres \
-t gzdaniel/postgres-for-rag:pg18-age-pgvector \
.To publish the image to your own registry, use a private tag:
docker build -f Dockerfile.postgres \
-t registry.example.com/postgres-for-rag:pg18-age-pgvector \
.
docker push registry.example.com/postgres-for-rag:pg18-age-pgvectorFor a multi-architecture image:
docker buildx build \
--platform linux/amd64,linux/arm64 \
-f Dockerfile.postgres \
-t registry.example.com/postgres-for-rag:pg18-age-pgvector \
--push \
.After building a custom tag, update the postgres.image value in the generated docker-compose.final.yml to point at that tag. On later setup wizard reruns, existing wizard-managed service images are preserved.
To update the Docker container:
docker compose pull
docker compose down
docker compose upSoftware packages requiring transformers, torch, or cuda are not preinstalled in the docker images. Consequently, document extraction tools such as Docling, as well as local LLM models like Hugging Face and LMDeploy, cannot be used in an offline environment. These high-compute-resource-demanding services should not be integrated into LightRAG. Docling will be decoupled and deployed as a standalone service.
The main image bundles everything the native docx parser's opt-in smart_heading engine parameter needs: the spaCy runtime plus the pinned zh_core_web_sm / en_core_web_sm 3.8.0 models are baked in at build time, so smart_heading works fully offline out of the box. The lite image ships the spaCy runtime (it comes with the api extra) but not the models — enabling smart_heading there requires installing them first (lightrag-download-cache --spacy-install, or see OfflineDeployment.md for air-gapped hosts).
# Build and run with Docker Compose (BuildKit automatically enabled)
docker compose up --build
# Or explicitly enable BuildKit if needed
DOCKER_BUILDKIT=1 docker compose up --buildNote: BuildKit is automatically enabled by the # syntax=docker/dockerfile:1 directive in the Dockerfile, ensuring optimal caching performance.
multi-architecture build and push:
# Use the provided build script
./docker-build-push.shThe build script will:
- Check Docker registry login status
- Create/use buildx builder automatically
- Build for both AMD64 and ARM64 architectures
- Push to GitHub Container Registry (ghcr.io)
- Verify the multi-architecture manifest
Prerequisites:
Before building multi-architecture images, ensure you have:
- Docker 20.10+ with Buildx support
- Sufficient disk space (20GB+ recommended for offline image)
- Registry access credentials (if pushing images)
Official LightRAG images published to GitHub Container Registry by GitHub Actions are signed with Sigstore Cosign using GitHub OIDC keyless signing.
Install cosign, then verify the image tag you want to run:
cosign verify ghcr.io/HKUDS/LightRAG:<tag> \
--certificate-identity-regexp '^https://github.com/HKUDS/LightRAG/.github/workflows/(docker-publish|docker-build-manual|docker-build-lite)\.yml@refs/.+$' \
--certificate-oidc-issuer https://token.actions.githubusercontent.comReplace <tag> with the version tag you want to validate, for example a release tag, latest, <tag>-lite, or lite.