LightRAG is an advanced Retrieval-Augmented Generation (RAG) framework designed to enhance information retrieval and generation through graph-based knowledge representation.
lightrag/: Core Python package with orchestrators (lightrag/lightrag.py), storage adapters inkg/, LLM bindings inllm/, and helpers such asoperate.pyandutils_*.py.lightrag-api/: FastAPI service (lightrag_server.py) with routers underrouters/and Gunicorn launcherrun_with_gunicorn.py.lightrag_webui/: React 19 + TypeScript client driven by Bun + Vite; UI components live insrc/.scripts/setup/: Interactive environment setup wizard.setup.shorchestrates staged--base/--storage/--server/ validation flows,lib/holds prompt/validation/file helpers, andtemplates/*.ymlcontains compose fragments for bundled services.- Tests live in
tests/and root-leveltest_*.py. Working datasets stay ininputs/,rag_storage/,temp/; deployment collateral lives indocs/,k8s-deploy/, anddocker-compose.yml. Makefile: Canonical entry point for the setup wizard and local developer shortcuts; prefer documented targets over invoking ad hoc shell snippets.
python -m venv .venv && source .venv/bin/activate: set up the Python runtime.pip install -e ./pip install -e .[api]: install the package and API extras in editable mode.make env-base: first-run interactive setup for LLM, embedding, and reranker configuration; writes.envand may generatedocker-compose.final.yml.make env-storage,make env-server: optional follow-up wizard stages for storage backends and server/security/SSL settings; both reuse the existing.env.make env-validate,make env-security-check,make env-backup: validate, audit, or back up the current.envvia the setup wizard.lightrag-serveroruvicorn lightrag.api.lightrag_server:app --reload: start the API locally; ensure.envis present.python -m pytest tests(offline markers apply by default) orpython -m pytest tests --run-integration/python test_graph_storage.py: run the full suite, opt into integration coverage, or target an individual script.ruff check .: lint Python sources before committing.bun install,bun run dev,bun run build,bun test: manage the web UI workflow (Bun is mandatory).
- Backend code follow PEP 8 with four-space indentation, annotate functions, and reach for dataclasses when modelling state.
- Use
lightrag.utils.loggerinstead ofprint; respect logger configuration flags. - Extend storage or pipeline abstractions via
lightrag.baseand keep reusable helpers in the existingutils_*.py. - Python modules remain lowercase with underscores; React components use
PascalCase.tsxand hooks-first patterns. - Front-end code should remain in TypeScript with two-space indentation, rely on functional React components with hooks, and follow Tailwind utility style.
- Keep pytest additions close to the code you touch (
tests/mirrors feature folders and there are root-leveltest_*.pyhelpers); functions must start withtest_. - Follow
tests/pytest.ini: markers includeoffline,integration,requires_db, andrequires_api, and the suite runs with-m "not integration"by default—pass--run-integration(or setLIGHTRAG_RUN_INTEGRATION=true) when external services are available. - Use the custom CLI toggles from
tests/conftest.py:--keep-artifacts/LIGHTRAG_KEEP_ARTIFACTS=true,--stress-test/LIGHTRAG_STRESS_TEST=true, and--test-workers N/LIGHTRAG_TEST_WORKERSto dial up workloads or preserve temp files during investigations. - Export other required
LIGHTRAG_*environment variables before running integration or storage tests so adapters can reach configured backends. - For UI updates, pair changes with Vitest specs and run
bun test.
- Use concise, imperative commit subjects (e.g.,
Fix lock key normalization) and add body context only when necessary. - PRs should include a summary, operational impact, linked issues, and screenshots or API samples for user-facing work.
- Verify
ruff check .,python -m pytest, and affected Bun commands succeed before requesting review; note the runs in the PR text. - This repo is a fork of
HKUDS/LightRAG. Always targetHKUDS/LightRAG:main(upstream) when creating PRs, not the fork's own main.
- Copy
.env.exampleandconfig.ini.example; never commit secrets or real connection strings. - Configure storage backends through
LIGHTRAG_*variables and validate them withdocker-composeservices when needed. - Treat
lightrag.log*as local artefacts; purge sensitive information before sharing logs or outputs.
- Use repo-relative
workdirarguments for every shell command and preferrg/rg --filesfor searches since they are faster under the CLI harness. - Default edits to ASCII, rely on
apply_patchfor single-file changes, and only add concise comments that aid comprehension of complex logic. - Honor existing local modifications; never revert or discard user changes (especially via
git reset --hard) unless explicitly asked. - Follow the planning tool guidance: skip it for trivial fixes, but provide multi-step plans for non-trivial work and keep the plan updated as steps progress.
- Validate changes by running the relevant
ruff/pytest/bun testcommands whenever feasible, and describe any unrun checks with follow-up guidance. - For Codex and other fresh-shell automation, prefer
./scripts/test.shinstead of barepytest; the script falls back throughPYTHON, the active virtualenv,uv,.venv, andvenvbefore tryingpythonorpython3. - For setup workflow changes, prefer
make env-*targets over callingscripts/setup/setup.shdirectly; theMakefileresolves a Bash 4+ interpreter for macOS/Linux compatibility. - When editing setup logic, keep
.envhost-usable and treatdocker-compose.final.ymlas generated output assembled fromscripts/setup/templates/*.yml; compose-only overrides belong in the wizard-managed compose layer rather than being persisted back into.env.