Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
SHELL := /bin/bash
SETUP_SCRIPT := scripts/setup/setup.sh
SETUP_OPTS ?=
COLOR_RESET := \033[0m
COLOR_BOLD := \033[1m
COLOR_BLUE := \033[34m
COLOR_GREEN := \033[32m
COLOR_YELLOW := \033[33m

ifeq ($(NO_COLOR),1)
COLOR_RESET :=
COLOR_BOLD :=
COLOR_BLUE :=
COLOR_GREEN :=
COLOR_YELLOW :=
endif

.PHONY: help setup configure setup-quick setup-production setup-validate setup-backup setup-help

help:
@printf "$(COLOR_BOLD)Interactive setup targets$(COLOR_RESET)\n"
@printf " $(COLOR_GREEN)make setup$(COLOR_RESET) Full wizard (development/production/custom)\n"
@printf " $(COLOR_GREEN)make setup-quick$(COLOR_RESET) Development preset, minimal prompts\n"
@printf " $(COLOR_GREEN)make setup-production$(COLOR_RESET) Production preset + SSL/security prompts\n"
@printf " $(COLOR_GREEN)make setup-validate$(COLOR_RESET) Validate existing .env\n"
@printf " $(COLOR_GREEN)make setup-backup$(COLOR_RESET) Backup current .env\n"
@printf " $(COLOR_GREEN)make setup-help$(COLOR_RESET) Script help and options\n\n"
@printf "$(COLOR_BOLD)Install types$(COLOR_RESET)\n"
@printf " $(COLOR_BLUE)development$(COLOR_RESET): local JSON/NetworkX defaults, fastest to start\n"
@printf " $(COLOR_BLUE)production$(COLOR_RESET): database-backed defaults, security prompts, docker services optional\n"
@printf " $(COLOR_BLUE)custom$(COLOR_RESET): pick each storage backend manually\n\n"
@printf "$(COLOR_BOLD)Examples$(COLOR_RESET)\n"
@printf " make setup\n"
@printf " make setup-quick\n"
@printf " make setup-production SETUP_OPTS=--debug\n\n"
@printf "$(COLOR_BOLD)Image tags$(COLOR_RESET)\n"
@printf " Wizard will show image tags for selected services and let you override them.\n"
@printf " You can also edit POSTGRES_IMAGE_TAG, NEO4J_IMAGE_TAG, etc. in .env.\n"
@printf " Compose file output: docker-compose.<development|production|custom>.yml\n"

setup:
@bash $(SETUP_SCRIPT) $(SETUP_OPTS)

configure:
@bash $(SETUP_SCRIPT) $(SETUP_OPTS)

setup-quick:
@bash $(SETUP_SCRIPT) --quick $(SETUP_OPTS)

setup-production:
@bash $(SETUP_SCRIPT) --production $(SETUP_OPTS)

setup-validate:
@bash $(SETUP_SCRIPT) --validate $(SETUP_OPTS)

setup-backup:
@bash $(SETUP_SCRIPT) --backup $(SETUP_OPTS)

setup-help:
@bash $(SETUP_SCRIPT) --help $(SETUP_OPTS)
56 changes: 56 additions & 0 deletions docs/DockerDeployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ The Dockerfile uses BuildKit cache mounts to significantly improve build perform
docker compose up -d
```

If you used the interactive setup, start the generated stack with:

```bash
docker compose -f docker-compose.development.yml up -d
```

LightRAG Server uses the following paths for data storage:

```
Expand All @@ -82,6 +88,56 @@ data/
└── inputs/ # Input documents
```

### Optional: local vLLM reranker

To enable local reranking with vLLM, run a vLLM container exposing the Cohere-compatible rerank endpoint and point LightRAG to it.
You can select `vllm` in the interactive setup to add the `vllm-rerank` service automatically.
vLLM provides a `v1/rerank` endpoint that works with the `cohere` binding.

Example `docker-compose.override.yml`:

```yaml
services:
vllm-rerank:
image: vllm/vllm-openai:latest
command: >
--model BAAI/bge-reranker-v2-m3
--port 8000
--dtype float16
ports:
- "8000:8000"
volumes:
- ./data/hf-cache:/root/.cache/huggingface
runtime: nvidia
```

Add the rerank config to `.env`:

```bash
RERANK_BINDING=cohere
RERANK_MODEL=BAAI/bge-reranker-v2-m3
RERANK_BINDING_HOST=http://vllm-rerank:8000/v1/rerank
RERANK_BINDING_API_KEY=local-key
VLLM_RERANK_DEVICE=cpu
VLLM_RERANK_DTYPE=float32
```

If you run vLLM on the host instead of Docker, use:

```bash
RERANK_BINDING_HOST=http://host.docker.internal:8000/v1/rerank
```

For GPU, set:

```bash
VLLM_RERANK_DEVICE=cuda
VLLM_RERANK_DTYPE=float16
```

Ensure the NVIDIA Container Toolkit is installed and the host has CUDA drivers available.
The default vLLM image is GPU-only; CPU setups require a CPU-compatible image tag.

### Updates

To update the Docker container:
Expand Down
51 changes: 51 additions & 0 deletions docs/InteractiveSetup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Interactive Setup (Make Targets)

Use the Make targets below to configure and deploy LightRAG with an interactive wizard.

## Targets

- `make setup`: Full wizard. Choose development/production/custom and all backends.
- `make setup-quick`: Development preset, minimal prompts (API keys only).
- `make setup-production`: Production preset with security and SSL prompts.
- `make setup-validate`: Validate current `.env`.
- `make setup-backup`: Backup current `.env`.
- `make setup-help`: Show CLI help.

## Install Types

- **development**: Local JSON/NetworkX defaults. Quickest start.
- **production**: Database-backed defaults with security prompts.
- **custom**: Manual selection of each storage backend.

## Compose Output

The wizard writes a dedicated compose file to avoid overwriting `docker-compose.yml`:

- `docker-compose.development.yml`
- `docker-compose.production.yml`
- `docker-compose.custom.yml`

You can let the wizard start the services immediately after generation.

## Image Tags

The wizard lists Docker image tags for selected services and lets you override them.
You can also edit these in `.env`:

- `POSTGRES_IMAGE_TAG`
- `NEO4J_IMAGE_TAG`
- `MONGODB_IMAGE_TAG`
- `REDIS_IMAGE_TAG`
- `MILVUS_IMAGE_TAG`
- `QDRANT_IMAGE_TAG`
- `MEMGRAPH_IMAGE_TAG`
- `VLLM_RERANK_IMAGE_TAG`

## Tips

- Add `SETUP_OPTS=--debug` to `make` for debug logging.
- Use `SETUP_WAIT_TIMEOUT=120` to increase the startup wait for dependent services.
- Set `NO_COLOR=1` to disable colored output.
- Choose `vllm` in the rerank prompt to add a local vLLM reranker service to `docker-compose.yml`.
- For GPU setups, set `VLLM_RERANK_DEVICE=cuda` and `VLLM_RERANK_DTYPE=float16` (requires NVIDIA Container Toolkit).
- CPU-only vLLM requires a CPU-compatible image tag (the default image is GPU-only).
30 changes: 29 additions & 1 deletion env.example
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ OLLAMA_EMULATING_MODEL_TAG=latest
### Logfile location (defaults to current working directory)
# LOG_DIR=/path/to/log/directory

############################
### Docker Image Tag Overrides
############################
# POSTGRES_IMAGE_TAG=18
# NEO4J_IMAGE_TAG=5.26.19-community
# MONGODB_IMAGE_TAG=8.2.3
# REDIS_IMAGE_TAG=8.4
# MILVUS_IMAGE_TAG=2.6-20251227-44275071
# ETCD_IMAGE_TAG=v3.5.16
# MINIO_IMAGE_TAG=RELEASE.2024-12-13T22-19-12Z
# QDRANT_IMAGE_TAG=v1.16-gpu-nvidia
# MEMGRAPH_IMAGE_TAG=3.7.2
# VLLM_RERANK_IMAGE_TAG=latest

#####################################
### Login and API-Key Configuration
#####################################
Expand Down Expand Up @@ -114,6 +128,18 @@ RERANK_BINDING=null
# RERANK_MODEL=BAAI/bge-reranker-v2-m3
# RERANK_BINDING_HOST=http://localhost:8000/v1/rerank
# RERANK_BINDING_API_KEY=your_rerank_api_key_here
# VLLM_RERANK_MODEL=BAAI/bge-reranker-v2-m3
# VLLM_RERANK_PORT=8000
# VLLM_RERANK_DEVICE=cuda
# VLLM_RERANK_DTYPE=float16
# # Use float16 for GPU mode. CPU-only requires a CPU-compatible vLLM image.
# VLLM_USE_CPU=1
# # Set to 1 for CPU mode, unset for GPU mode
# CUDA_VISIBLE_DEVICES=-1
# # Set to -1 to disable CUDA (CPU mode), or specific GPU IDs for GPU mode
# VLLM_RERANK_EXTRA_ARGS=
# Note: vLLM typically requires GPU. For CPU-only, you may need a CPU-compatible build.
# If you have GPU, remove VLLM_USE_CPU and CUDA_VISIBLE_DEVICES, set VLLM_RERANK_DTYPE=float16.

### Default value for Cohere AI
# RERANK_MODEL=rerank-v3.5
Expand Down Expand Up @@ -450,10 +476,12 @@ MONGO_DATABASE=LightRAG

### Milvus Configuration
MILVUS_URI=http://localhost:19530
MILVUS_DB_NAME=lightrag
MILVUS_DB_NAME=default
# MILVUS_USER=root
# MILVUS_PASSWORD=your_password
# MILVUS_TOKEN=your_token
# MINIO_ACCESS_KEY_ID=minioadmin
# MINIO_SECRET_ACCESS_KEY=minioadmin
### DB specific workspace should not be set, keep for compatible only
### MILVUS_WORKSPACE=forced_workspace_name

Expand Down
144 changes: 144 additions & 0 deletions scripts/setup/lib/file_ops.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# File operations for interactive setup.

format_env_value() {
local value="$1"
local escaped

if [[ -z "$value" ]]; then
printf ''
return
fi

if [[ "$value" =~ [[:space:]] || "$value" == *"\""* || "$value" == *"$"* ]]; then
escaped="${value//\\/\\\\}"
escaped="${escaped//\"/\\\"}"
printf '"%s"' "$escaped"
return
fi

printf '%s' "$value"
}

backup_env_file() {
local env_file="${1:-${REPO_ROOT:-.}/.env}"
local backup_file=""

if [[ -f "$env_file" ]]; then
backup_file="${env_file}.backup.$(date +%Y%m%d_%H%M%S)"
cp "$env_file" "$backup_file"
printf '%s' "$backup_file"
fi
}

generate_env_file() {
local template_file="${1:-${REPO_ROOT:-.}/env.example}"
local output_file="${2:-${REPO_ROOT:-.}/.env}"
local tmp_file="${output_file}.tmp"
local line key value
local -A written_keys=()

if [[ ! -f "$template_file" ]]; then
echo "env.example not found at $template_file" >&2
return 1
fi

: > "$tmp_file"

while IFS= read -r line || [[ -n "$line" ]]; do
if [[ "$line" =~ ^[A-Z0-9_]+= ]]; then
key="${line%%=*}"
if [[ -z "${written_keys[$key]+set}" ]]; then
if [[ -n "${ENV_VALUES[$key]+set}" ]]; then
value="${ENV_VALUES[$key]}"
printf '%s=%s\n' "$key" "$(format_env_value "$value")" >> "$tmp_file"
else
printf '%s\n' "$line" >> "$tmp_file"
fi
written_keys["$key"]=1
else
printf '%s\n' "$line" >> "$tmp_file"
fi
elif [[ "$line" =~ ^#[[:space:]]*([A-Z0-9_]+)= ]]; then
key="${BASH_REMATCH[1]}"
if [[ -z "${written_keys[$key]+set}" && -n "${ENV_VALUES[$key]+set}" ]]; then
value="${ENV_VALUES[$key]}"
printf '%s=%s\n' "$key" "$(format_env_value "$value")" >> "$tmp_file"
written_keys["$key"]=1
else
printf '%s\n' "$line" >> "$tmp_file"
fi
else
printf '%s\n' "$line" >> "$tmp_file"
fi
done < "$template_file"

mv "$tmp_file" "$output_file"
}

generate_docker_compose() {
local output_file="${1:-${REPO_ROOT:-.}/docker-compose.yml}"
local base_file="${REPO_ROOT:-.}/docker-compose.yml"
local tmp_file="${output_file}.tmp"
local template_file
local volume_names=()

if [[ -f "$base_file" ]]; then
cp "$base_file" "$tmp_file"
else
printf 'services:\n' > "$tmp_file"
fi

for service in "${DOCKER_SERVICES[@]}"; do
template_file="$TEMPLATES_DIR/${service}.yml"
if [[ "$service" == "vllm-rerank" ]]; then
if [[ "${ENV_VALUES[VLLM_RERANK_DEVICE]:-cpu}" == "cuda" ]]; then
if [[ -f "$TEMPLATES_DIR/${service}-gpu.yml" ]]; then
template_file="$TEMPLATES_DIR/${service}-gpu.yml"
fi
fi
fi
if [[ ! -f "$template_file" ]]; then
format_error "Missing docker template: $template_file" "Reinstall the setup scripts."
return 1
fi

printf '\n' >> "$tmp_file"
cat "$template_file" >> "$tmp_file"

case "$service" in
postgres)
volume_names+=("postgres_data")
;;
neo4j)
volume_names+=("neo4j_data")
;;
mongodb)
volume_names+=("mongo_data")
;;
redis)
volume_names+=("redis_data")
;;
milvus)
volume_names+=("milvus_data" "etcd_data" "minio_data")
;;
qdrant)
volume_names+=("qdrant_data")
;;
memgraph)
volume_names+=("memgraph_data")
;;
vllm-rerank)
volume_names+=("vllm_rerank_cache")
;;
esac
done

if ((${#volume_names[@]} > 0)); then
printf '\nvolumes:\n' >> "$tmp_file"
for volume in "${volume_names[@]}"; do
printf ' %s:\n' "$volume" >> "$tmp_file"
done
fi

mv "$tmp_file" "$output_file"
}
Loading
Loading