Maintainers
Pricing
Enterprise
More
More
Documentation
Try Live
Rankings
Install
Blog
Docs7
Ask
New
Add Docs
LightRAG
https://github.com/hkuds/lightrag
Admin
"LightRAG: Simple and Fast Retrieval-Augmented Generation"
Tokens:
409,158
Snippets:
2,601
Trust Score:
9.5
License:
MIT
Update:
2 weeks ago
Context
Chat
Benchmark
64.1
Latest
Show doc for...
Code
Info
Show Results
Tokens:
Raw
Copy
Link
Tokens:
Raw
Copy
Link
### Install LightRAG Server from Source with make and uv Source: https://github.com/hkuds/lightrag/blob/main/README.md Clone the repository and bootstrap the development environment with make dev, which installs the test toolchain, full offline stack, and builds the frontend. Equivalent manual steps with uv sync are also provided. After setup, build front-end artifacts with bun and launch the server with lightrag-server. ```bash 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 ``` -------------------------------- ### Start Apple container system Source: https://github.com/hkuds/lightrag/blob/main/docs/AppleContainerSetup.md Start the Apple container system once. Accept the default kernel install when prompted. ```bash container system start # accept the default kernel install when prompted ``` -------------------------------- ### Install dependency groups with pip Source: https://github.com/hkuds/lightrag/blob/main/docs/OfflineDeployment.md Installation examples for the available dependency groups. The 'api' group includes document processing (PDF, DOCX, PPTX, XLSX). The 'offline' group is recommended for offline deployment and includes all features. ```bash # Install API with document processing pip install lightrag-hku[api] # Install API and storage backends pip install lightrag-hku[api,offline-storage] # Install all offline dependencies (recommended for offline deployment) pip install lightrag-hku[offline] ``` -------------------------------- ### Install KubeBlocks and Addons Source: https://github.com/hkuds/lightrag/blob/main/k8s-deploy/K8S-README.md Installs KubeBlocks and KubeBlocks-Addons. Skip if already installed. ```bash bash ./databases/01-prepare.sh ``` -------------------------------- ### Start development server with Bun and npm Source: https://github.com/hkuds/lightrag/blob/main/lightrag_webui/WEBUI-README.md Starts the development server. Use `bun run dev` with Bun or `npm run dev` with Node.js/npm. ```bash # With Bun bun run dev # With Node.js/npm npm run dev ``` -------------------------------- ### Customize UI from source with UI_TEMPLATES_DIR Source: https://github.com/hkuds/lightrag/blob/main/docs/UserDefinedUI.md Steps to customize the UI from a source checkout: copy the example bundle, edit the welcome text and logo, set UI_TEMPLATES_DIR in .env, start the server, and check the startup log for the bundle state. ```bash # The conventional location for a source checkout; it is git-ignored. cp -r docs/ui_templates_example lightrag_webui/ui_templates # Edit the texts and drop in your own logo (PNG / JPEG / WebP / SVG all work, see §4.4) $EDITOR lightrag_webui/ui_templates/locales/en/welcome.md cp /path/to/your-logo.svg lightrag_webui/ui_templates/assets/logo.svg ``` ```ini UI_TEMPLATES_DIR=./lightrag_webui/ui_templates ``` ```bash lightrag-server ``` ```text INFO: UI customization: bundle 1f0c… ['en', 'zh', 'zh-TW'] ``` -------------------------------- ### Install LightRAG service with systemctl Source: https://github.com/hkuds/lightrag/blob/main/docs/LightRAG-API-Server.md Install and manage the LightRAG systemd service on Ubuntu. Copy the service file to /etc/systemd/system/, reload systemd, start the service, check its status, and enable it to start on boot. ```shell sudo cp lightrag.service /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl start lightrag.service sudo systemctl status lightrag.service sudo systemctl enable lightrag.service ``` -------------------------------- ### .env example for LightRAG API server Source: https://github.com/hkuds/lightrag/blob/main/docs/LightRAG-API-Server.md Reference .env snippet for tuning an existing deployment. For a first run, follow the Progressive Setup Recipes instead of copying this entire file. Contains commented-out options for server, indexing, LLM, VLM, reranker, embedding, and JWT auth settings. ```bash ### Server Configuration # HOST=0.0.0.0 PORT=9621 WORKERS=2 # LIGHTRAG_API_PREFIX=/site01 ### Settings for document indexing ENTITY_EXTRACTION_USE_JSON=true # ENTITY_TYPE_PROMPT_FILE=entity_type_prompt.yml # MAX_EXTRACT_INPUT_TOKENS=20480 # MAX_EXTRACTION_RECORDS=100 # MAX_EXTRACTION_ENTITIES=40 SUMMARY_LANGUAGE=Chinese MAX_PARALLEL_INSERT=3 LIGHTRAG_PARSER=*:native-teP,*:legacy-R # CHUNK_R_SEPARATORS=["\n\n","\n","。","!","?",";",","," ",""] # CHUNK_P_SIZE=2000 ### LLM Configuration (Use valid host. For local services installed with docker, you can use host.docker.internal) TIMEOUT=150 MAX_ASYNC_LLM=4 LLM_BINDING=openai LLM_MODEL=gpt-4o-mini LLM_BINDING_HOST=https://api.openai.com/v1 LLM_BINDING_API_KEY=your-api-key KEYWORD_LLM_MODEL=gpt-4o-mini QUERY_LLM_MODEL=gpt-4o ### Optional VLM configuration for documents using i/t/e process options VLM_PROCESS_ENABLE=false # VLM_LLM_MODEL=gpt-4o # VLM_MAX_IMAGE_BYTES=5242880 # SURROUNDING_LEADING_MAX_TOKENS=2000 # SURROUNDING_TRAILING_MAX_TOKENS=2000 ### Optional reranker configuration RERANK_BINDING=null # MAX_ASYNC_RERANK=4 # RERANK_TIMEOUT=30 ### Embedding Configuration (Use valid host. For local services installed with docker, you can use host.docker.internal) # see also env.ollama-binding-options.example for fine tuning ollama EMBEDDING_MODEL=bge-m3:latest EMBEDDING_DIM=1024 EMBEDDING_BINDING=ollama EMBEDDING_BINDING_HOST=http://localhost:11434 # Optional asymmetric embedding for prefix-based models: # EMBEDDING_ASYMMETRIC=true # EMBEDDING_QUERY_PREFIX="search_query: " # EMBEDDING_DOCUMENT_PREFIX="search_document: " # Use NO_PREFIX for a side that should intentionally have no prefix. ### For JWT Auth # AUTH_ACCOUNTS='admin:{bcrypt}$2b$12$replace-with-generated-hash,user1:pass456' # TOKEN_SECRET=your-key-for-LightRAG-API-Server-xxx # TOKEN_EXPIRE_HOURS=48 # LIGHTRAG_API_KEY=your-secure-api-key-here-123 # WHITELIST_PATHS=/api/* # WHITELIST_PATHS=/health,/api/* ``` -------------------------------- ### Normal installation with mandatory frontend build Source: https://github.com/hkuds/lightrag/blob/main/docs/FrontendBuildGuide.md Performs a normal installation for testing the package build. The frontend must be built first because files are copied to site-packages; post-build modifications won't affect the installed package, requiring a rebuild and reinstall to update. ```bash # Clone the repository git clone https://github.com/HKUDS/LightRAG.git cd LightRAG # ⚠️ MUST build frontend FIRST cd lightrag_webui bun install --frozen-lockfile bun run build cd .. # Now install pip install ".[api]" ``` -------------------------------- ### Run OpenSearch with Docker Compose Source: https://github.com/hkuds/lightrag/blob/main/docs/ProgramingWithCore.md Downloads and starts the recommended OpenSearch Docker Compose setup with plugins. Set OPENSEARCH_INITIAL_ADMIN_PASSWORD to a custom admin password before running. ```bash curl -O https://raw.githubusercontent.com/opensearch-project/opensearch-build/main/docker/release/dockercomposefiles/docker-compose-3.x.yml OPENSEARCH_INITIAL_ADMIN_PASSWORD=<custom-admin-password> docker-compose -f docker-compose-3.x.yml up -d ``` -------------------------------- ### Minimal installation with lightrag-hku[api] Source: https://github.com/hkuds/lightrag/blob/main/docs/OfflineDeployment.md Best practice for minimal installation. Installs only the lightrag-hku[api] extra for document processing, then manually adds a specific LLM provider like openai to keep the offline footprint small. ```bash # If you only need API with document processing pip install lightrag-hku[api] # Then manually add specific LLM: pip install openai ``` -------------------------------- ### Install with uv and activate virtual environment Source: https://github.com/hkuds/lightrag/blob/main/AGENTS.md Install the project with uv. The first block sets up the base environment and activates the virtual environment (use .venv\Scripts\activate on Windows). The second adds API support. The third installs specific extras: offline-storage for storage backends, offline-llm for LLM providers, and test for testing dependencies. ```bash uv sync source .venv/bin/activate # Or: .venv\Scripts\activate on Windows ``` ```bash uv sync --extra api ``` ```bash uv sync --extra offline-storage # Storage backends uv sync --extra offline-llm # LLM providers uv sync --extra test # Testing dependencies ``` -------------------------------- ### Install Databases with Script Source: https://github.com/hkuds/lightrag/blob/main/k8s-deploy/K8S-README.md Installs the required databases (PostgreSQL and Neo4J by default). Modify databases/00-config.sh to select different databases. ```bash bash ./databases/02-install-database.sh ``` -------------------------------- ### Install Bash and run apple-container.sh Source: https://github.com/hkuds/lightrag/blob/main/docs/AppleContainerSetup.md Install Bash 4+ (macOS ships Bash 3.2) and run the Apple container setup script with it. ```bash brew install bash bash scripts/setup/apple-container.sh up ``` -------------------------------- ### Create UI templates directory and copy example bundle Source: https://github.com/hkuds/lightrag/blob/main/docs/DockerDeployment.md Create the UI templates directory before the first `docker compose up` so it is not created root-owned by Docker, then copy the example bundle into it. The directory must exist before the mount is used. ```bash mkdir -p ./data/ui_templates cp -r docs/ui_templates_example/* ./data/ui_templates/ ``` -------------------------------- ### Add storage to LightRAG Docker setup Source: https://github.com/hkuds/lightrag/blob/main/docs/InteractiveSetup.md Adds storage to the base setup by running the storage environment target and then starting the Docker containers. ```bash make env-base make env-storage docker compose -f docker-compose.final.yml up -d ``` -------------------------------- ### Install LightRAG Server from PyPI with uv or pip Source: https://github.com/hkuds/lightrag/blob/main/README.md Install the LightRAG server as a tool using uv (recommended) or pip. After installation, copy env.example to .env and configure LLM and embedding settings. Launch the server with lightrag-server; it binds to all interfaces by default, so configure authentication in .env before exposing it on a network. ```bash ### 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 ``` -------------------------------- ### Prepare environment and install KubeBlocks add-ons Source: https://github.com/hkuds/lightrag/blob/main/k8s-deploy/databases/K8S-DB-README.md Run 01-prepare.sh to perform pre-checks, add the KubeBlocks Helm repo, install core CRDs/controllers, and install addons for enabled databases. Does not create clusters. ```bash bash ./01-prepare.sh ``` -------------------------------- ### Install dependencies with Bun (bun install --frozen-lockfile) Source: https://github.com/hkuds/lightrag/blob/main/lightrag_webui/WEBUI-README.md Run this command in the `lightrag_webui` directory to install project dependencies with Bun while keeping the lockfile frozen. ```bash bun install --frozen-lockfile ``` -------------------------------- ### Install LightRAG SDK from PyPI Source: https://github.com/hkuds/lightrag/blob/main/README.md Install from PyPI using uv pip install lightrag-hku or pip install lightrag-hku. ```bash uv pip install lightrag-hku # 或: pip install lightrag-hku ``` -------------------------------- ### apple-container.sh quick start commands Source: https://github.com/hkuds/lightrag/blob/main/docs/AppleContainerSetup.md Commands to start the full stack, start databases only, check status, tail logs, stop containers, and purge data. The script is idempotent for 'up' and keeps data on 'down' unless '--purge' is used. ```bash # Start the whole stack (databases + LightRAG server) bash scripts/setup/apple-container.sh up # Databases only (run the LightRAG server on the host yourself) bash scripts/setup/apple-container.sh up --no-lightrag # See what is running bash scripts/setup/apple-container.sh status # Tail a service's logs bash scripts/setup/apple-container.sh logs lightrag --follow # Stop and remove containers (keeps data) bash scripts/setup/apple-container.sh down # Stop, remove containers AND delete all stored data bash scripts/setup/apple-container.sh down --purge ``` -------------------------------- ### Install faiss-cpu Source: https://github.com/hkuds/lightrag/blob/main/docs/ProgramingWithCore.md Install the faiss-cpu package before using Faiss storage. Alternatively, install faiss-gpu for GPU support. ```bash pip install faiss-cpu ``` -------------------------------- ### Start LightRAG server without Docker services Source: https://github.com/hkuds/lightrag/blob/main/docs/InteractiveSetup.md Starts the LightRAG server after setup when wizard-managed Docker services were not enabled. ```bash lightrag-server ``` -------------------------------- ### Add security and SSL to LightRAG Docker setup Source: https://github.com/hkuds/lightrag/blob/main/docs/InteractiveSetup.md Adds security and SSL before exposure by running the server and security-check environment targets, then starting the Docker containers. ```bash make env-base make env-storage make env-server make env-security-check docker compose -f docker-compose.final.yml up -d ``` -------------------------------- ### Install LightRAG SDK from source code Source: https://github.com/hkuds/lightrag/blob/main/README.md Install from source code. Note that uv sync automatically creates a virtual environment in .venv/ directory. Activate the virtual environment with source .venv/bin/activate on Linux/macOS, or use .venv\Scripts\activate on Windows. Alternatively, use pip install -e . ```bash cd LightRAG # 注意: uv sync 会自动在 .venv/ 目录创建虚拟环境 uv sync source .venv/bin/activate # 激活虚拟环境 (Linux/macOS) # Windows 系统: .venv\Scripts\activate # 或: pip install -e . ``` -------------------------------- ### Install LightRAG from Source with make, uv, or pip Source: https://github.com/hkuds/lightrag/blob/main/docs/LightRAG-API-Server.md Clone the LightRAG repository and set up the development environment. The 'make dev' command installs the test toolchain plus the full offline stack (API, storage backends, provider integrations) and builds the frontend. Equivalent manual steps with uv or pip are provided, along with building the frontend using bun. ```bash # Clone the repository git clone https://github.com/HKUDS/lightrag.git # Change to the repository directory 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 .. ``` -------------------------------- ### Set up LightRAG development environment with editable install and Bun build Source: https://github.com/hkuds/lightrag/blob/main/docs/FrontendBuildGuide.md Sets up a development environment for LightRAG. Installs the package in editable mode (symlink) so changes take effect immediately, then builds the frontend with Bun when needed. The frontend build output goes to `lightrag/api/webui/`. ```bash # Clone the repository git clone https://github.com/HKUDS/LightRAG.git cd LightRAG # Install in editable mode (no frontend build required yet) pip install -e ".[api]" # Build frontend when needed (can be done anytime) cd lightrag_webui bun install --frozen-lockfile bun run build cd .. ``` -------------------------------- ### Run LightRAG interactive setup wizard Source: https://github.com/hkuds/lightrag/blob/main/docs/InteractiveSetup.md Runs the interactive setup wizard for LightRAG. It prompts for LLM provider, model, endpoint, API key, embedding configuration, and reranking options, then writes .env and optionally docker-compose.final.yml. ```bash make env-base ``` -------------------------------- ### Install with individual requirements files Source: https://github.com/hkuds/lightrag/blob/main/docs/OfflineDeployment.md Install dependencies using individual requirements files for storage backends, LLM providers, or all offline dependencies. ```bash # Storage backends only pip install -r requirements-offline-storage.txt # LLM providers only pip install -r requirements-offline-llm.txt # All offline dependencies pip install -r requirements-offline.txt ``` -------------------------------- ### Build frontend with Bun Source: https://github.com/hkuds/lightrag/blob/main/docs/FrontendBuildGuide.md Build the frontend from the lightrag_webui directory using Bun. Run this after installing in development mode if the web interface does not work. ```bash cd lightrag_webui && bun run build ``` -------------------------------- ### Install Bun on macOS/Linux and Windows Source: https://github.com/hkuds/lightrag/blob/main/docs/FrontendBuildGuide.md Install Bun on macOS/Linux or Windows. The macOS/Linux command uses curl to pipe the install script to bash, while the Windows command uses PowerShell to execute the installer. Official documentation is available at https://bun.sh. ```bash # macOS/Linux curl -fsSL https://bun.sh/install | bash # Windows powershell -c "irm bun.sh/install.ps1 | iex" ``` -------------------------------- ### Start LightRAG server with docker compose Source: https://github.com/hkuds/lightrag/blob/main/docs/DockerDeployment.md Starts the LightRAG server using the default docker-compose configuration. Run this in the project root. ```bash docker compose up -d ``` -------------------------------- ### Install LightRAG Server from PyPI using uv or pip Source: https://github.com/hkuds/lightrag/blob/main/docs/LightRAG-API-Server.md Install the LightRAG API server as a tool using uv, or via pip in a virtual environment. The uv command installs the 'lightrag-hku[api]' package as a standalone tool. The pip commands show creating a virtual environment and installing the package with the 'api' extra. ```bash ### 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]" ``` -------------------------------- ### Start OpenSearch for integration testing Source: https://github.com/hkuds/lightrag/blob/main/docs/ProgramingWithCore.md Starts OpenSearch using the Docker Compose file downloaded earlier. This is the first step of the integration testing workflow. ```bash OPENSEARCH_INITIAL_ADMIN_PASSWORD=<custom-admin-password> docker-compose -f docker-compose-3.x.yml up -d ``` -------------------------------- ### Install ragas and datasets Source: https://github.com/hkuds/lightrag/blob/main/lightrag/evaluation/README_EVALUASTION_RAGAS.md Install the required Python packages for RAGAS evaluation. ```bash pip install ragas datasets ``` -------------------------------- ### Generate .env with Interactive Setup Tool (make env-base, env-storage, env-server, env-security-check) Source: https://github.com/hkuds/lightrag/blob/main/docs/LightRAG-API-Server.md Interactive setup wizard commands to generate a configured .env and, when needed, docker-compose.final.yml. Run make env-base first, then optional targets; run make env-security-check separately to audit the .env for security risks before deployment. ```bash 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-security-check # Optional: audit the current .env for security risks ``` -------------------------------- ### Copy env.example to .env Source: https://github.com/hkuds/lightrag/blob/main/docs/DockerDeployment.md Copies the example environment file to .env for configuration. The first block is for Linux/macOS, the second for Windows PowerShell. ```bash cp env.example .env # Edit .env with your preferred configuration ``` ```powershell Copy-Item env.example .env # Edit .env with your preferred configuration ``` -------------------------------- ### Configure server, validate, and start deployment Source: https://github.com/hkuds/lightrag/blob/main/docs/LightRAG-API-Server.md Configure server-facing settings, validate the environment, run security checks, and start the deployment. Before exposing the deployment, configure authentication, API keys, and SSL in 'make env-server'. The generated .env stays host-usable; container-only service names and Docker-specific overrides are written into docker-compose.final.yml. ```bash make env-server make env-validate make env-security-check docker compose -f docker-compose.final.yml up -d ``` -------------------------------- ### Pre-install optional dependencies for dynamic install failure Source: https://github.com/hkuds/lightrag/blob/main/docs/OfflineDeployment.md Use when dynamic package installation fails with 'Error installing package xxx'. Pre-install the specific optional dependency needed: lightrag-hku[api] for document processing, lightrag-hku[offline-storage] for storage backends, or lightrag-hku[offline-llm] for LLM providers. ```bash # Pre-install the specific package you need # For API with document processing: pip install lightrag-hku[api] # For storage backends: pip install lightrag-hku[offline-storage] # For LLM providers: pip install lightrag-hku[offline-llm] ``` -------------------------------- ### Install LightRAG evaluation extras Source: https://github.com/hkuds/lightrag/blob/main/lightrag/evaluation/README_EVALUASTION_RAGAS.md Installs the project with the 'evaluation' extra, which includes the necessary dependencies for running evaluations. ```bash pip install -e ".[evaluation]" ``` -------------------------------- ### Start LightRAG Server with Docker Compose Source: https://github.com/hkuds/lightrag/blob/main/docs/LightRAG-API-Server.md Starts the LightRAG Server using Docker Compose. Add the -d parameter to run in the background after startup. ```shell docker compose up # If you want the program to run in the background after startup, add the -d parameter at the end of the command. ``` -------------------------------- ### Start LightRAG Server (Uvicorn and Gunicorn modes) Source: https://github.com/hkuds/lightrag/blob/main/docs/LightRAG-API-Server.md Two ways to start the LightRAG server: the simple Uvicorn mode and the multiprocess Gunicorn + Uvicorn mode (production, not supported on Windows). The current working directory must contain the .env file; after modifying .env, reopen the terminal for changes to take effect. ```bash lightrag-server ``` ```bash lightrag-gunicorn --workers 4 ``` -------------------------------- ### Filename override examples for parser options Source: https://github.com/hkuds/lightrag/blob/main/docs/FileProcessingPipeline.md Filename override examples showing how to specify engine and processing options in the filename. Each line demonstrates a different combination, with comments explaining the effect. ```text my-proposal.[native-iet].docx # Use the native engine, enable drawing/table/equation analysis my-memo.[native-R!].docx # Use the native engine, recursive semantic chunking, disable knowledge graph construction my-proposal.[-!].docx # Use the default engine, only disable knowledge graph construction my-proposal.[mineru].docx # Use the MinerU engine, all processing options default ``` -------------------------------- ### Install database clusters Source: https://github.com/hkuds/lightrag/blob/main/k8s-deploy/databases/K8S-DB-README.md Run 02-install-database.sh to deploy the chosen databases to Kubernetes. This may take a few minutes for clusters to become ready. ```bash bash ./02-install-database.sh ``` -------------------------------- ### Install LightRAG using convenience script Source: https://github.com/hkuds/lightrag/blob/main/k8s-deploy/K8S-README.md Sets environment variables for OpenAI API and runs the convenience script to deploy LightRAG with lightweight storage. ```bash export OPENAI_API_BASE=<YOUR_OPENAI_API_BASE> export OPENAI_API_KEY=<YOUR_OPENAI_API_KEY> bash ./install_lightrag_dev.sh ``` -------------------------------- ### Install LightRAG with OpenAI Credentials Source: https://github.com/hkuds/lightrag/blob/main/k8s-deploy/K8S-README.md Sets OpenAI API credentials and runs the LightRAG installation script. The script automatically retrieves database connection information from KubeBlocks, so manual database credentials are not needed. ```bash export OPENAI_API_BASE=<YOUR_OPENAI_API_BASE> export OPENAI_API_KEY=<YOUR_OPENAI_API_KEY> bash ./install_lightrag.sh ``` -------------------------------- ### Start Docker containers for remote LLM with local embedding and rerank Source: https://github.com/hkuds/lightrag/blob/main/docs/InteractiveSetup.md Sets up the base environment and starts the Docker containers for remote LLM with local embedding and rerank. ```bash make env-base docker compose -f docker-compose.final.yml up -d ``` -------------------------------- ### Install LightRAG from PyPI with API extra Source: https://github.com/hkuds/lightrag/blob/main/docs/FrontendBuildGuide.md Installs the LightRAG package with the API extra from PyPI. The frontend is already built and included, so no additional steps are needed and the web interface works immediately. ```bash pip install lightrag-hku[api] ``` -------------------------------- ### Verify offline installation with import tests Source: https://github.com/hkuds/lightrag/blob/main/docs/OfflineDeployment.md Verifies the offline installation by testing imports of LightRAG, TiktokenTokenizer, and optional Redis. Each command prints a success message if the import works. ```bash # Test Python import python -c "from lightrag import LightRAG; print('✓ LightRAG imported')" # Test tiktoken python -c "from lightrag.utils import TiktokenTokenizer; t = TiktokenTokenizer(); print('✓ Tiktoken working')" # Test optional dependencies (if installed) python -c "import redis; print('✓ Redis available')" ``` -------------------------------- ### Create a standalone backup with env-backup Source: https://github.com/hkuds/lightrag/blob/main/docs/InteractiveSetup.md Use this command to create a manual backup without running any setup flow. ```bash make env-backup ``` -------------------------------- ### Configure full multimodal setup with MinerU and VLM Source: https://github.com/hkuds/lightrag/blob/main/docs/LightRAG-API-Server.md Full multimodal setup using the MinerU official API and a VLM. Requires setting MINERU_API_MODE and MINERU_API_TOKEN, and enables VLM processing with the specified model. ```bash LIGHTRAG_PARSER=*:native-iteP,*:mineru-iteP,*:legacy-R VLM_PROCESS_ENABLE=true VLM_LLM_MODEL=gpt-4o MINERU_API_MODE=official MINERU_API_TOKEN=your_mineru_api_token MINERU_OFFICIAL_ENDPOINT=https://mineru.net MINERU_MODEL_VERSION=vlm MINERU_IS_OCR=false ``` -------------------------------- ### Run LightRAG server with remote models Source: https://github.com/hkuds/lightrag/blob/main/docs/InteractiveSetup.md Sets up the base environment and starts the LightRAG server for remote models with a local server. ```bash make env-base lightrag-server ``` -------------------------------- ### Dockerfile RUN with uv sync --frozen --no-dev --extra api Source: https://github.com/hkuds/lightrag/blob/main/docs/UV_LOCK_GUIDE.md Dockerfile instruction to install dependencies with `--frozen` for reproducible builds, `--no-dev` to skip dev dependencies, and `--extra api` to install the API server. ```dockerfile RUN uv sync --frozen --no-dev --extra api ``` -------------------------------- ### Start Docker-based LightRAG stack Source: https://github.com/hkuds/lightrag/blob/main/docs/InteractiveSetup.md Starts the generated Docker-based LightRAG stack together with the selected local services when wizard-managed Docker services were enabled. ```bash docker compose -f docker-compose.final.yml up -d ``` -------------------------------- ### Configure and run the API server Source: https://github.com/hkuds/lightrag/blob/main/AGENTS.md Set up and run the API server. Copy env.example to .env and edit it with your LLM/embedding configs. Build the WebUI from lightrag_webui using bun. Then run the server: lightrag-server for production, uvicorn with --reload for development, or lightrag-gunicorn for multi-worker gunicorn. ```bash cp env.example .env # Edit with your LLM/embedding configs ``` ```bash cd lightrag_webui bun install --frozen-lockfile bun run build cd .. ``` ```bash lightrag-server # Production uvicorn lightrag.api.lightrag_server:app --reload # Development lightrag-gunicorn # Multi-worker (gunicorn) ``` -------------------------------- ### Scenario 1: .env.development configuration (VITE_BACKEND_URL, VITE_API_PROXY, VITE_API_ENDPOINTS) Source: https://github.com/hkuds/lightrag/blob/main/docs/MultiSiteDeployment.md Environment file for the default single-instance dev setup. VITE_BACKEND_URL points to the backend, VITE_API_PROXY enables the Vite proxy, VITE_API_ENDPOINTS lists the proxied paths, and VITE_DEV_API_PREFIX is left empty to avoid a prefix. ```bash # lightrag_webui/.env.development (already in repo as sample) VITE_BACKEND_URL=http://localhost:9621 VITE_API_PROXY=true VITE_API_ENDPOINTS=/api,/documents,/graphs,/graph,/health,/query,/docs,/redoc,/openapi.json,/login,/auth-status,/auth/verify,/ui/customization,/static # VITE_DEV_API_PREFIX= ← leave empty ``` -------------------------------- ### Example 6: Using Environment Variables from .env File Source: https://github.com/hkuds/lightrag/blob/main/lightrag/evaluation/README_EVALUASTION_RAGAS.md Creates a .env file with environment variables and runs the evaluation, which automatically loads the .env file. ```bash # Create .env file in project root cat > .env << EOF EVAL_LLM_BINDING_API_KEY=your-key EVAL_LLM_BINDING_HOST=http://localhost:8000/v1 EVAL_LLM_MODEL=qwen-plus EVAL_EMBEDDING_MODEL=BAAI/bge-m3 EOF # Run evaluation (automatically loads .env) python lightrag/evaluation/eval_rag_quality.py ``` -------------------------------- ### heading position object example Source: https://github.com/hkuds/lightrag/blob/main/docs/LightRAGSidecarFormat.md Example of a positions object with type heading, used for Markdown-like files. The anchor is the starting heading, and charspan is optional. ```json "positions": [ { "type": "heading", "anchor": "ii" "range": [174, 155, 818, 333] "charspan": [10, 999] }] ``` -------------------------------- ### Scenario 1: Run commands (lightrag-server and bun run dev) Source: https://github.com/hkuds/lightrag/blob/main/docs/MultiSiteDeployment.md Two-terminal startup for the default scenario: run lightrag-server without LIGHTRAG_API_PREFIX in one terminal, then cd into lightrag_webui and run bun run dev in another. Open http://localhost:5173/ in the browser. ```bash lightrag-server # in one terminal, no LIGHTRAG_API_PREFIX cd lightrag_webui && bun run dev # in another; open http://localhost:5173/ ``` -------------------------------- ### Local backend with LIGHTRAG_API_PREFIX=/site01 Source: https://github.com/hkuds/lightrag/blob/main/docs/MultiSiteDeployment.md Commands to run the LightRAG server with the API prefix and the Vite dev server, for a simple two-process local setup. ```bash VITE_BACKEND_URL=http://localhost:9621 ``` ```bash # Terminal 1 LIGHTRAG_API_PREFIX=/site01 lightrag-server # Terminal 2 cd lightrag_webui && bun run dev ``` -------------------------------- ### absolute position object example Source: https://github.com/hkuds/lightrag/blob/main/docs/LightRAGSidecarFormat.md Example of a positions object with type absolute, used for text-like files. The charspan specifies the start and end character positions. ```json "positions": [ { "charspan": [10, 999] }] ``` -------------------------------- ### paraid position object example Source: https://github.com/hkuds/lightrag/blob/main/docs/LightRAGSidecarFormat.md Example of a positions object with type paraid, used for docx files. The range field specifies start and end paragraph ids, and charspan is optional. ```json "positions": [ { "type": "paraid", "range": ["5EA4577A", "6555DDCB"] "charspan": [10,999] }] ``` -------------------------------- ### Build project with Bun (bun run build) Source: https://github.com/hkuds/lightrag/blob/main/lightrag_webui/WEBUI-README.md Build the project with Bun, bundling it and outputting files to the `lightrag/api/webui` directory. ```bash bun run build ``` -------------------------------- ### Install and build with Node.js/npm (alternative) Source: https://github.com/hkuds/lightrag/blob/main/lightrag_webui/WEBUI-README.md Use this alternative when Bun is unavailable or its build fails. Note that tests (`bun test`) still require Bun, while other scripts work with both Bun and Node.js/npm. ```bash npm install npm run build ``` -------------------------------- ### Start multiple LightRAG instances with different ports and workspaces Source: https://github.com/hkuds/lightrag/blob/main/docs/LightRAG-API-Server.md Start two LightRAG instances in the same working directory with different ports and workspaces. The workspace parameter must be unique for each instance to avoid data confusion and corruption. ```bash # Start instance 1 lightrag-server --port 9621 --workspace space1 # Start instance 2 lightrag-server --port 9622 --workspace space2 ``` -------------------------------- ### Install spaCy language models for smart_heading Source: https://github.com/hkuds/lightrag/blob/main/README.md Run this command to install the pinned spaCy language models (zh_core_web_sm / en_core_web_sm 3.8.0) required by the native docx parser's opt-in smart_heading engine. The spaCy runtime is already included in the api extra; only the models need this step. Models are verified at startup when smart_heading is enabled, and the main Docker image ships them pre-installed. ```bash lightrag-download-cache --spacy-install ``` -------------------------------- ### Run LightRAG WebUI with OpenSearch Source: https://github.com/hkuds/lightrag/blob/main/docs/ProgramingWithCore.md Starts the LightRAG WebUI server with OpenSearch storage and OpenAI bindings. Requires an OPENAI_API_KEY and the OpenSearch environment variables. ```bash LIGHTRAG_KV_STORAGE=OpenSearchKVStorage \ LIGHTRAG_DOC_STATUS_STORAGE=OpenSearchDocStatusStorage \ LIGHTRAG_GRAPH_STORAGE=OpenSearchGraphStorage \ LIGHTRAG_VECTOR_STORAGE=OpenSearchVectorDBStorage \ LLM_BINDING=openai \ EMBEDDING_BINDING=openai \ EMBEDDING_MODEL=text-embedding-3-large \ EMBEDDING_DIM=3072 \ OPENAI_API_KEY=your-api-key \ lightrag-server ``` -------------------------------- ### Add user prompt with query prefix Source: https://github.com/hkuds/lightrag/blob/main/docs/LightRAG-API-Server.md Examples of appending a user prompt in square brackets to a query prefix. The user prompt does not participate in RAG retrieval but guides the LLM on how to process the retrieved results. The first example uses the / prefix (defaults to mix mode), and the second explicitly uses /mix. ```text /[Use mermaid format for diagrams] Please draw a character relationship diagram for Scrooge /mix[Use mermaid format for diagrams] Please draw a character relationship diagram for Scrooge ``` -------------------------------- ### Run LLM Cache Migration Tool Source: https://github.com/hkuds/lightrag/blob/main/lightrag/tools/README_MIGRATE_LLM_CACHE.md Run the LLM cache migration tool from the LightRAG project root directory. Both commands are equivalent and start the migration process. ```bash python -m lightrag.tools.migrate_llm_cache # or python lightrag/tools/migrate_llm_cache.py ``` -------------------------------- ### Override provider option per role (e.g., QUERY_OPENAI_LLM_REASONING_EFFORT) Source: https://github.com/hkuds/lightrag/blob/main/docs/LLMProviderOptions.md Keep a provider option out of one role when there is no 'unset an inherited option' syntax. Override the option for that role with a value the role's model accepts, or keep the option role-level from the start. This example shows a local OpenAI-compatible endpoint sharing the 'openai' binding with the official API. ```env LLM_BINDING=openai LLM_MODEL=gpt-5-mini # Do NOT set OPENAI_LLM_REASONING_EFFORT globally here — the local server rejects it. QUERY_OPENAI_LLM_REASONING_EFFORT=medium KEYWORD_OPENAI_LLM_MAX_TOKENS=2048 ``` -------------------------------- ### Launch LightRAG Server with Docker Compose Source: https://github.com/hkuds/lightrag/blob/main/README.md Clone the repository, copy env.example to .env, and modify LLM and embedding settings. Then run docker compose up to launch the server. Historical Docker images are available on GitHub Packages. ```bash 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 ``` -------------------------------- ### Error for connection failure Source: https://github.com/hkuds/lightrag/blob/main/lightrag/tools/README_CLEAN_LLM_QUERY_CACHE.md Example error message when initialization fails due to connection issues. Check database service, connection parameters, firewall, and network. ```text ✗ Initialization failed: Connection refused ``` -------------------------------- ### Install missing runtime dependencies with lightrag-hku[offline] Source: https://github.com/hkuds/lightrag/blob/main/docs/OfflineDeployment.md Use when a runtime error occurs: 'ModuleNotFoundError: No module named 'xxx''. First check installed packages with pip list, then install the missing component using the lightrag-hku[offline] extra which installs all offline dependencies. ```bash # Check what you have installed pip list | grep -i xxx # Install missing component pip install lightrag-hku[offline] # Install all offline deps ``` -------------------------------- ### View provider options with lightrag-server --help Source: https://github.com/hkuds/lightrag/blob/main/docs/LightRAG-API-Server.md Commands to view the complete list of configurable options for OpenAI, Ollama, and Gemini LLM and embedding interfaces. The --help output covers only the binding you pass and prints no default values or environment-variable names. ```bash lightrag-server --llm-binding openai --help lightrag-server --llm-binding ollama --help lightrag-server --llm-binding gemini --help lightrag-server --embedding-binding ollama --help lightrag-server --embedding-binding gemini --help ``` -------------------------------- ### macOS Gunicorn fork-safety override and start command Source: https://github.com/hkuds/lightrag/blob/main/docs/LightRAG-API-Server.md Required on macOS before starting Gunicorn multi-worker mode to avoid Objective-C fork-safety issues. The environment variable must be set before the Python process starts; setting it in .env is too late. The command starts the LightRAG server with two workers. ```shell export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES lightrag-gunicorn --workers 2 ``` -------------------------------- ### Install RAGAS dependencies with pip Source: https://github.com/hkuds/lightrag/blob/main/lightrag/evaluation/README_EVALUASTION_RAGAS.md Installs the required Python packages for RAGAS evaluation: ragas, datasets, and langfuse. ```bash pip install ragas datasets langfuse ``` -------------------------------- ### Simple LightRAG Core Python example with initialization and hybrid query Source: https://github.com/hkuds/lightrag/blob/main/docs/ProgramingWithCore.md Use this script to integrate LightRAG Core into your application. It requires an OPENAI_API_KEY environment variable and creates a working directory for persistence. The script initializes the LightRAG instance with gpt_4o_mini_complete and openai_embed, inserts text, performs a hybrid query, and finalizes storage. Note that both initialization calls (initialize_storages and finalize_storages) are required. ```python import os import asyncio from lightrag import LightRAG, QueryParam from lightrag.llm.openai import gpt_4o_mini_complete, gpt_4o_complete, openai_embed from lightrag.utils import setup_logger setup_logger("lightrag", level="INFO") WORKING_DIR = "./rag_storage" if not os.path.exists(WORKING_DIR): os.mkdir(WORKING_DIR) async def initialize_rag(): rag = LightRAG( working_dir=WORKING_DIR, embedding_func=openai_embed, llm_model_func=gpt_4o_mini_complete, ) # IMPORTANT: Both initialization calls are required! await rag.initialize_storages() # Initialize storage backends return rag async def main(): try: # Initialize RAG instance rag = await initialize_rag() await rag.ainsert("Your text") # Perform hybrid search mode = "hybrid" print( await rag.aquery( "What are the top themes in this story?", param=QueryParam(mode=mode) ) ) except Exception as e: print(f"An error occurred: {e}") finally: if rag: await rag.finalize_storages() if __name__ == "__main__": asyncio.run(main()) ``` -------------------------------- ### Install LightRAG offline and configure tiktoken cache Source: https://github.com/hkuds/lightrag/blob/main/docs/OfflineDeployment.md Installs LightRAG in the offline environment. Extracts the archive, installs Python packages using --no-index with the local package directory, sets up the tiktoken cache, and adds the TIKTOKEN_CACHE_DIR export to ~/.bashrc for persistence. ```bash # 1. Extract archive cd /tmp tar -xzf lightrag-offline-complete.tar.gz # 2. Install Python packages pip install --no-index \ --find-links=/tmp/offline_cache/packages \ lightrag-hku[offline] # 3. Set up tiktoken cache mkdir -p ~/.tiktoken_cache cp -r /tmp/offline_cache/tiktoken/* ~/.tiktoken_cache/ export TIKTOKEN_CACHE_DIR=~/.tiktoken_cache # 4. Add to shell profile for persistence echo 'export TIKTOKEN_CACHE_DIR=~/.tiktoken_cache' >> ~/.bashrc ``` -------------------------------- ### Install LightRAG using Helm directly Source: https://github.com/hkuds/lightrag/blob/main/k8s-deploy/K8S-README.md Helm command to install or upgrade LightRAG with configurable environment variables for storage and LLM/embedding bindings. ```bash # You can override any env param you want helm upgrade --install lightrag ./lightrag \ --namespace rag \ --set-string env.LIGHTRAG_KV_STORAGE=JsonKVStorage \ --set-string env.LIGHTRAG_VECTOR_STORAGE=NanoVectorDBStorage \ --set-string env.LIGHTRAG_GRAPH_STORAGE=NetworkXStorage \ --set-string env.LIGHTRAG_DOC_STATUS_STORAGE=JsonDocStatusStorage \ --set-string env.LLM_BINDING=openai \ --set-string env.LLM_MODEL=gpt-4o-mini \ --set-string env.LLM_BINDING_HOST=$OPENAI_API_BASE \ --set-string env.LLM_BINDING_API_KEY=$OPENAI_API_KEY \ --set-string env.EMBEDDING_BINDING=openai \ --set-string env.EMBEDDING_MODEL=text-embedding-ada-002 \ --set-string env.EMBEDDING_DIM=1536 \ --set-string env.EMBEDDING_BINDING_API_KEY=$OPENAI_API_KEY ``` -------------------------------- ### Run make env-storage to add storage backends Source: https://github.com/hkuds/lightrag/blob/main/docs/InteractiveSetup.md Run this command when you already have a .env file from make env-base and want to switch to database-backed storage. The wizard will ask for storage backend choices and database connection details. ```bash make env-storage ``` -------------------------------- ### Start MinerU API service Source: https://github.com/hkuds/lightrag/blob/main/docs/ParserServiceDeployment.md Starts the MinerU API service using the api profile. The service listens on port 8000 by default. ```bash docker compose -f compose.yaml --profile api up -d ``` -------------------------------- ### Example 1: Default Configuration (OpenAI Official API) Source: https://github.com/hkuds/lightrag/blob/main/lightrag/evaluation/README_EVALUASTION_RAGAS.md Uses OpenAI's official API for both LLM and embeddings with default models. Requires setting OPENAI_API_KEY. ```bash export OPENAI_API_KEY=sk-xxx python lightrag/evaluation/eval_rag_quality.py ``` -------------------------------- ### Create distribution package with frontend build Source: https://github.com/hkuds/lightrag/blob/main/docs/FrontendBuildGuide.md Creates distribution packages for LightRAG. Builds the frontend with production dependencies, then runs `python -m build` to generate wheel and source archives. `setup.py` checks for the frontend build and fails with an error if missing. ```bash # Build frontend first cd lightrag_webui bun install --frozen-lockfile --production bun run build cd .. # Create distribution packages python -m build # Output: dist/lightrag_hku-*.whl and dist/lightrag_hku-*.tar.gz ``` -------------------------------- ### Run tests/setup suite explicitly Source: https://github.com/hkuds/lightrag/blob/main/AGENTS.md Run the setup wizard's test suite (tests/setup/) explicitly. This suite runs only when a wizard input changed (scripts/setup/**, env.example, docker-compose*.yml, Makefile, or tests/setup/ itself) and never imports lightrag. It is skipped by norecursedirs in pyproject.toml in every recursive run, so you must name it explicitly. ```bash ./scripts/test.sh tests/setup ``` -------------------------------- ### Configure Milvus via environment variables Source: https://github.com/hkuds/lightrag/blob/main/docs/ProgramingWithCore.md Quick setup for Milvus vector storage via environment variables. Sets the Milvus URI, database name, and selects MilvusVectorDBStorage as the vector storage backend. ```bash MILVUS_URI=http://localhost:19530 MILVUS_DB_NAME=lightrag LIGHTRAG_VECTOR_STORAGE=MilvusVectorDBStorage ``` -------------------------------- ### Start and Verify LightRAG Service Source: https://github.com/hkuds/lightrag/blob/main/docs/LightRAG-API-Server.md Starts the LightRAG service in the background and verifies it is healthy via the /health endpoint. After this, open the WebUI at http://localhost:9621/webui to upload documents. ```bash docker compose up -d curl http://localhost:9621/health ```