LightRAG is a retrieval-augmented generation system that combines language models with retrieved information and knowledge-graph data to answer questions using relevant sources. It is for building applications that search document or knowledge collections before generating responses.
Borrowing it
Nothing to install: this file belongs to HKUDS/LightRAG. Take a copy, put it at the same path in your own repository, and replace the rules that are about this project with yours.
curl -O https://raw.githubusercontent.com/HKUDS/LightRAG/main/AGENTS.mdgit clone --depth 1 https://github.com/HKUDS/LightRAGWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/instructions/hkuds/lightrag/agents-md)<a href="https://agentmods.dev/instructions/hkuds/lightrag/agents-md"><img src="https://agentmods.dev/badge/instructions/hkuds/lightrag/agents-md/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/instructions/hkuds/lightrag/agents-md"><img src="https://agentmods.dev/badge/instructions/hkuds/lightrag/agents-md.svg" alt="Reviewed on agentmods" width="80" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.07646 | $0.07646 |
| Opus 5.5 | $0.03058 | $0.03058 |
| Sonnet 5.5 | $0.01529 | $0.01529 |
| Haiku 4.5 | $0.00765 | $0.00765 |
Grade A, and why
LightRAG AGENTS.md scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 393 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Repository Guidelines
Project Overview
LightRAG is a Retrieval-Augmented Generation (RAG) framework that uses graph-based knowledge representation for enhanced information retrieval. The system extracts entities and relationships from documents, builds a knowledge graph, and uses multiple retrieval modes (local, global, hybrid, mix, naive) for queries.
Project Structure
Top-level directories:
- lightrag/: Core Python package — see Module Layout below.
- lightrag_webui/: React 19 + TypeScript client (Bun + Vite + Tailwind). UI components in
src/. - scripts/:
test.sh(preferred test runner),setup/interactive environment wizard (usemake env-*rather than callingsetup.shdirectly — see Configuration > Setup Wizard Outputs), and release tooling. - tests/: Pytest coverage, organized into subdirectories that mirror
lightrag/(see Testing below for layout). Working datasets stay ininputs/,rag_storage/, andtemp/; deployment collateral lives indocs/,k8s-deploy/, and compose files.
Module Layout (lightrag/)
- lightrag.py: Main orchestrator class (
LightRAG) — assembled from mixins (see LightRAG class composition). Hostsainsert_custom_kg,_insert_done,_process_extract_entities,_refresh_addon_params_cache, andaddon_paramsaccessors. Critical: always callawait rag.initialize_storages()after instantiation. - pipeline.py:
_PipelineMixin— owns the document ingestion pipeline (apipeline_enqueue_documents,apipeline_process_enqueue_documents,apipeline_process_error_documents), theparse_native/parse_mineru/parse_doclingparser dispatchers, multimodal analysis, validation, and the worker scaffolding. - utils_pipeline.py: Pure helpers shared by the pipeline mixin and other entry points: doc-status field access, document identity (source key, content hash), parsed-artifact path resolution, parser payload normalization, multimodal entity augmentation, and
make_lightrag_doc_content. - llm_roles.py:
RoleSpec/RoleLLMConfig/_RoleLLMState/ROLESregistry plus_RoleLLMMixin— role normalization, builder registration, wrapper rebuild, runtime config update, queue cleanup, sanitized config export, queue status reporting. Route role-specific behavior here rather than into provider modules. - storage_migrations.py:
_StorageMigrationMixin—check_and_migrate_data,_migrate_entity_relation_data,_migrate_chunk_tracking_storage. - addon_params.py:
ObservableAddonParamsplusdefault_addon_params/normalize_addon_paramshelpers. - operate.py: Core extraction and query operations including entity/relation extraction, chunking, and multi-mode retrieval logic.
- base.py: Abstract base classes for storage backends (
BaseKVStorage,BaseVectorStorage,BaseGraphStorage,BaseDocStatusStorage). - kg/: Storage implementations (JSON, NetworkX, Neo4j, PostgreSQL, MongoDB, Redis, Milvus, Qdrant, Faiss, Memgraph, OpenSearch, NanoVectorDB). The backend registry (
STORAGE_IMPLEMENTATIONS/STORAGES) lives inkg/__init__.py;kg/factory.py::get_storage_class()resolves backend classes from configuration. - llm/: LLM and embedding provider bindings (OpenAI, Ollama, Azure, Gemini, Bedrock, Anthropic, etc.). All async with caching support.
- parser/: Unified parsing layer.
parser/routing.pyresolves engine and filename hints forlegacy,native,mineru, anddoclingflows;parser/debug.pyprovides an offline LightRAG stub for theparser/cli.pydebug entry point (python -m lightrag.parser.cli). Native format parsers live as sibling sub-packages underparser/(currentlyparser/docx/); external HTTP-based adapters live underparser/external/(mineru,docling) with shared helpers inparser/external/_common.py,_manifest.py,_zip.py. - chunker/: Chunking strategies (token-size, recursive character, semantic vector, paragraph semantic).
- api/: FastAPI service (
lightrag_server.py) with REST endpoints and Ollama-compatible API; routers underrouters/, static Swagger assets, packaged WebUI output, and Gunicorn launcher.
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 1mo ago Changed · +5 lines · +462 tokens per session 00ca19f18d78
- 1mo ago Changed · +1 lines · +157 tokens per session 65a6ec45ab2e
- 1mo ago Changed · +24 lines · +1,100 tokens per session 350ee583b4da
- 1mo ago Changed · -14 lines · -101 tokens per session 712c17efb495
- 2mo ago Changed · +10 lines · +326 tokens per session f82eb398d861
- 2mo ago Changed · -175 lines · -3,898 tokens per session 49cf3b94ef91
- 2mo ago Changed · +65 lines · +1,068 tokens per session 986e33f0ad86
- 2mo ago Changed · +71 lines · +1,227 tokens per session c0d1845546d6
- 2mo ago First seen · 406 lines · 7,305 tokens per session scan A 1f074a3d67f7
LightRAG AGENTS.md is an instructions file published in the GitHub repository HKUDS/LightRAG (40,557 stars, last pushed yesterday), licensed MIT. It adds 7,646 tokens to every session, about $0.0306 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
LightRAG AGENTS.md compared with instructions from other repositories
| Mod | Type | Stars | Last push | Licence | Scan | Tokens | Works with |
|---|---|---|---|---|---|---|---|
| LightRAG AGENTS.mdHKUDS/LightRAG | Instructions file | 41k | yesterday | MIT | A | 7,646 | Codex, OpenCode |
| vscode buildNext.instructions.mdmicrosoft/vscode | Instructions file | 195k | today | MIT | A | 9,719 | GitHub Copilot |
| next.js AGENTS.mdvercel/next.js | Instructions file | 143k | today | MIT | A | 7,461 | Codex, OpenCode |
| vscode oss-third-party-notices.instructions.mdmicrosoft/vscode | Instructions file | 195k | today | MIT | A | 5,516 | GitHub Copilot |
| langchain AGENTS.mdlangchain-ai/langchain | Instructions file | 149k | today | MIT | A | 4,680 | Codex, OpenCode |
| vscode copilot-instructions.mdmicrosoft/vscode | Instructions file | 195k | today | MIT | A | 3,093 | GitHub Copilot |
| deepseek-harness AGENTS.mddeepseek-ai/deepseek-harness | Instructions file | 274k | 2d ago | MIT | A | 4,313 | Codex, OpenCode |