LightRAG/scripts/setup.sh
Claude 0a48c633cd
Add Schema-Driven Configuration Pattern
Implement comprehensive configuration management system with:

**Core Components:**
- config/config.schema.yaml: Configuration metadata (single source of truth)
- scripts/lib/generate_from_schema.py: Schema → local.yaml generator
- scripts/lib/generate_env.py: local.yaml → .env converter
- scripts/setup.sh: One-click configuration initialization

**Key Features:**
- Deep merge logic preserves existing values
- Auto-generation of secrets (32-char random strings)
- Type inference for configuration values
- Nested YAML → flat environment variables
- Git-safe: local.yaml and .env excluded from version control

**Configuration Coverage:**
- Trilingual entity extractor (Chinese/English/Swedish)
- LightRAG API, database, vector DB settings
- LLM provider configuration
- Entity/relation extraction settings
- Security and performance tuning

**Documentation:**
- docs/ConfigurationGuide-zh.md: Complete usage guide with examples

**Usage:**
```bash
./scripts/setup.sh  # Generate config/local.yaml and .env
```

This enables centralized configuration management with automatic
secret generation and safe handling of sensitive data.
2025-11-19 19:33:13 +00:00

87 lines
2.5 KiB
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# LightRAG 配置初始化脚本
# 从 config.schema.yaml 自动生成 config/local.yaml 和 .env
set -e # 遇到错误立即退出
# 获取脚本所在目录
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
echo "======================================================================"
echo " LightRAG 配置初始化"
echo "======================================================================"
echo ""
# 检查 Python 版本
echo "🔍 检查 Python 环境..."
if ! command -v python3 &> /dev/null; then
echo "❌ 错误: 未找到 python3"
echo " 请先安装 Python 3.7 或更高版本"
exit 1
fi
python_version=$(python3 --version 2>&1 | awk '{print $2}')
echo " Python 版本: $python_version"
# 检查必要的 Python 包
echo ""
echo "🔍 检查 Python 依赖..."
if ! python3 -c "import yaml" 2>/dev/null; then
echo " ⚠️ 未找到 PyYAML正在安装..."
pip install pyyaml
else
echo " ✓ PyYAML 已安装"
fi
# 检查 Schema 文件
echo ""
echo "🔍 检查配置 Schema..."
SCHEMA_FILE="${PROJECT_ROOT}/config/config.schema.yaml"
if [ ! -f "$SCHEMA_FILE" ]; then
echo "❌ 错误: 未找到 $SCHEMA_FILE"
exit 1
fi
echo " ✓ Schema 文件存在: config/config.schema.yaml"
# 生成 config/local.yaml
echo ""
echo "📝 生成本地配置..."
python3 "${SCRIPT_DIR}/lib/generate_from_schema.py"
# 检查生成是否成功
if [ ! -f "${PROJECT_ROOT}/config/local.yaml" ]; then
echo "❌ 错误: config/local.yaml 生成失败"
exit 1
fi
# 生成 .env
echo ""
echo "📝 生成环境变量..."
python3 "${SCRIPT_DIR}/lib/generate_env.py"
# 检查生成是否成功
if [ ! -f "${PROJECT_ROOT}/.env" ]; then
echo "❌ 错误: .env 生成失败"
exit 1
fi
echo ""
echo "======================================================================"
echo " ✅ 配置初始化完成"
echo "======================================================================"
echo ""
echo "生成的文件:"
echo " - config/local.yaml (本地配置文件)"
echo " - .env (环境变量文件)"
echo ""
echo "下一步:"
echo " 1. 编辑 config/local.yaml 修改配置(可选)"
echo " 2. 重新运行 ./scripts/setup.sh 更新 .env如果修改了配置"
echo " 3. 启动 LightRAG 服务"
echo ""
echo "提示:"
echo " - 这两个文件已添加到 .gitignore不会提交到 Git"
echo " - 密钥已自动生成,请妥善保管"
echo " - 修改配置后重新运行此脚本即可更新"
echo ""